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.


Messages - Sarbast

Pages: [1] 2
1
Graphics / Re: SFML Game Development, Movement
« on: June 27, 2014, 11:18:34 pm »
I'll add them later.
nobody answered my question  :o

2
Graphics / Re: SFML Game Development, Movement
« on: June 27, 2014, 02:56:46 pm »
Thats the only i could make SFML static works for me

3
Graphics / SFML Game Development, Movement
« on: June 26, 2014, 02:14:04 pm »
Hi
i wrote the code same as the book but the after the key is released the bool variables won't reset to false
and object moves without stopping
also the object moves opposite direction, when i press W set the mPlayer.move(0,-1) but it moves to down

Main.cpp

#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")  
#endif // SFML_STATIC

#include "game.h"
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

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

        return 0;
}

game.h

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

#ifndef GAME_H
#define GAME_H

class Game{
private:
        void processEvents();
        void update();
        void render();

private:
        sf::RenderWindow mWindow;
        sf::CircleShape mPlayer;
        bool mIsMovingUp, mIsMovingDown, mIsMovingLeft, mIsMovingRight;

public:
        Game();
        void HandlePlayerInput(sf::Keyboard::Key, bool);
        void run();
};


#endif // GAME_H

game.cpp

#include "game.h"

Game::Game() : mWindow(sf::VideoMode(640, 480), "SFML Application"), mPlayer(){
        mPlayer.setRadius(40.f);
        mPlayer.setPosition(100.f, 100.f);
        mPlayer.setFillColor(sf::Color::Cyan);
}


void Game::run(){
        while (mWindow.isOpen()){
                processEvents();
                update();
                render();
        }
}

void Game::processEvents(){
        sf::Event event;
        while (mWindow.pollEvent(event)){
                switch (event.type){
                        case sf::Event::KeyPressed:
                                HandlePlayerInput(event.key.code, true);
                                break;
                        case sf::Event::KeyReleased:
                                HandlePlayerInput(event.key.code, false);
                                break;
                        case sf::Event::Closed:
                                mWindow.close();
                                break;
                }
        }
}

void Game::HandlePlayerInput(sf::Keyboard::Key key, bool isPressed){
        if (key == sf::Keyboard::W)
                mIsMovingUp = isPressed;
        else if (key == sf::Keyboard::S)
                mIsMovingDown = isPressed;
        else if (key == sf::Keyboard::A)
                mIsMovingLeft = isPressed;
        else if (key == sf::Keyboard::D)
                mIsMovingRight = isPressed;
}

void Game::update(){
        sf::Vector2f movement(0.f, 0.f);

        if (mIsMovingUp)
                movement.y -= 1.f;
        if (mIsMovingDown)
                movement.y += 1.f;
        if (mIsMovingLeft)
                movement.x -= 1.f;
        if (mIsMovingRight)
                movement.x += 1.f;

        mPlayer.move(movement);
}

void Game::render(){
       
        mWindow.clear();
        mWindow.draw(mPlayer);
        mWindow.display();
}

4
Graphics / Re: Sf::View, putting player in the middle of screen
« on: June 20, 2014, 03:03:15 pm »
Thats what i got after putting
MyView.SetCenter(player.getPosition())

i don't know how to remove the black sides


5
Graphics / Re: Sf::View, putting player in the middle of screen
« on: June 20, 2014, 02:03:42 pm »
I meant screen scrolling, while the player goes left/right of the screen the map goes opposite it and camera always shows the Player. i can't explain better than that  :(

btw i found out how to do that i followed a youtube video i don't know if thats a right way to do that.
if you understood my question and have better way to do that please tell me how?

//Screen Scroling
                MapPosition.x = player.getPosition().x + 16 - (position.x / 2);
                MapPosition.y = player.getPosition().y + 16 - (position.y / 2);
               
                if (MapPosition.x < 0)
                        MapPosition.x = 0;
                if (MapPosition.y < 0)
                        MapPosition.y = 0;

                MyView.reset(sf::FloatRect(MapPosition.x, MapPosition.y, position.x, position.y));

now i got into this problem


Language was always obstacle for me to learn programming there isn't a single book about programming in my language :(

6
Graphics / Re: Sf::View, putting player in the middle of screen
« on: June 19, 2014, 01:18:09 am »
that's what i want like other games
I just want the camera follow where the player goes


7
Graphics / Re: Sf::View, putting player in the middle of screen
« on: June 19, 2014, 12:31:55 am »
Thanks for the answer but setCenter() not really working fine for my code it changes position of the map and puts left above in the middle of the screen

and thanks for the tips they were so helpful

8
Graphics / [SOLVED]Sf::View, putting player in the middle of screen
« on: June 19, 2014, 12:03:06 am »
Hi
i want to put the player in the middle of the screen but i don't know
can someone tell me how to do it?
also when i move it to a side and then press another side its legs stop moving(fixed thanks for Ixrec)

sorry for my english

#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")  
#endif // SFML_STATIC


#include <SFML\Graphics.hpp>
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <cstdlib>

