#include #include #include "global.h" #include "background.h" #include "bullets.h" #include "enemies.h" #include "humans.h" #include "player.h" #include "stage.h" #include "chrome.h" #include "start.h" #include "sfx.h" static void loadInternals(){ JOY_init(); JOY_setEventHandler(&updateControls); SPR_init(); VDP_setPlaneSize(128, 32, TRUE); VDP_loadFont(font.tileset, DMA); PAL_setPalette(PAL0, font.palette->data, DMA); PAL_setPalette(PAL1, shadow.palette->data, CPU); VDP_setTextPriority(1); } void clearLevel(){ for(s16 i = 0; i < BULLET_COUNT; i++) if(bullets[i].active) killBullet(i, FALSE); for(s16 i = 0; i < ENEMY_COUNT; i++) if(enemies[i].active){ enemies[i].hp = 0; killEnemy(i); } for(s16 i = 0; i < HUMAN_COUNT; i++) if(humans[i].active) killHuman(i); humanBeingCarried = FALSE; collectedCount = 0; // black out everything SPR_setVisibility(player.image, HIDDEN); VDP_clearTileMapRect(BG_A, 0, 0, 128, 32); VDP_clearTileMapRect(BG_B, 0, 0, 128, 32); } void loadGame(){ loadBackground(); loadPlayer(); loadChrome(); loadLevel(0); XGM2_play(stageMusic); XGM2_setFMVolume(MUSIC_VOLUME); XGM2_setPSGVolume(MUSIC_VOLUME); player.recoveringClock = 120; killBullets = TRUE; started = TRUE; } static void updateGame(){ updateChrome(); updateSfx(); if(levelClearing){ levelClearClock++; if(levelClearClock == 1){ clearLevel(); } if(levelClearClock >= 120){ levelClearing = FALSE; loadBackground(); loadChrome(); loadLevel(level + 1); XGM2_play(stageMusic); SPR_setVisibility(player.image, VISIBLE); player.recoveringClock = 120; killBullets = TRUE; } return; } if(!paused){ updatePlayer(); updateBackground(); if(clock % 2 == 0){ updateEnemies(); if(!gameOver && enemyCount == 0){ if(level >= LEVEL_COUNT - 1){ gameOver = TRUE; XGM2_stop(); } else { levelClearing = TRUE; levelClearClock = 0; XGM2_stop(); } } updateHumans(); } else { updateBullets(); } } } int main(bool hardReset){ loadInternals(); loadStart(); while(1){ if(started) updateGame(); else updateStart(); clock++; if(clock >= CLOCK_LIMIT) clock = 600; SPR_update(); SYS_doVBlankProcess(); } return(0); }