/* *-------------------------------------- * Program Name: LAND LOONS * Author: Rodger "Iambian" Weisman * License: BSD (See LICENSE file) * Description: Dodge the mines and deliver packages *-------------------------------------- */ #define VERSION_INFO "v0.1" #define TRANSPARENT_COLOR 0xF8 #define SKYCOLOR 0x1F #define MINIMUM_MINE_INTERVAL 90 #define JEEPPOS 30 #define JEEPWIDTH 32 #define GM_TITLE 0 #define GM_GAMEPLAY 1 #define GM_DYING 2 #define GM_GAMEOVER 3 #define GM_PICKUP 4 #define GMBOX_X (LCD_WIDTH/4) #define GMBOX_Y (LCD_HEIGHT/2-LCD_HEIGHT/8) #define GMBOX_W (LCD_WIDTH/2) #define GMBOX_H (LCD_HEIGHT/4) /* Keep these headers */ #include #include #include #include /* Standard headers (recommended) */ #include #include #include #include /* External library headers */ #include #include #include #include #include #include /* Import graphics */ #include "gfx/loonjeep_gfx.h" #include "gfx/wheels_gfx.h" #include "gfx/dune_gfx.h" #include "gfx/mine_gfx.h" #include "gfx/background.h" #include "gfx/explosion_gfx.h" #include "gfx/postoffice_gfx.h" #include "gfx/title_gfx.h" #include "gfx/cactus_gfx.h" /* Put your function prototypes here */ void drawbg(); void drawjeep(); void movejeep(); void loadstage(); void drawdebug(); void addmine(); //--- void putaway(); void interrupt isr_on(void); void keywait(); void waitanykey(); void centerxtext(char*,int); /* Put all your globals here */ int curx,cury,prevx,prevy,camx,camy,sprx,spry,debugvalue,mineindex; int mapwidth,difficulty,suicide; int nomines; //post office at 320+JEEPPOS+32 mark, if nonzero, no mines will spawn int gamemode; int levelmaxlen,levelcurlen; int packagesdelivered; unsigned int curscore; unsigned int highscore; int minefield[8]; int cactusfield[16]; gfx_image_t *tmp_ptr; gfx_image_t *loonjeep; gfx_image_t *jeepwheels[2]; gfx_image_t *stage_tileset[64]; gfx_image_t *explosion_sprite; gfx_tilemap_t tilemap; gfx_image_t *mine; uint8_t tilemap_map[2048+16]; gfx_image_t *postoffice_sprite; gfx_image_t *title_sprite; gfx_image_t *cactus_sprite; ti_var_t slot; const char *gameoverdesc[] = {"Your loon exploded.","The package was lost.","Your jeep broke.","You had only one job"}; const char *gameoverquit = "SELF-DESTRUCT MODE"; const char *gameovertext = "Game Over"; const char *gamestart1 = "Received package!"; const char *gamestart2 = "Get ready!"; const char *checkpoint1 = "Dropped off package!"; const char *checkpoint2 = "Got another package!"; const char *title1 = "Press [2nd] to start game"; const char *title2 = "Press [MODE] to quit"; char *tmp_str; void main(void) { int x,y,i,j; kb_key_t k; malloc(0); /* Initialize system */ gfx_Begin(gfx_8bpp); gfx_SetDrawBuffer(); gfx_SetTransparentColor(TRANSPARENT_COLOR); gfx_SetClipRegion(0,0,320,240); ti_CloseAll(); // int_Initialize(); // int_SetVector(ON_IVECT,isr_on); // int_EnableConfig = INT_ON; // int_Enable(); /* Initialize data */ highscore = 0; slot = ti_Open("LLOONDAT","r"); if (slot) ti_Read(&highscore,sizeof highscore, 1, slot); ti_CloseAll(); for (i=0;i<64;i++) stage_tileset[i] = NULL; for (i=0;i<16;i++) cactusfield[i] = 0; cactus_sprite = gfx_MallocSprite(16,22); dzx7_Turbo(cactus_compressed,cactus_sprite); title_sprite = gfx_MallocSprite(246,27); dzx7_Turbo(title_compressed,title_sprite); explosion_sprite = gfx_MallocSprite(48,48); postoffice_sprite = gfx_MallocSprite(32,32); dzx7_Turbo(postoffice_compressed,postoffice_sprite); tmp_ptr = gfx_MallocSprite(8,8); dzx7_Turbo(mine_compressed,tmp_ptr); mine = tmp_ptr; tmp_ptr = gfx_MallocSprite(32,32); dzx7_Turbo(loonjeep_compressed,tmp_ptr); loonjeep = tmp_ptr; for (i=0;i<2;i++) { tmp_ptr = gfx_MallocSprite(32,8); dzx7_Turbo(wheels_ts_tiles_compressed[i],tmp_ptr); jeepwheels[i] = tmp_ptr; } // The game loop while (1) { i++; kb_Scan(); switch(gamemode) { case GM_TITLE: // Title screen gfx_SetTextFGColor(0x08); //xlibc darkblue gfx_FillScreen(SKYCOLOR); gfx_TransparentSprite(title_sprite,(LCD_WIDTH-246)/2,15); centerxtext(title1,110); centerxtext(title2,130); gfx_SetTextXY(5,230); gfx_PrintString("HIGH SCORE: "); gfx_PrintUInt(highscore,8); gfx_SetTextXY(290,230); gfx_PrintString(VERSION_INFO); gfx_SwapDraw(); keywait(); //make sure keys are released before continuing while (1) { kb_Scan(); k = kb_Data[1]; if (k == kb_2nd) break; if (k == kb_Mode) putaway(); } // Initialize gameplay if reach this far. loadstage(); nomines = LCD_WIDTH; difficulty = 64; curx = 10*256; prevx = 4*256; curscore = prevy = cury = 0; levelmaxlen = levelcurlen = 200; packagesdelivered = 0; for (i=0;i<8;i++) minefield[i] = 0; suicide = 0; movejeep(); //keep this here to get over game stop condition drawbg(); drawjeep(); //Display welcome message gfx_SetColor(0x08); //xlibc dark blue gfx_FillRectangle(GMBOX_X,GMBOX_Y,GMBOX_W,GMBOX_H); gfx_GetStringWidth(tmp_str); gfx_SetTextFGColor(0xDF); centerxtext(gamestart1,GMBOX_Y+15); centerxtext(gamestart2,GMBOX_Y+35); gfx_SwapDraw(); waitanykey(); gamemode = GM_GAMEPLAY; break; case GM_GAMEPLAY: // Normal gameplay if ((kb_Data[kb_group_1] == kb_2nd) && !cury && !prevy) { prevy = -(25*256); //jump } if (kb_Data[kb_group_1] == kb_Mode) { gamemode = GM_DYING; suicide = 1; } //Every fifth tick, inc score and roll for mine placement if (i > 5) { curscore++; i = 0; j = randInt(0,255); if (j>9; // diff/256/2 if (nomines>LCD_WIDTH-j && nomines < LCD_WIDTH+j+1) gamemode = GM_PICKUP; levelcurlen--; break; case GM_DYING: if (i>20) { gamemode++; while (kb_AnyKey()); //wait until all keys released before advancing break; } drawbg(); if (i<5) drawjeep(); if (i<10) { dzx7_Turbo(explosion_ts_tiles_compressed[i],explosion_sprite); gfx_TransparentSprite(explosion_sprite,28,LCD_HEIGHT-48); } gfx_SwapDraw(); break; case GM_GAMEOVER: gfx_SetColor(0x08); //xlibc dark blue gfx_FillRectangle(GMBOX_X,GMBOX_Y,GMBOX_W,GMBOX_H); tmp_str = gameoverdesc[randInt(0,3)]; if (suicide) tmp_str = gameoverquit; gfx_GetStringWidth(tmp_str); gfx_SetTextFGColor(0xDF); centerxtext(tmp_str,GMBOX_Y+15); centerxtext(gameovertext,GMBOX_Y+35); gfx_SwapDraw(); waitanykey(); if (curscore>highscore) highscore = curscore; gamemode = GM_TITLE; break; case GM_PICKUP: movejeep(); //keep this here to get over game stop condition drawbg(); drawjeep(); //Display welcome message gfx_SetColor(0x08); //xlibc dark blue gfx_FillRectangle(GMBOX_X,GMBOX_Y,GMBOX_W,GMBOX_H); gfx_GetStringWidth(tmp_str); gfx_SetTextFGColor(0xDF); centerxtext(checkpoint1,GMBOX_Y+10); centerxtext(checkpoint2,GMBOX_Y+25); centerxtext(gamestart2,GMBOX_Y+40); gfx_SwapDraw(); waitanykey(); levelcurlen = levelmaxlen += 30; if (difficulty<255) difficulty += 4; packagesdelivered++; curscore += packagesdelivered*100; gamemode = GM_GAMEPLAY; break; default: putaway(); } } /* Exit */ putaway(); } /* Put other functions here */ void drawbg() { int i,j,x; gfx_FillScreen(SKYCOLOR); tilemap.y_loc = camy; gfx_Tilemap(&tilemap,camx/2,0); for (i=0,x=(camx&15)-16;i<21;i++,x+=16) gfx_Sprite(stage_tileset[15],x,LCD_HEIGHT-16); for (i=0;i<16;i++) { j = cactusfield[i]; if (j) gfx_TransparentSprite(cactus_sprite,j-16,LCD_HEIGHT-15-22); } for (i=0;i<8;i++) { j = minefield[i]; if (j) { gfx_TransparentSprite(mine,j-8,LCD_HEIGHT-12); } } gfx_SetTextFGColor(0x08); //xlibc darkblue gfx_SetTextXY(5,5); gfx_PrintString("SCORE: "); gfx_PrintUInt(curscore,8); gfx_SetTextXY(5,15); gfx_PrintString("PACKS: "); gfx_PrintInt(packagesdelivered,4); x = nomines-LCD_WIDTH; if (x>-60 || x>8; } else { cury = t; } t = mapwidth<<8; if (curx>t) { curx = curx - t; prevx = prevx - t; } t = nomines - (dx>>8); if (nomines) nomines = (t>0) ? t : 0; for (i=0;i<8;i++) { t = minefield[i]-(dx>>8); t = minefield[i] = (t>0) ? t : 0; if (t>JEEPPOS+2+8 && t>8); t = cactusfield[i] = (t>0) ? t : 0; } sprx = 30; spry = LCD_HEIGHT - 32 - 8 - (cury>>8); camx = (curx>>8)%mapwidth; camy = 0; } void loadstage() { int i,ntiles,mwidth,mheight; uint8_t **c_tset; uint8_t *c_tmap; // This is the only stage. ntiles = 16; mwidth = 128; mheight = 15; c_tset = dune_ts_tiles_compressed; c_tmap = dunemap_compressed; // Load tilemap graphics for (i=0;i(LCD_WIDTH+8-MINIMUM_MINE_INTERVAL)) j++; } if (j || nomines) return; for (i=0;i<8;i++) { if (!minefield[i]) { minefield[i] = LCD_WIDTH+8; break; } } return; } void drawdebug() { static int i=0; i++; gfx_SetTextXY(10,5); gfx_PrintInt(i,4); gfx_SetTextXY(50,5); gfx_PrintChar('X'); gfx_PrintChar(':'); gfx_PrintInt(curx>>8,5); gfx_SetTextXY(120,5); gfx_PrintChar('Y'); gfx_PrintChar(':'); gfx_PrintInt(cury>>8,4); gfx_SetTextXY(10,15); gfx_PrintInt(debugvalue,4); gfx_SetTextXY(50,15); gfx_PrintChar('C'); gfx_PrintChar('X'); gfx_PrintChar(':'); gfx_PrintInt(camx,5); gfx_SetTextXY(120,15); gfx_PrintChar('C'); gfx_PrintChar('Y'); gfx_PrintChar(':'); gfx_PrintInt(camy,4); gfx_SetTextXY(50,25); gfx_PrintChar('S'); gfx_PrintChar('X'); gfx_PrintChar(':'); gfx_PrintInt(sprx,5); gfx_SetTextXY(120,25); gfx_PrintChar('S'); gfx_PrintChar('Y'); gfx_PrintChar(':'); gfx_PrintInt(spry,4); } //======================================================================== void interrupt isr_on(void) { int_Acknowledge = INT_ON; putaway(); } void putaway() { // int_Reset(); gfx_End(); slot = ti_Open("LLOONDAT","w"); ti_Write(&highscore,sizeof highscore, 1, slot); ti_CloseAll(); exit(0); } void waitanykey() { keywait(); //wait until all keys are released while (!kb_AnyKey()); //wait until a key has been pressed. while (kb_AnyKey()); //make sure key is released before advancing } void keywait() { while (kb_AnyKey()); //wait until all keys are released } void centerxtext(char* strobj,int y) { gfx_PrintStringXY(strobj,(LCD_WIDTH-gfx_GetStringWidth(strobj))/2,y); }