Source: mymsnake.mak # ********************************************************************************************************************** Name: Makefile # Project: mymsnake My Mobile Greed Snake # Date: 2004-10-09 # by: gaogao goithfox@163.com# # US dollar Right bracket # # ************ *****************************
# ************************************************** # Flags # ***** ********************************** CFLAGS = -O2 -wall -fvstudio
# **************************************** # Objektfiles # ***** ********************************** Objs = res.o mymsnake.o
All: mymsnake.mpn
# **************************************** # resource # ***** ******************************************* Res.: res.txt morc -v res.txt
# *************************************** # compiler # ***** *******************************************. CO: PIP-GCC -C $ (cflags) -o $ @ <
# ***************************************** # linker # ***** ***************************************************** MYMSNAKE.MPN: $ (OBJS) PIP-GCC -O $ @ $ (Objs) -mstack = 1024 -mdata = 10000-LDATACERT -S
??????????????????????????????????????????? ??????????????????????????????????????? MYMSNAKE.H // ********* ****************************************** / / Mophun version for eating snake version for SE T618 @ @ Author USD Right Brand // @version 0.01 @Connect GoThfox@163.com// ************************************************ ****************
#ifndef mymsnake_h # define mymsnake_h
#include
Snake body size #define SNAKE_ELEMENT_SIZE // // direction element 8 #define UP_DIRECTION 0 # define DOWN_DIRECTION 1 # define LEFT_DIRECTION 2 # define RIGHT_DIRECTION 3 // map in the initial state #define EMPTY 0 // Snake1 map is a map of the body typedef struct state storage body #define SNAKE_IN 1 // Snake2 map is a map of the physical state of the snake #define SNAKE_OVERFLOW 2 // {struct SnakeElement * next; int16_t x; int16_t y; int16_t direction;} SnakeElement; // snake of Head and tail pointer SnakeElement * snakehead, * snaketail;
// Snake's food storage typef struct {INT16_T X; INT16_T Y; INT16_T VAR;} Snakefood;
// Whether the food is eating int16_t isfoodbeeaten = false;
// Cute greedy snake died because of greed? INT16_T ISTHESNAKEDEAD = FALSE;
// Map of wide #define x_max 16 // map high #define y_max 20 // Map storage INT16_T BackgroundArray [y_max] [x_max];
// Eat the initial position of the snake setting #define x_init 8 # Define y_init 10
// Game counter #define level letter_num 10int16_t level_counter [] = {30, 25, 20, 18, 16, 13, 11, 10, 5, 3}; Level_numint16_t currentlevel = 0; int16_t counter = 0;
// Food's initial position snakefood snakefood; #define frame_controler 30
// Method Void InIntgame (Void); // Initialize the screen void getScreensize (void); // Initialize the font void initfont (void); // Map Initiation Void Initmap (Void); // Greedy Snake InitSnake (Void) ; // Move the greedy snake void movesnake (void); // Generate food void generatefood (void); // Draw a game scene void PaintObjects (void); // Destroy the memory fragment void destroyObjects (Void) in all games;
#ENDIF
??????????????????????????????????????????? ????????????????????????????????***************** *********************************************************************************************** Brand // @version 0.01 @Connect headithfox@163.com// ******************************************* ************ # include "mymsnake.h"
Void inIntgame (void) {isthesnakedead = false; isfoodbeeaten = false; currentlevel = 0; counter = 0;}
// ******************************************************** ******* // Get screen size // ******************************************** ******************* void getScreenSize (void) {VIDEOCAPS videocaps; videocaps.size = sizeof (VIDEOCAPS); if (vGetCaps (CAPS_VIDEO, & videocaps)) {screen_width = videocaps = VideoCaps.Height;}} // ************************************************ ***************** // New font // ********************************** ************************************** VOID INITFONT (VOID) {fonta.width = 4; fonta.height = 6; fonta.bpp = 1; fonta.palindex = 0; fonta.chartbl = fonta 16; fonta.fontdata = fonta 16 256; vsetactivefont (& fonta);} // map initialization void initmap (void) {Int i = 0, j = 0; for (i = 0; i SnakeElement * temp; snakeTail = (SnakeElement *) malloc (sizeof (SnakeElement)); snakeTail-> x = X_INIT - 3; snakeTail-> y = Y_INIT; snakeTail-> direction = RIGHT_DIRECTION; snakeTail-> next = (SnakeElement *) Malloc (SNAKEELEMENT)); Temp = SnakeTail-> Next; Temp-> x = x_init - 2; Temp-> Y = Y_INIT; TEMP-> Direction = Right_Direction; Temp-> Next = (SnakeElement *) Malloc (Sizeof (SnakeElement); temp = temp-> next; temp-> x = x_init - 1; temp-> y = y_init; temp-> Direction = Right_Direction; Temp-> Next = (SnakeElement *) Malloc (Strib (SnakeElement) ); Temp = temp-> next; temp-> y = y_init; temp-> Direction = Right_Direction; temp-> next = null; snakehead = Temp; BackgroundArray [y_init] [x_init - 3] = Snake_in; backgroundArray [y_init] [x_init - 2] = snake_in; backgroundArray [y_init] [x_init - 1] = snake_in; backgroundArray [y_init] [x_init - 0] = snake_in;} // Mobile Greed Snake Voidsnake (void ) {// Clean up not BackgroundArray; snakelement * temp = snaketail; while (temp! = Null) {BackgroundArray [TEMP-> Y] [T emp-> x] = EMPTY; temp = temp-> next;} // move Snake SnakeElement * tempTailToo = (SnakeElement *) malloc (sizeof (SnakeElement)); tempTailToo-> x = snakeTail-> x; tempTailToo-> y = SnakeTail-> Y; TemptailToo-> Direction = snaketail-> Direction; snakeElement * TempNew Head = snaketail; snaketail = snaketail-> next; tempnewhead-> next = NULL; switch (snakeHead-> direction) {case UP_DIRECTION: tempNewHead-> y = snakeHead-> y - 1; tempNewHead-> x = snakeHead-> x; tempNewHead-> direction = snakeHead-> direction; break; case DOWN_DIRECTION: tempNewHead- > y = snakeHead-> y 1; tempNewHead-> x = snakeHead-> x; tempNewHead-> direction = snakeHead-> direction; break; case LEFT_DIRECTION: tempNewHead-> x = snakeHead-> x - 1; tempNewHead-> y = snakeHead-> y; tempNewHead-> direction = snakeHead-> direction; break; case RIGHT_DIRECTION: tempNewHead-> x = snakeHead-> x 1; tempNewHead-> y = snakeHead-> y; tempNewHead-> direction = snakeHead -> direction; break;} snakeHead-> next = tempNewHead; snakeHead = snakeHead-> next; if (snakeHead-> x == snakeFood.x && snakeHead-> y == snakeFood.y) {isFoodBeEaten = TRUE;} if (isFoodBeEaten == TRUE) {// isFoodBeEaten = FALSE; tempTailToo-> next = snakeTail; snakeTail = tempTailToo; generateFood ();} // after moving temp = snakeTail; while (temp = NULL!) {backgroundArray [temp-> Y] [TEMP-> x] = snake_in; if (Ba CkgroundArray [Temp-> Y] [Temp-> X]> Snake_in) {iSthesnakeDead = true;} Temp = Temp-> Next;} if (snakehead-> x <0 || snakehead-> y <0 || snakehead- > x> = x_max || snakehead-> y> = y_max) {isthesnakedead = true;}} // Generate food void generatefood (void) {if (isfoodbeeaten == false) {Return;} else {INT X; int y ; vsetrandom (Vgettime ()); x = ABS (VgetrandOM ()% x_max); vsetrandom (Vgettime ()); y = ABS (vgetrandom ()% y_max); if (BackgroundArray [Y] [x] == EMPTY) { Snakefood.x = x; snakefood.y = y; snakefood.var = 1; isfoodbeeaten = false;} generatefood ();}} // Draw game scene void PaintObjects (void) {SnakeElement * Temp = snaketail; // - - INIT Graphics ------------------------------- vsetclipwindow (0, 0, screen_width, screen_height); // set Maximum Clipwindow vSetForeColor (vRGB (255,255,255)); // White forecolor vSetBackColor (vRGB (0,0,0)); // Black background vClearScreen (vRGB (0,0,0)); // Fill Screen with black vSetTransferMode ( Mode_Trans); // set transfer mode to transparent while (temp = NULL!) {vDrawObject (temp-> x * SNAKE_ELEMENT_SIZE, temp-> y * SNAKE_ELEMENT_SIZE, & MYSPRITE); temp = temp-> next;} vDrawObject (snakeFood.x * SNAKE_ELEMENT_SIZE, snakeFood.y * SNAKE_ELEMENT_SIZE, & MYSPRITE ); Vflipscreen (1);} // destroy all games in memory fragment void destroyObjects (void) {} int main (void) { initGame (); InitFont (); GetScreenSize (); initMap (); initSnake (); uint32_t frame; int16_t currentDirection = snakeHead-> direction; while (1) {switch (vGetButtonData ()) {case KEY_UP: if (currentDirection! = DOWN_DIRECTION) {snakeHead-> direction = UP_DIRECTION;} break; case KEY_DOWN:! if (currentDirection = UP_DIRECTION) {snakeHead-> direction = DOWN_DIRECTION;} break; case KEY_LEFT:! if (currentDirection = RIGHT_DIRECTION) {snakeHead-> direction = LEFT_DIRECTION;} break; case KEY_RIGHT: if (! currentDirection = LEFT_DIRECTION) {snakeHead-> direction = RIGHT_DIRECTION;} break;} frame = vGetTickCount (); if (counter > level_counter [currentLevel]) {counter = 0; if ( iSthesnakedead! = true) {movesnake (); currentdirection = snakehead-> direction;}} PainTObjects (); while (vgettickcount () - frame // ******************************************************** ******************************************************* / / CERTIFICATION STUFF // ********************************************************* ******************************************************** DATACT_AND_SECURITY_RESOURCREDITS DATA {Fill 32,0} Section data // ************************************************ // THE FONT / / *************************************************** FontA Data "GFX / SystemFont4x6.fnt "TILES TILESet 8 8 Format RGB332" GFX / TILES.BMP "mysprite sprite format RGB332" gfx / sprite.bmp " image display: