Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - nopilpl

Pages: [1]
1
General / using namespace sf; error
« on: January 30, 2018, 03:50:13 pm »
Hey
When i want build my code compiler shows the error:
Severity   Code   Description   Project   File   Line   Suppression State
Error   C2871   'sf': a namespace with this name does not exist   ConsoleApplication11   c:\users\kamil\documents\visual studio 2015\projects\consoleapplication11\consoleapplication11\game.cpp
Severity   Code   Description   Project   File   Line   Suppression State 9

ConsoleApplication11.cpp
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
#include <Windows.h>
#include <string>
#include "stdafx.h"
#include "Game.h"


int main()
{
        Game game;
        game.runGame();

        return EXIT_SUCCESS;
}

Game.cpp
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
#include <Windows.h>
#include <string>
#include "Game.h"
#include "stdafx.h"

using namespace sf;

RenderWindow window(VideoMode(1280, 720), "Morbid Squirrel Wars");

Game::Game(void)
{
        state = END;

        if (!font.loadFromFile("Fonts/arial.ttf"))
        {
                //Error
        }

        state = MENU;
}


void Game::move()
{
        if (state == GAME)
        {
                Texture tPlayer;
                tPlayer.loadFromFile("Sprites/Player");
                Sprite sPlayer;
                sPlayer.setTexture(tPlayer);




        }





}

void Game::runGame()
{
        while (state != END)
        {
                switch (state)
                {
                case GameState::MENU:
                        menu();
                        break;
                case GameState::GAME:
                        //
                        break;
                }
        }
}