#pragma region Variables
sf::RenderWindow window;
sf::Texture Map;
sf::Sprite sMap;
sf::Clock MyClock;
sf::Event MyEvent;
sf::Vector2f position(800, 600);
sf::Texture Image;
sf::Sprite player;
sf::View MyView;
sf::Vector2i Place(1, 0);
sf::Vector2f MapPosition(position.x/2, position.y/2);
enum Direction{Down, Left, Right, Up};
float FrameSpeed = 500, SwitchFrame = 60, FrameCount = 0;
bool updateFrame = false;
#pragma endregion sf

int main()
{
        //Window
        window.create(sf::VideoMode(position.x, position.y), "My First SFML Game", sf::Style::Close);
        window.setPosition(sf::Vector2i(300, 50));
        window.setFramerateLimit(60);
        window.setKeyRepeatEnabled(false);

        //Texture Map
        if (!Map.loadFromFile("LOF-Map.png"))
                std::cout << "Couldn't Load The Map" << std::endl;

        //Texture player
        if (!Image.loadFromFile("Player.png"))
                std::cout << "Couldn't load the Image" << std::endl;
        Image.setSmooth(true);

        //Sprite Map
        sMap.setTexture(Map);

        //Sprite Player
        player.setTexture(Image);
        player.setPosition(sf::Vector2f(100, 100));

        //Game Loop
        while (window.isOpen())
        {

                //Event loop
                while (window.pollEvent(MyEvent))
                {
                       place.x = 1;
                        switch (MyEvent.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        }

                }
                updateFrame = false;
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
                        updateFrame = true;
                        Place.y = Down;
                        player.move(0, 1);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
                        updateFrame = true;
                        Place.y = Left;
                        player.move(-1, 0);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
                        updateFrame = true;
                        Place.y = Right;
                        player.move(1, 0);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
                        updateFrame = true;
                        Place.y = Up;
                        player.move(0, -1);
                }
       

                FrameCount += FrameSpeed * MyClock.restart().asSeconds();
                if (updateFrame == true){
                        if (FrameCount > SwitchFrame)
                        {
                                FrameCount = 0;
                                Place.x++;
                                if (Place.x * 32 >= Image.getSize().x)
                                        Place.x = 0;
                        }
                }
                if (player.getPosition().x<= 0)
                        player.setPosition(sf::Vector2f(0,player.getPosition().y));
                if (player.getPosition().y < 0)
                        player.setPosition(sf::Vector2f(player.getPosition().x, 0));

                //Display a block of the SpriteSheet
                player.setTextureRect(sf::IntRect(Place.x * 32, Place.y * 32, 32, 32));

                window.clear();
                window.setView(MyView);
                window.draw(sMap);
                window.draw(player);
                window.display();
        }
        return EXIT_SUCCESS;
}

9
Thank you

10
General discussions / Re: Setup SFML on VS 2013 professional
« on: June 03, 2014, 10:41:28 pm »
here is the video i made of how i tried to build it for VS2013 but the static not works
https://www.youtube.com/watch?v=a2HvDgFhnYs&feature=youtu.be

i hope someone help me  :(

11
General discussions / Re: Setup SFML on VS 2013 professional
« on: May 12, 2014, 10:56:22 pm »
worst language ever there is only one c# tutorial and a little about web designing :D
btw its Kurdish

i tried to use static but i had no chance to get it works
i did same as written http://www.sfml-dev.org/tutorials/2.1/start-vc.php

i would be if someone login into my laptop through TeamViewer

12
General discussions / Re: Setup SFML on VS 2013 professional
« on: May 12, 2014, 07:29:14 pm »
i don't whats the problem with SFML_STATIC;
but here the steps
1-download SFML2.1 at Nightly and extract to c:\data

2-make an empty project and add a source.cpp

3-link C:\data\SFML-VS12x32\include and C:\data\SFML-VS12x32\lib

4- add Add the following libraries for statically
sfml-graphics-s-d.lib
sfml-audio-s-d.lib
sfml-system-s-d.lib
sfml-window-s-d.lib
sfml-network-s-d.lib

Add the following libraries for dynamically

sfml-graphics-d.lib
sfml-audio-d.lib
sfml-system-d.lib
sfml-window-d.lib
sfml-network-d.lib

5- add SFML_STATIC


i don't know whats more i should do :-\

13
General discussions / Re: Setup SFML on VS 2013 professional
« on: May 12, 2014, 06:07:05 pm »
it worked magneonx  :o
i want to thank you 1 million times man you saved me  :-*
i was about to give up and start downloading SDL

14
General discussions / Re: Setup SFML on VS 2013 professional
« on: May 12, 2014, 05:52:48 pm »
I really tired it won't work :(

15
General discussions / Re: Setup SFML on VS 2013 professional
« on: May 12, 2014, 04:42:39 pm »
fixed it
now i have another one
the program can't start because sfml-graphics-2.dll missing from your computer
how can i link the DLL files?
i forgot to add SFML_STATIC :D
well another error  :'(

Error   1       error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)     C:\Users\Sarbast\documents\visual studio 2013\Projects\SFMLs\main.obj   SFMLs
Error   2       error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)    C:\Users\Sarbast\documents\visual studio 2013\Projects\SFMLs\main.obj   SFMLs
Error   3       error LNK1120: 2 unresolved externals   C:\Users\Sarbast\documents\visual studio 2013\Projects\SFMLs\Debug\SFMLs.exe    1       1       SFMLs
 

Pages: [1] 2