Need some help about how to structure a 2D game

Started by
11 comments, last by slayemin 11 years, 6 months ago

Ok now I'm using SFML 2. Just a little question: how do I draw a rectangle filled with gradient color?

EDIT: also, I've written this little test program... But why the rectangle doesn't move to the left when it goes out of the screen on the right?
The forum editor is messing up my indentation, so I'm using Pastebin. http://pastebin.com/....php?i=yShxR10s


My bet is this line:

if (rectPos > window.getSize().x)


If window.getSize().x returned unsigned, it may also make rectPos unsigned, and if rectPos == -50, when it's unsigned, it'll always be larger that x. Change the line to:


if (rectPos > (int)window.getSize().x)


See if that helps

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Advertisement
Thank you!
Here's another idea/technique you could take into consideration: Use the MVC framework. Don't even worry about drawing or graphics.

I'm currently working on a game and all of my coding is in a Win32 Console application. Rather than getting bogged down in graphics, rendering, art assets, input controls, etc. I'm focusing exclusively on the game model. I can focus on the game play logic, game mechanics, object inheritance and class structure, object interactions, etc. without wasting time on platform/API specific code. I can change the game model at my leisure, advance to the next frame when I'm ready, examine how the game state changed, tweak more variables, run other tests, and verify whether everything worked as expected.

At the end, my game is all contained within a model. Then, when I port it over to a platform, I only have to worry about how to represent the state of the model (through graphical representation of objects, or "the view") and how to interact with the model (user input and controllers).

This seems to work pretty well with test driven development. I can try out all of the "happy" cases to make sure that they are functional, and then I can try all of the cases which should not be allowed via game logic (like casting a spell without mana, or shooting a gun without ammo).

This topic is closed to new replies.

Advertisement