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

Pages: 1 2 [3] 4
31
SFML projects / Yellow Snake - w/Source (Updated 10/21)
« on: October 18, 2011, 06:09:56 am »
Actually, nevermind... that Sleep function wasn't taking affect at all. I had Vertical sync enabled on code at home, and it was keeping my frame rate at 60 fps pretty much constantly. That's it didn't matter what FPS was set to...

32
SFML projects / Yellow Snake - w/Source (Updated 10/21)
« on: October 18, 2011, 05:53:41 am »
Also it seems like adding the following code:

Code: [Select]

if(1.0f/Window.GetFrameTime() < 1.0f/FPS){
    sf::Sleep(1.0f/FPS-(1.0f/Window.GetFrameTime()));
}


Is really what is making a difference in my newly found speed increase! However, it's weird, this 'if' block doesn't compile correctly on all of my computers even though I am using the same versions of Code::Blocks, Mingw, and SFML. On my work computer, the 'if' statement is ignored, and my game runs at 1200+FPS (which makes my snake plant himself permanently into a wall). At home it seems to function very well, but my FPS stays constant at 59-60 FPS regardless what my FPS variable is set to. If I set FPS to 30, I still get 60 FPS, if I set it to 1000, I still get 60 FPS... This seems very odd to me.

33
SFML projects / Yellow Snake - w/Source (Updated 10/21)
« on: October 18, 2011, 05:09:37 am »
Calmatory,

I don't quite understand which of the if-statements in my loop could be moved elsewhere. I have examined them all, and I don't see to be able to find a solution that could take place out of the loop. Any advice on which particular ifs I should take a closer look at?

Thank you!

34
SFML projects / Yellow Snake - w/Source (Updated 10/21)
« on: October 18, 2011, 02:13:06 am »
Lots of great advice; thanks a lot guys for looking at this and commenting!

35
SFML projects / Yellow Snake - w/Source (Updated 10/21)
« on: October 17, 2011, 01:40:14 pm »
I am on my way to work, so I haven't had time to implement those changes, and no I wasn't away of compiler optimizations until I read your post, but I will look them up and make sure they are turned on!

All your advice is spectacular! I plan on addressing each of those issues and learning from them how to code better for the future. Thank you so much for taking the time to toss some advice my way!

Anything further that anyone else sees is also very welcome. My goal is to be a good coder, not just to have a good snake game. So I am absorbing whatever advice I can get.

Thanks!
BG

36
SFML projects / Yellow Snake - w/Source (Updated 10/21)
« on: October 17, 2011, 02:08:45 am »
I've been programming in C++ for about 3 weeks. About a week into it, I stumbled upon SFML! I wanted my first project to be a game that my kids could play. I also wanted to make something I was familiar with, so I chose to make a snake game.

When my wife and I were dating in high-school, we use to compete on her cell-phone playing the snake game, so this is also something we can have fun with together.

This game has 2 modes: NORMAL and DRAW mode. Normal mode is classic snake game. Draw mode is what I made for my kids (they are 3 and 4 years old)--your snake never dies, and you grow at a very fast pace.

There are also 3 speeds. The game saves your last speed to a file, so it will load that same speed the next time you launch the game.

I am definitely open to criticism, seeing that I am new to C++ in general. I am out to better my skills and logic techniques, so keep the criticisms flowing! Thanks!

So far I only have a Windows version.

[Edit (10/21): I have implemented some changes suggested by the people on this post. Also, the game now tracks the person who holds the High-Score; and the game now starts in a paused state]

You can download it here: http://bglz.net/files/cpp/projects/Yellow_Snake.zip

And the source code and CB project here: http://bglz.net/files/cpp/projects/Yellow_Snake_src_10-21.zip

Here are some screenshots.



Draw Mode:

37
General / Simple Collision Detection - BoundingBoxTest
« on: October 15, 2011, 12:56:52 pm »
I am using the simple collision detection modules found here:
http://www.sfml-dev.org/wiki/en/sources/simple_collision_detection

