shit!
This commit is contained in:
parent
1702a06d9f
commit
364a34ce33
20 changed files with 453 additions and 64 deletions
117
src/chrome.h
117
src/chrome.h
|
|
@ -2,18 +2,55 @@
|
|||
#define MAP_TILE TILE_ATTR_FULL(PAL1, 1, 0, 0, MAP_I)
|
||||
#define MAP_PLAYER_TILE TILE_ATTR_FULL(PAL0, 1, 0, 0, MAP_I + 1)
|
||||
#define MAP_ENEMY_TILE TILE_ATTR_FULL(PAL0, 1, 0, 0, MAP_I + 2)
|
||||
#define MAP_BORDER_X_TILE TILE_ATTR_FULL(PAL0, 1, 0, 0, MAP_I + 3)
|
||||
#define MAP_HUMAN_TILE TILE_ATTR_FULL(PAL0, 1, 0, 0, MAP_I + 3)
|
||||
#define MAP_BORDER_X_TILE TILE_ATTR_FULL(PAL0, 1, 0, 0, MAP_I + 4)
|
||||
|
||||
#define FONT_BIG_I 256
|
||||
|
||||
void bigText(char* str, u16 x, u16 y, bool shadow){
|
||||
for(u8 i = 0; i < strlen(str); i++){
|
||||
if(str[i] >= 48){
|
||||
VDP_setTileMapXY(BG_A, TILE_ATTR_FULL(PAL0, 1, 0, 0, (shadow ? 32 : 0) + FONT_BIG_I + str[i] - 48), x + i, y);
|
||||
VDP_setTileMapXY(BG_A, TILE_ATTR_FULL(PAL0, 1, 0, 0, (shadow ? 32 : 0) + FONT_BIG_I + 16 + str[i] - 48), x + i, y + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char scoreStr[SCORE_LENGTH];
|
||||
u32 lastScore;
|
||||
s16 scoreLength;
|
||||
|
||||
#define SCORE_X 1
|
||||
#define SCORE_Y 5
|
||||
|
||||
#define LIFE_I (FONT_BIG_I + 64)
|
||||
#define LIVES_X 38
|
||||
#define LIVES_Y 5
|
||||
s16 lastLives;
|
||||
|
||||
static void drawLives(){
|
||||
VDP_clearTileMapRect(BG_A, LIVES_X, LIVES_Y, 1, 16);
|
||||
for(u8 i = 0; i < (player.lives - 1); i++)
|
||||
VDP_fillTileMapRectInc(BG_A, TILE_ATTR_FULL(PAL0, 1, 0, 0, LIFE_I + (i > 0 ? 2 : 0)), LIVES_X, LIVES_Y + i, 1, 2);
|
||||
lastLives = player.lives;
|
||||
}
|
||||
|
||||
// previous map positions: -1 means not drawn
|
||||
s16 mapEnemyCol[ENEMY_COUNT], mapEnemyRow[ENEMY_COUNT];
|
||||
s16 mapHumanCol[HUMAN_COUNT], mapHumanRow[HUMAN_COUNT];
|
||||
s16 mapPlayerRow;
|
||||
|
||||
static void drawScore(){
|
||||
uintToStr(score, scoreStr, 1);
|
||||
VDP_drawText(scoreStr, 1, 5);
|
||||
if(lastScore < 10) scoreLength = 1;
|
||||
else if(lastScore < 100) scoreLength = 2;
|
||||
else if(lastScore < 1000) scoreLength = 3;
|
||||
else if(lastScore < 10000) scoreLength = 4;
|
||||
else if(lastScore < 100000) scoreLength = 5;
|
||||
else if(lastScore < 1000000) scoreLength = 6;
|
||||
else if(lastScore < 10000000) scoreLength = 7;
|
||||
else scoreLength = 8;
|
||||
uintToStr(lastScore, scoreStr, scoreLength);
|
||||
bigText(scoreStr, SCORE_X, SCORE_Y, FALSE);
|
||||
}
|
||||
|
||||
// load map when stage does so we have all enemies + player
|
||||
|
|
@ -29,17 +66,24 @@ void loadMap(){
|
|||
mapEnemyCol[i] = -1;
|
||||
mapEnemyRow[i] = -1;
|
||||
}
|
||||
for(s16 i = 0; i < HUMAN_COUNT; i++){
|
||||
mapHumanCol[i] = -1;
|
||||
mapHumanRow[i] = -1;
|
||||
}
|
||||
mapPlayerRow = -1;
|
||||
}
|
||||
|
||||
// temp arrays for new positions
|
||||
s16 mapNewCol[ENEMY_COUNT], mapNewRow[ENEMY_COUNT];
|
||||
s16 mapNewHumanCol[HUMAN_COUNT], mapNewHumanRow[HUMAN_COUNT];
|
||||
|
||||
static bool mapTileOccupied(s16 col, s16 row, s16 pRow){
|
||||
// player always at center column
|
||||
if(col == MAP_W / 2 && row == pRow) return TRUE;
|
||||
for(s16 i = 0; i < ENEMY_COUNT; i++)
|
||||
if(mapNewCol[i] == col && mapNewRow[i] == row) return TRUE;
|
||||
for(s16 i = 0; i < HUMAN_COUNT; i++)
|
||||
if(mapNewHumanCol[i] == col && mapNewHumanRow[i] == row) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +111,24 @@ static void updateMap(){
|
|||
mapNewRow[i] = row;
|
||||
}
|
||||
|
||||
// compute new human positions
|
||||
for(s16 i = 0; i < HUMAN_COUNT; i++){
|
||||
if(!humans[i].active || humans[i].image == NULL){
|
||||
mapNewHumanCol[i] = -1;
|
||||
mapNewHumanRow[i] = -1;
|
||||
continue;
|
||||
}
|
||||
fix32 dx = getWrappedDelta(humans[i].pos.x, player.pos.x);
|
||||
s16 col = fix32ToInt(dx) / 54 + MAP_W / 2;
|
||||
if(col < 0) col = 0;
|
||||
if(col >= MAP_W) col = MAP_W - 1;
|
||||
s16 row = fix32ToInt(humans[i].pos.y) / 75;
|
||||
if(row < 0) row = 0;
|
||||
if(row >= MAP_H) row = MAP_H - 1;
|
||||
mapNewHumanCol[i] = col;
|
||||
mapNewHumanRow[i] = row;
|
||||
}
|
||||
|
||||
// clear old player tile if it moved and nothing new occupies it
|
||||
if(mapPlayerRow >= 0 && mapPlayerRow != pRow)
|
||||
if(!mapTileOccupied(MAP_W / 2, mapPlayerRow, pRow))
|
||||
|
|
@ -80,6 +142,23 @@ static void updateMap(){
|
|||
VDP_setTileMapXY(BG_A, MAP_TILE, MAP_X + mapEnemyCol[i], MAP_Y + mapEnemyRow[i]);
|
||||
}
|
||||
|
||||
// clear old human tiles that moved or disappeared
|
||||
for(s16 i = 0; i < HUMAN_COUNT; i++){
|
||||
if(mapHumanCol[i] < 0) continue;
|
||||
if(mapHumanCol[i] == mapNewHumanCol[i] && mapHumanRow[i] == mapNewHumanRow[i]) continue;
|
||||
if(!mapTileOccupied(mapHumanCol[i], mapHumanRow[i], pRow))
|
||||
VDP_setTileMapXY(BG_A, MAP_TILE, MAP_X + mapHumanCol[i], MAP_Y + mapHumanRow[i]);
|
||||
}
|
||||
|
||||
// draw human dots (skip if player occupies same tile)
|
||||
for(s16 i = 0; i < HUMAN_COUNT; i++){
|
||||
mapHumanCol[i] = mapNewHumanCol[i];
|
||||
mapHumanRow[i] = mapNewHumanRow[i];
|
||||
if(mapNewHumanCol[i] < 0) continue;
|
||||
if(mapNewHumanCol[i] == MAP_W / 2 && mapNewHumanRow[i] == pRow) continue;
|
||||
VDP_setTileMapXY(BG_A, MAP_HUMAN_TILE, MAP_X + mapNewHumanCol[i], MAP_Y + mapNewHumanRow[i]);
|
||||
}
|
||||
|
||||
// draw enemy dots (skip if player occupies same tile)
|
||||
for(s16 i = 0; i < ENEMY_COUNT; i++){
|
||||
mapEnemyCol[i] = mapNewCol[i];
|
||||
|
|
@ -95,18 +174,42 @@ static void updateMap(){
|
|||
}
|
||||
|
||||
void loadChrome(){
|
||||
VDP_loadTileSet(imageFontBig.tileset, FONT_BIG_I, DMA);
|
||||
VDP_loadTileSet(imageFontBigShadow.tileset, FONT_BIG_I + 32, DMA);
|
||||
VDP_loadTileSet(imageChromeLife.tileset, LIFE_I, DMA);
|
||||
VDP_loadTileSet(imageChromeLife2.tileset, LIFE_I + 2, DMA);
|
||||
VDP_loadTileSet(mapIndicator.tileset, MAP_I, DMA);
|
||||
lastScore = 1;
|
||||
drawScore();
|
||||
drawLives();
|
||||
}
|
||||
|
||||
bool didGameOver;
|
||||
static void doGameOver(){
|
||||
didGameOver = TRUE;
|
||||
for(s16 i = 0; i < BULLET_COUNT; i++) if(bullets[i].active) SPR_setPalette(bullets[i].image, PAL1);
|
||||
for(s16 i = 0; i < ENEMY_COUNT; i++) if(enemies[i].active) SPR_setPalette(enemies[i].image, PAL1);
|
||||
for(s16 i = 0; i < HUMAN_COUNT; i++) if(humans[i].active) SPR_setPalette(humans[i].image, PAL1);
|
||||
SPR_releaseSprite(player.image);
|
||||
// clear minimap
|
||||
VDP_clearTileMapRect(BG_A, MAP_X, MAP_Y, MAP_W, MAP_H);
|
||||
// clear score
|
||||
VDP_clearTileMapRect(BG_A, SCORE_X, SCORE_Y, SCORE_LENGTH, 2);
|
||||
|
||||
// clear lives
|
||||
VDP_clearTileMapRect(BG_A, LIVES_X, LIVES_Y, 1, 16);
|
||||
|
||||
VDP_drawText("GAME OVER", 15, 13);
|
||||
VDP_drawText("PRESS ANY BUTTON", 12, 14);
|
||||
}
|
||||
|
||||
void updateChrome(){
|
||||
score++;
|
||||
if(score > 99999999) score = 0;
|
||||
if(gameOver && !didGameOver) doGameOver();
|
||||
if(didGameOver) return;
|
||||
if(lastScore != score){
|
||||
lastScore = score;
|
||||
drawScore();
|
||||
}
|
||||
if(lastLives != player.lives) drawLives();
|
||||
if(clock % 4 == 0) updateMap();
|
||||
// VDP_clearText(1, 26, 4);
|
||||
// VDP_drawText(debugStr, 1, 26);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue