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 - northLynx

Pages: [1]
1
General discussions / Re: GameState
« on: August 05, 2016, 05:51:50 pm »
Thanks exploiter. I was looking over the code again and I was wondering if its possible to write all the state management in one header file? Instead of having two separate files.Ill use a unique pointer as a type for my std::stack. I didnt even notice my template function was void  :-[. I should have checked it. Also, how do make headers files appear as a .hpp? In my visual studious all i see when creating a new header file is .h . What do you mean use tags next time so you dont have to insert them.

2
General discussions / GameState
« on: August 05, 2016, 04:36:36 am »
I have been looking at some State menu code from sfml game development book and other game source code. I was wonder if my game state code will work if implemented in a game? i created a state and gamestate header files with their cpp files. I been trying to practice on my own rather than just copy and past code from other source code so if I did something wrong or wrote code in a bad way please point it out and tell me how to write it better or if i need to remove some functions or add functions to a header file or just write the whole thing over again. Thank you  :)

#pragma once
#include "State.h"
#include <stack>
#include <memory>
#include <SFML\System\NonCopyable.hpp>

namespace sf
{
        class RenderWindow;
        class Time;
}


class GameState : public sf::NonCopyable
{
public:
        GameState();
        void push(States::ID);
        void pop();
        bool isEmpty();
        template<typename T>
        void registerState(States::ID);

private:
        void update(sf::Time& dt);
        void render(sf::RenderWindow& wind);

private:
        std::stack<States::ID> mStack;
        State *activeState;
};

template<typename T>
void registerState(States::ID)
{
        return mStack(new T(States::ID));
}

#include "GameState.h"

GameState::GameState()
{
        activeState = nullptr;
}

void GameState::push(States::ID mStateID)
{
        if (!isEmpty())
                mStack.push(mStateID);
}

void GameState::pop()
{
        if (!isEmpty())
                mStack.pop();
}

void GameState::update(sf::Time& dt)
{
        if (activeState)
                activeState->update(dt);
}

void GameState::render(sf::RenderWindow& wind)
{
        if (activeState)
                activeState->render(wind);
}

bool GameState::isEmpty()
{
        mStack.empty();
}

#pragma once
#include "GameState.h"

namespace sf
{
        class RenderWindow;
        class Time;
}

namespace States
{
        enum ID
        {
                Title,
                MainMenu,
                Settings,
                Quit,
        };
}

class GameState;

class State
{
public:
        virtual void update(sf::Time& dt) = 0;
        virtual void render(sf::RenderWindow& wind) = 0;
       
public:
        State(GameState mstate);
        virtual ~State();
        void addState();

private:
        GameState mstack;
};

#include "State.h"

State::State(GameState mstate) : mstack(mstate)
{

}

State::~State()
{

}

void State::addState()
{
        mstack.push(States::Title);
}

3
General discussions / Fully finished game with source code
« on: August 04, 2016, 04:53:14 am »
I have been reading the sfml game development book and I was wondering if anybody knows where I can see a fully finished game with the source code. I want to see a different example of a finished game to see how the code looks different than the one from the book. Also to apply it to my code to get practice :)

4
General / Re: Game menu
« on: July 09, 2016, 01:15:02 am »
Ok thanks for the link it is useful. Is there any example online that can get me started and I mean a good example to look at that can give me a good idea of how the class should look like because the link is just explaining how it works with only partial code example.

5
General / Game menu
« on: July 07, 2016, 05:35:27 am »
I want to make a game menu where it shows the intro then the screen starts going black and shows the main menu and the main menu shows play, settings, about and quit. Also, if the user enters settings or about they can go back to the main menu. Do I create a class with an enum that shows all the states and a stack instance in the private section followed by some functions that get current state and set any of state equal to one of them?

6
I got to the chapter 4 and now I am having a problem with one of the functions of the eventmanager. I call setfocus in window.cpp but I realized the book never implemented it. Should I know how to implement it? Also, the same with the void togglefullscreen function that was introduced as well in chapter 4.

7
Yes that did the trick! Now I am getting an error with the float timestep variable the book created. I compared the m_elapsed sf::Time variable I created from chapter 2 and I am assuming the book says that you need to compare that with the float timestep,but it is giving me an error. Is it suppose to give me an error?

8
I am on the third chapter of the book and followed the code from the book to make the snake game. Right when I call the render functions for the snake and world I realized that that whats passed into the function is not a function that the book made me created. The function is called GetRenderWindow() and its called like *m_window.GetRenderWindow() and passed into the render function like that as well. I checked the chapter again to see if I missed it but I dont see it. Is it something that I need to make because GetRenderWindow is not a function either for the window class.

9
General / Window
« on: June 08, 2016, 10:13:19 pm »
I have got the new sfml game development by example book and I have been following the code for the snake program in chapter 3. When I get to the last part before running the program I get an error . In the void Game::Render() method i pass in the pointer *m_window.GetRenderWindow() to the m_world and m_snake but I get and error saying no operator "*" matches these operands type *Window. Also, I dont remember the book telling me to write a GetRenderWindow() method either. Can someone help me out please.

void World::Render(sf::RenderWindow &l_window)
{
   for (int i = 0; i < 4; ++i)
   {
      l_window.draw(m_bounds);
   }
   l_window.draw(m_appleShape);
}

void Snake::Render(sf::RenderWindow& l_window)
{
   if (m_snakeBody.empty()) { return; }

   auto head = m_snakeBody.begin();
   m_bodyRect.setFillColor(sf::Color::Yellow);
   m_bodyRect.setPosition(head->position.x * m_size, head->position.y * m_size);
   l_window.draw(m_bodyRect);

   m_bodyRect.setFillColor(sf::Color::Green);
   for (auto itr = m_snakeBody.begin() + 1; itr != m_snakeBody.end(); ++itr)
   {
      m_bodyRect.setPosition(itr->position.x * m_size, itr->poistion.y * m_size);
      l_window.draw(m_bodyRect);
   }
}


void Game::Render()
{
   m_window.BeginDraw(); // clear

   m_world.Render(*m_window.GetRenderWindow());
   m_snake.Render(*m_window.GetRenderWindow());

   m_window.EndDraw(); //display
}

my error occurs when I pass in the *m_window to the game render function. Also the book says to call those functions which I never made because the book never created those functions either

Pages: [1]
anything