Snake game finished - check it out

Pages: 1234
I'm a semi-regular on the SFML forums, and from the looks of it, he's working out the details for the new graphic API, but once that's done and the code is complete, SFML 2.0 will effectively be done and released. IIRC it was projected to be another month or two.


Alright. Thank you for the clarification.

-Albatross
While we're at SFML - where can I look up the differences between SFML and SFML2? I personally always liked Allegro (despity my predispositions against C), but the "Can be integrated into components of existing Qt / MFC / wxWidgets / Win32 / X11 / ... interfaces" line made me interested. Really interested.

Oh, and does SFML provide a file system interface? Or am I better off continuing to use PhysFS?
Last edited on
closed account (zwA4jE8b)
@Disch

So in my message loop I need a case for WM_PAINT and use BEGIN/END_PAINT in there?

as far as the 'mdc' I would declare that in my gamengine class and use a render function like so...

1
2
3
4
5
6
void game_render()
{
HDC hDC = GetDC(hWnd);
//blit mdc to hDC
ReleaseDC(hWnd, hDC);
}


and call this render function once per frame.
hanst99 wrote:
While we're at SFML - where can I look up the differences between SFML and SFML2?


I don't know if there's a place that outlines all of it yet. There was a thread on the SFML boards that had a general overview of the big changes, but I couldn't find it. I don't think an official list has been made because SFML2 is still undergoing changes.

Oh, and does SFML provide a file system interface? Or am I better off continuing to use PhysFS?


It doesn't. Keep using PhysFS. I actually have "SFSL" as a side project which is basically a file system lib for use with SFML, but I haven't had time to work on it lately.

One of the additions to SFML2 was the ability to use custom loaders to load resources like images/fonts/etc. So if you want to use PhysFS with it, all you have to do is write an implementation class that's derived from sf::InputStream and it'll fit right in. All you need to do is fill in read/seek/tell functions.

CreativeMFS wrote:
So in my message loop I need a case for WM_PAINT and use BEGIN/END_PAINT in there?


Yes. Remember that BeginPaint will give you the screen DC, and that's the DC you'd want to draw to. You do not want to use BeginPaint and GetDC at the same time.

I would probably do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void game_render(HWND wnd)  // called every frame
{
  HDC hDC = GetDC(wnd);
  game_render(hDC);
  ReleaseDC(wnd,hDC);
}

void game_render(HDC screen)
{
  // blit mdc to screen
}

//... in your WndProc/message handler
case WM_PAINT:
  PAINTSTRUCT ps;
  HDC screen = BeginPaint(wnd,&ps);
  game_render(screen);
  EndPaint(wnd,&ps);
  break;


Don't worry about the PAINTSTRUCT thing. That's just something BeginPaint/EndPaint use to keep track of this particular painting instance. You don't need to initialize it or anything.
closed account (zwA4jE8b)
Thank you, i am going to implement that, ill post how it works out.
Last edited on
One of the additions to SFML2 was the ability to use custom loaders to load resources like images/fonts/etc


Awesome - I was already thinking of writing some wrappers for PhysFS, but I guess I'll wait with that now until 2 is out.
closed account (zwA4jE8b)
It mostly works now. That bug #5 is fixed.
I am not sure if I am calling render in the right place

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

	ShowWindow(hWnd, nCmdShow);

	MSG msg;

	_game.game_gethwnd(hWnd);
	_game.game_setstate('i');

	while(TRUE)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			_game.game_state();
			_game.game_render();
			_game.game_framerate();
		}
	}
	return msg.wParam;
}




Updated mediafire.

damn, now that I have this method of drawing there is so much I want to restructure.
Last edited on
Wherever makes the most sense ;P

They need to have a scope that keeps them alive for the duration of the program. So wherever you put them has to accomplish that.
closed account (zwA4jE8b)
Well Disch thank you for all your time and help.

The game is so much better than before. I have also done some restructuring.

1) No longer use pointers for level and snake objects
2) Level Splash screen added
3) Graphic bugs fixed (at least all that I know of)
4) Highscore updates dynamically
5) Updated input function, no longer uses GetAsyncKeyState()

There might be some misc cleanup but I can get to that later.

Anyone who had trouble playing it before try it now!

http://www.mediafire.com/?db959tciirdd0
Last edited on
closed account (zwA4jE8b)
Version 2.0 is out.

Added music
Added wrap around functionality (modern snake)
I just noticed:

1
2
3
4
5
6
7
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) // <-  this should be while, not if
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}


If it's an if statement, that means you're only processing at most 1 message per frame. In the (very likely) event that windows sends your program more messages than that, they will back up in the queue and make your program become unresponsive.

Changing it to a while loop makes it so you completely empty the queue every frame.
closed account (zwA4jE8b)
cool, will change that. makes sense, maybe that will improve the input handling for direction.

edit: when I change that to while it freezes on end game.
Last edited on
closed account (zwA4jE8b)
Added designed level for modern mode. 7 total.

http://www.mediafire.com/?db959tciirdd0
Me Gusta.

Now for particle effects?
closed account (zwA4jE8b)
Gracias,

you create em and ill paste it in ;)
Do they have to be efficient? =]
closed account (zwA4jE8b)
They shouldn't slow it down.

But it's a pretty basic game anyway, almost no cpu usage.


So i guess no, not really.
Awesome, then I'll make some really simple ones, I could port your code to SDL and make it a titch easier- or I could just whip up a quick snake game in SDL and you can use the particles in your own game?
closed account (zwA4jE8b)
if you want to port it to sdl that would be awesome. then I can crash course myself into learning the lib.
no no!!! SFML!!!!

Don't use SDL =(

At least not until it updates. It's so stale and dated.
Last edited on
Pages: 1234