void Game::menu()
{
        Text Title;
        Title.setStyle(Text::Bold);
        Title.setFont(font);
        Title.setCharacterSize(80);
        Title.setString("Morbid Squirrel Wars");
        Title.setPosition(1280 / 2 - Title.getGlobalBounds().width / 2, 20);


        Text Play;
        Play.setFont(font);
        Play.setCharacterSize(65);
        Play.setString("Play");
        Play.setPosition(1280 / 2 - Play.getGlobalBounds().width / 2, 250);

        Text Options;
        Options.setFont(font);
        Options.setCharacterSize(65);
        Options.setString("Options");
        Options.setPosition(1280 / 2 - Options.getGlobalBounds().width / 2, 370);

        Text Exit;
        Exit.setFont(font);
        Exit.setCharacterSize(65);
        Exit.setString("Exit");
        Exit.setPosition(1280 / 2 - Exit.getGlobalBounds().width / 2, 490);

        while (state == MENU)
        {
                Vector2f mouse(Mouse::getPosition(window));
                Event event;

                if (state == END)
                {
                        window.close();
                }
                while (window.pollEvent(event))
                {
                        //klikniêcie EXIT
                        if (Exit.getGlobalBounds().contains(mouse) &&
                                event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
                        {
                                state = END;
                        }

                        if (Play.getGlobalBounds().contains(mouse))
                                Play.setColor(Color::Cyan);
                        else Play.setColor(Color::White);

                        if (Options.getGlobalBounds().contains(mouse))
                                Options.setColor(Color::Cyan);
                        else Options.setColor(Color::White);

                        if (Exit.getGlobalBounds().contains(mouse))
                                Exit.setColor(Color::Cyan);
                        else Exit.setColor(Color::White);
                }

                if (Play.getGlobalBounds().contains(mouse) && event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
                {
                        state = GAME;
                }

                window.clear();

                window.draw(Title);
                window.draw(Play);
                window.draw(Options);
                window.draw(Exit);

                window.display();
        }
}


Game::~Game()
{
}

Game.h
#pragma once
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp>
#include <Windows.h>
#include <string>
#include "stdafx.h"

using namespace std;
using namespace sf;

class Game
{
public:
        Game(void);
        ~Game(void);

        void move();
        void runGame();
        enum GameState { MENU, GAME, GAME_OVER, END };
        GameState state;

        Font font;
        void menu();
};

 

2
General / Sprite is not moving
« on: January 23, 2018, 09:52:28 pm »
Hey
I have problem
#define NOMINMAX
#define SFML_NO_DEPRECATED_WARNINGS
#include <iostream>
#include <Windows.h>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include <SFML\Audio.hpp>
#include <SFML\Window.hpp>
#include <algorithm>

using namespace sf;
using namespace std;

int main()
{
        Sprite sgracz; //sprite
        //Sprite smapa1;
        Texture gracz;
        //Texture mapa1;

        gracz.loadFromFile("Textures/Player.png");
        sgracz.setTexture(gracz);
        sgracz.setPosition(Vector2f(120, 200));


        enum enumStates { MENU, GAME, GAMEOVER, END };
        enumStates state = MENU;
        RenderWindow window(VideoMode(1500, 900), "Rise of the Cyborg Story");
        while (window.isOpen())
        {              
                Font font;

                if (!font.loadFromFile("Fonts/arial.ttf"))
                {
                        //Error
                }

                ////// Menu //////

                // Nag&#322;ówek //
                Text title("Rise of the Cyborg Story", font, 80);
                title.setStyle(Text::Bold);
                title.setPosition(1280 / 2 - title.getGlobalBounds().width / 2, 20);

                Text Play;
                Text Options;
                Text Exit;

                // Play //
                Play.setFont(font);
                Play.setCharacterSize(65);
                Play.setString("Play");
                Play.setPosition(1280 / 2 - Play.getGlobalBounds().width / 2, 250);

                // Options //
                Options.setFont(font);
                Options.setCharacterSize(65);
                Options.setString("Options");
                Options.setPosition(1280 / 2 - Options.getGlobalBounds().width / 2, 250 + 120);

                // Exit //
                Exit.setFont(font);
                Exit.setCharacterSize(80);
                Exit.setString("Exit");
                Exit.setPosition(1280 / 2 - Exit.getGlobalBounds().width / 2, 250 + 240);

                //// Dzia&#322;anie menu ////
                Vector2f mouse(Mouse::getPosition(window));
                Event event;
                int selected = 1;

                // Wy&#322;&#261;czanie gry //
                while (window.pollEvent(event))
                {

                        if (event.type == Event::Closed)
                        {
                                window.close();
                        }

                        else if (Exit.getGlobalBounds().contains(mouse) &&
                                event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left)
                        {
                                window.close();
                        }
                }


                Text wybrane1;
                Text wybrane2;

                // Pod&#347;wietlanie si&#281; napisów w menu //
                if (Play.getGlobalBounds().contains(mouse))
                        Play.setColor(Color::Cyan);
                else (Play.setColor(Color::White));

                if (Options.getGlobalBounds().contains(mouse))
                        Options.setColor(Color::Cyan);
                else (Options.setColor(Color::White));

                if (Exit.getGlobalBounds().contains(mouse))
                        Exit.setColor(Color::Cyan);
                else (Exit.setColor(Color::White));

                if (state == MENU)
                {
                        window.draw(title);
                        window.draw(Play);
                        window.draw(Options);
                        window.draw(Exit);
                }

                ////// Koniec Menu //////

                if (Play.getGlobalBounds().contains(mouse) && event.type == Event::MouseButtonPressed && event.key.code == Mouse::Left)
                {
                        state = GAME;
                }


                if (state == GAME)
        {
                        window.clear();

                        Event poruszanieSie;
                        while (window.pollEvent(poruszanieSie))
                        {
                                if ( poruszanieSie.type == Event::KeyPressed && poruszanieSie.key.code == Keyboard::Right)
                                {
                                        sgracz.move(Vector2f( 50, 0));
                                       
                                }

                                if (poruszanieSie.type == Event::KeyPressed && poruszanieSie.key.code == Keyboard::Left)
                                {
                                        sgracz.move(Vector2f(-50, 0));
                                       
                                }
                        }
                        window.draw(sgracz);
                }
                window.display();
        }

        return EXIT_SUCCESS;
}
 
So I want to move my sprite when i will click button but it doesnt work

Pages: [1]