I am using this with a snake game to test whether or not my snake eats his food.

The BoundingBoxTest seems to create a box that is nearly twice the size of my sprite image. My snake will eat his food if I am merely passing beside the food on the grid. Is there any way to fix this, such as shrinking the size of the bounding box in this code?

I don't need pixel perfect detection, but I don't want to eat my food by merely passing next to my food either.

Thanks so much!!

38
General / Keep seeing: error: expected ')' before '&' token ?
« on: October 11, 2011, 09:49:10 pm »
Disch,

Thanks for helping a newb out. That advice will continue to help me forever. I read that entire tutorial on Headers, and it cleared up exactly what I was doing.

Thanks again,
Brock

39
General / Keep seeing: error: expected ')' before '&' token ?
« on: October 11, 2011, 08:38:37 pm »
Disch,

that would explain why it keeps happening. =)

Thanks so much!

40
General / Keep seeing: error: expected ')' before '&' token ?
« on: October 11, 2011, 08:22:30 pm »
I hadn't thought of that, but I tried it, and it did not work.

Thanks for the suggestion, though.

41
General / Keep seeing: error: expected ')' before '&' token ?
« on: October 11, 2011, 07:48:12 pm »
I keep seeing the following error when trying to assign my game object to my snake object. Since I have seen it so many times now, and have spent 2 days finding workarounds, but without knowing what is causing it, I am hoping someone can see why it's happening, so I can fix it directly.

Here is the full error:
Code: [Select]

s Files\CPP\Dev\The_Yellow_Snake\Yellow_Snake_testing_window_passing\Snake.h|12|error: expected ')' before '&' token|
s Files\CPP\Dev\The_Yellow_Snake\Yellow_Snake_testing_window_passing\Snake.h|15|error: 'Game' does not name a type|
s Files\CPP\Dev\The_Yellow_Snake\Yellow_Snake_testing_window_passing\Snake.cpp|6|error: prototype for 'Snake::Snake(Game&)' does not match any in class 'Snake'|
s Files\CPP\Dev\The_Yellow_Snake\Yellow_Snake_testing_window_passing\Snake.h|9|error: candidates are: Snake::Snake(const Snake&)|
s Files\CPP\Dev\The_Yellow_Snake\Yellow_Snake_testing_window_passing\Snake.h|9|error:                 Snake::Snake()|
||=== Build finished: 5 errors, 0 warnings ===|



And here are my files, starting with main.cpp
Code: [Select]

#include "Game.h"
#include "Snake.h"
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::VideoMode VMode(600, 390, 32);
    sf::RenderWindow window;
    window.Create(VMode, "Yellow Snake", sf::Style::Close);

    Game game(window);
    game.Run();

    return 0;
}


Game.h
Code: [Select]

#ifndef GAME_H
#define GAME_H

#include "Game.h"
#include "Snake.h"
#include <SFML/Graphics.hpp>
#include <iostream>

class Game
{
    public:
        Game(sf::RenderWindow& window);

        //funcs
        void Run();

        //vars
        double FPS;
        sf::RenderWindow& Window;


    protected:

    private:
};

#endif // GAME_H


Game.cpp
Code: [Select]

#include "Game.h"
#include "Snake.h"
#include <SFML/Graphics.hpp>
#include <iostream>

Game::Game(sf::RenderWindow& window):
FPS(15.0),
Window(window)
{
}

void Game::Run()
{
    Snake snake(this);

    while(Window.IsOpened())
    {
        sf::Event event;
        while(Window.GetEvent(event))
        {
            switch(event.Type)
            {
                case sf::Event::Closed:
                    Window.Close();
                    break;
                default:
                    break;
            }
        }

        Window.Clear(sf::Color(0, 0, 0));
        Window.Display();

        /* Free up the CPU */
        sf::Sleep(1.0/FPS);
    }
}


