some background/foreground work

This commit is contained in:
t. boddy 2022-08-16 17:38:58 -04:00
parent 98631cb721
commit a95f6f043e
10 changed files with 84 additions and 26 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
res/fg/rock1t.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -1,8 +1,10 @@
IMAGE font "font.png" BEST NONE IMAGE font "font.png" BEST NONE
IMAGE frame "chrome/frame.png" FAST
IMAGE bgWall1 "bg/wall1.png" FAST IMAGE wall1 "bg/wall1.png" FAST
IMAGE bgCeil1 "bg/ceil1.png" FAST
IMAGE bgFloor1 "bg/floor1.png" FAST IMAGE rock1 "fg/rock1.png" FAST
IMAGE rock1t "fg/rock1t.png" FAST
SPRITE nitori "player/nitori.png" 4 4 FAST SPRITE nitori "player/nitori.png" 4 4 FAST

View File

@ -1,4 +1,4 @@
// bg // background
#define BG_I 512 #define BG_I 512
@ -11,16 +11,7 @@
static void drawBg(){ static void drawBg(){
for(u16 x = 0; x < BG_W; x++) for(u16 y = 0; y < BG_H; y++){ for(u16 x = 0; x < BG_W; x++) for(u16 y = 0; y < BG_H; y++){
if(x % 8 == 0 && y % 8 == 0){ if(x % 8 == 0 && y % 8 == 0){
VDP_drawImageEx(BG_B, &bgWall1, TILE_ATTR_FULL(PAL2, 0, 0, 0, BG_I), x, y, 0, DMA); VDP_drawImageEx(BG_A, &wall1, TILE_ATTR_FULL(PAL2, 0, 0, 0, BG_I), x, y, 0, DMA);
}
}
}
static void drawFg(){
for(u16 x = 0; x < BG_W; x++){
if(x % 4 == 0){
VDP_drawImageEx(BG_A, &bgCeil1, TILE_ATTR_FULL(PAL2, 0, 0, 0, BG_I + 64), x, 0, 0, DMA);
VDP_drawImageEx(BG_A, &bgFloor1, TILE_ATTR_FULL(PAL2, 0, 0, 0, BG_I + 64 + 12), x, 21, 0, DMA);
} }
} }
} }
@ -28,7 +19,6 @@ static void drawFg(){
// update // update
#define BG_SPEED FIX16(1) #define BG_SPEED FIX16(1)
#define BG_SPEED_NORM FIX16(0.707) #define BG_SPEED_NORM FIX16(0.707)
@ -36,24 +26,27 @@ static void drawFg(){
#define BG_SIZE_F FIX16(BG_SIZE) #define BG_SIZE_F FIX16(BG_SIZE)
s16 bgPosX[WIN_H_T];
fix16 bgPosXF[WIN_H_T];
Vect2D_f16 bgPos; Vect2D_f16 bgPos;
static void scrollBg(){ static void scrollBg(){
bgPos.x = fix16Sub(bgPos.x, BG_SPEED);
// bgPos.y = fix16Add(bgPos.y, BG_SPEED_NORM); for(u8 y = 0; y < WIN_H_T; y++){
if(bgPos.x <= -BG_SIZE_F) bgPos.x = fix16Add(bgPos.x, BG_SIZE_F); if(y > 3) bgPosXF[y] = fix16Sub(bgPosXF[y], BG_SPEED);
if(bgPos.y >= BG_SIZE_F) bgPos.y = fix16Sub(bgPos.y, BG_SIZE_F); if(bgPosXF[y] <= -BG_SIZE_F) bgPosXF[y] = fix16Add(bgPosXF[y], BG_SIZE_F);
bgPosX[y] = fix16ToInt(bgPosXF[y]);
}
} }
// loop // loop
void loadBg(){ void loadBg(){
VDP_setScrollingMode(HSCROLL_TILE, VSCROLL_PLANE);
drawBg(); drawBg();
drawFg();
} }
void updateBg(){ void updateBg(){
VDP_setHorizontalScroll(BG_B, fix16ToInt(bgPos.x)); VDP_setHorizontalScrollTile(BG_A, 0, bgPosX, WIN_H_T, DMA);
VDP_setVerticalScroll(BG_B, fix16ToInt(bgPos.y));
scrollBg(); scrollBg();
} }

View File

@ -1,5 +1,14 @@
// chrome // chrome
#define CHROME_I 64
// frame
static void loadFrame(){
VDP_loadTileSet(frame.tileset, CHROME_I, DMA);
VDP_fillTileMapRect(BG_A, TILE_ATTR_FULL(PAL2, 1, 0, 0, CHROME_I), 0, 0, WIN_W_T, 3);
}
// score // score
#define SCORE_X 4 #define SCORE_X 4
@ -52,6 +61,7 @@ static void loadHeat(){
// loop // loop
void loadChrome(){ void loadChrome(){
loadFrame();
loadScore(); loadScore();
loadRound(); loadRound();
loadHeat(); loadHeat();

49
src/foreground.h Normal file
View File

@ -0,0 +1,49 @@
// foreground
#define FG_I 576
// draw
#define CEIL_Y 3
#define FLOOR_Y 24
static void drawFg(){
for(u16 x = 0; x < BG_W; x++){
if(x % 4 == 0){
VDP_drawImageEx(BG_B, &rock1t, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I), x, CEIL_Y, 0, DMA);
VDP_drawImageEx(BG_B, &rock1, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 16), x, FLOOR_Y, 0, DMA);
}
}
}
// update
#define FG_SPEED FIX16(2)
#define BG_SPEED_NORM FIX16(2 * 0.707)
#define FG_SIZE 32
#define FG_SIZE_F FIX16(FG_SIZE)
Vect2D_f16 fgPos;
static void scrollFg(){
fgPos.x = fix16Sub(fgPos.x, FG_SPEED);
if(fgPos.x <= -FG_SIZE_F) fgPos.x = fix16Add(fgPos.x, FG_SIZE_F);
if(fgPos.y >= FG_SIZE_F) fgPos.y = fix16Sub(fgPos.y, FG_SIZE_F);
}
// loop
void loadFg(){
drawFg();
}
void updateFg(){
// VDP_setHorizontalScroll(BG_B, fix16ToInt(fgPos.x));
// VDP_setVerticalScroll(BG_B, fix16ToInt(fgPos.y));
scrollFg();
}

View File

@ -6,6 +6,7 @@
#include "global.h" #include "global.h"
#include "controls.h" #include "controls.h"
#include "background.h" #include "background.h"
#include "foreground.h"
#include "player.h" #include "player.h"
#include "bullets.h" #include "bullets.h"
#include "chrome.h" #include "chrome.h"
@ -17,14 +18,16 @@ static void loadInternals(){
JOY_setEventHandler(&updateControls); JOY_setEventHandler(&updateControls);
SPR_init(127, 0, 0); SPR_init(127, 0, 0);
VDP_setScreenWidth256(); VDP_setScreenWidth256();
VDP_setPalette(PAL1, font.palette -> data); VDP_setPalette(PAL1, nitori.palette -> data);
VDP_setPalette(PAL2, bgWall1.palette -> data); VDP_setPalette(PAL2, wall1.palette -> data);
VDP_setPalette(PAL3, font.palette -> data);
VDP_loadFont(font.tileset, DMA); VDP_loadFont(font.tileset, DMA);
VDP_setTextPalette(1); VDP_setTextPalette(3);
} }
static void loadGame(){ static void loadGame(){
loadBg(); loadBg();
loadFg();
loadPlayer(); loadPlayer();
loadChrome(); loadChrome();
} }
@ -33,6 +36,7 @@ static void updateGame(){
updatePlayer(); updatePlayer();
updateBullets(); updateBullets();
updateBg(); updateBg();
updateFg();
updateChrome(); updateChrome();
clock++; clock++;
if(clock >= CLOCK_LIMIT) clock -= CLOCK_LIMIT; if(clock >= CLOCK_LIMIT) clock -= CLOCK_LIMIT;

View File

@ -2,7 +2,7 @@
#define PLAYER_OFF FIX16(16) #define PLAYER_OFF FIX16(16)
#define PLAYER_INIT_X FIX16(40) #define PLAYER_INIT_X FIX16(40)
#define PLAYER_INIT_Y FIX16(GAME_H / 2) #define PLAYER_INIT_Y FIX16((GAME_H - 24) / 2 + 24)
#define INVINCIBLE_LIMIT 60 * 4 #define INVINCIBLE_LIMIT 60 * 4
#define SHOT_INTERVAL 15 #define SHOT_INTERVAL 15