Runs fine here. =)
More things I noticed:
1) Moving backwards is still allowed. I don't see anywhere where you're trying to prevent it. Looks like keydown messages go straight to game_input which directly sets the snake's direction.
2) You have a small memory leak. ~8K a second. Run the program with Task manager open and watch the memory footprint of the program climb and climb. It only happens in the actual game part, so the issue is likely in game_play or one of the functions it calls. I haven't looked any more into it.
3) You get a compiler warning, and for good reason:
1 2 3 4 5
|
HDC hDC;
MSG msg;
_game.game_getvars(hDC, hWnd);
|
hDC is uninitialized, so you're basically giving game_getvars a bad DC. It doesn't seem to affect anything so the DC probably just isn't being used. If that's the case, you should probably get rid of that function (or at least don't pass a DC to it)
4) Your
while(clock() < wait){}
loop does not play nice in multitasking environments and sucks life out of laptop batteries. Failure to sleep causes your program to eat up 100% CPU time.
5) You don't seem to be doing complete rendering, but rather are only updating the snake as he moves. This also doesn't play nice in a multitasking environment. Try this out:
- start the game
- switch to another window... one that overlaps your game window or is maximized.
- switch back to your game
- game is now unplayable
It's also worth noting that most of these tricky problems are due to the complexities of WinAPI. If you were using a game lib like SFML you wouldn't be having these issues.
CreativeMFS wrote: |
---|
It should be 100% bug free |
It never is. ;)