Snake.h
Code: [Select]

#ifndef SNAKE_H
#define SNAKE_H

#include "Game.h"
#include "Snake.h"
#include <SFML/Graphics.hpp>
#include <iostream>

class Snake
{
    public:
        Snake(Game& g);
    protected:
    private:
    Game game;
};

#endif // SNAKE_H


Snake.cpp
Code: [Select]

#include "Game.h"
#include "Snake.h"
#include <SFML/Graphics.hpp>
#include <iostream>

Snake::Snake(Game& g):
game(g)
{
}



My full program is larger, but this is as small as I could get it and reproduce the error.

Your consideration is much appreciated!

Thanks
- Brock

42
Graphics / Pointer to RenderWindow object?
« on: October 11, 2011, 07:24:06 pm »
keyforge and Laurent:

Thank you both so much. I am up and running, and I learned a lot about references with this mistake. I appreciate the help very much!

43
Graphics / Pointer to RenderWindow object?
« on: October 11, 2011, 06:22:29 am »
It still isn't working for me for some reason. Window works fine for me if I don't try to imbed it into my Game class, however, when I do it this way I get an error saying NonCopyable. Here is my code for my main file and my header files, and below them is the error.

main.cpp
Code: [Select]

#include "Game.h"
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::VideoMode VMode(600, 390, 32);
    sf::RenderWindow window;
    window.Create(VMode, "Yellow Snake", sf::Style::Close);

    Game game(window);
    game.Run();

    return 0;
}


Game.h
Code: [Select]

#ifndef GAME_H
#define GAME_H

#include <SFML/Graphics.hpp>
#include <iostream>

class Game
{
    public:
        Game(sf::RenderWindow& window);

        sf::RenderWindow Window;

        void Run();

    protected:

    private:
};

#endif // GAME_H


Game.cpp
Code: [Select]

#include "Game.h"
#include <SFML/Graphics.hpp>
#include <iostream>

Game::Game(sf::RenderWindow& window):
Window(window)
{
}

void Game::Run()
{
    window.Display();
}


Error:
Code: [Select]

c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\SFML\System\NonCopyable.hpp|57|error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\SFML\Window\Window.hpp|55|error: within this context|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\SFML\System\NonCopyable.hpp|57|error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\SFML\Window\Input.hpp|44|error: within this context|
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\SFML\Window\Window.hpp|55|note: synthesized method 'sf::Input::Input(const sf::Input&)' first required here |
c:\mingw\bin\..\lib\gcc\mingw32\4.6.1\..\..\..\..\include\SFML\Graphics\RenderWindow.hpp|45|note: synthesized method 'sf::Window::Window(const sf::Window&)' first required here |
s Files\CPP\Dev\Yellow_Snake2\Game.cpp||In constructor 'Game::Game(sf::RenderWindow&)':|
s Files\CPP\Dev\Yellow_Snake2\Game.cpp|6|note: synthesized method 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)' first required here |
s Files\CPP\Dev\Yellow_Snake2\Game.cpp||In member function 'void Game::Run()':|
s Files\CPP\Dev\Yellow_Snake2\Game.cpp|12|error: 'window' was not declared in this scope|
s Files\CPP\Dev\Yellow_Snake2\Game.cpp|13|error: expected ';' before '}' token|
||=== Build finished: 9 errors, 0 warnings ===|



Any advice here?

44
Graphics / Pointer to RenderWindow object?
« on: October 11, 2011, 05:54:03 am »
Woh, that is perfect! Thank you so much for taking the time to respond! I really appreciate that!

- Brock

45
Graphics / Pointer to RenderWindow object?
« on: October 11, 2011, 05:24:09 am »
I would like to create my window object in my Main function, and then set my Game class to have a member variable called "window" so that I can access the window's properties via game.window or game->window.

Is there a way to do this?

Thanks!

Pages: 1 2 [3] 4
anything