Simple snake game written in C/SDL under linux, with Code::Blocks. The code can be compiled under windows without any problem. click "U" to speed up click "L" to speed down.
Source Code
//************************************** // Name: Simple Snake Game // Description:Simple snake game written in C/SDL under linux, with Code::Blocks. The code can be compiled under windows without any problem. click "U" to speed up click "L" to speed down // By: Goundy // #include <stdlib.h> #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include <time.h> #define N 500 /*snake max length*/ #define NODESIZE 10 /*node height & width*/ #define WINSIZE 400 /*window height & width*/ /********************************* types **************************************/ typedef enum {Up, Down, Right, Left}TDirection; /*possible direction type*/ /******************************************************************************/ /********************************* ecran **************************************/ SDL_Surface* screen = NULL; /*main screen*/ SDL_Surface* Table[N] = {NULL}; /*snake node table*/ SDL_Surface* blank; /*background (will be totaly wait)*/ SDL_Surface* puce; /*snake puce*/ /******************************************************************************/ /********************************* positions **********************************/ SDL_RectTabpos[N], /*snake node positions*/ ppuce; /*puce positions*/ /******************************************************************************/ /*********************************** other ***********************************/ int NodeCounter; /*snake node counter*/ TDirection direction; /*current direction*/ SDL_TimerID timer; /*timer descriptor*/ /******************************************************************************/ /************************* functions Prototypes ***************************/ Uint32 Anime_it (Uint32, void *); int snakeColl(void); void Quitter(void); // will be executed when exiting the game void SetPos(void); void MoveSnake (void); void Show (void); void PurgeScreen (void); void SetPuce(void); void Lose (void); void freeNodes (void); void AddNode(void);
Download Full Source Code: Click Here
Output
Also Read: Program To Find Whether A Number Is Prime Or Not
Also Read : Program to find factorial of Number in C++
0 comments:
Post a Comment