obstacle/stage work

This commit is contained in:
t. boddy 2022-08-20 20:05:05 -04:00
parent 60aa78f3f1
commit 8837c2a00f
15 changed files with 75 additions and 38 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@ -7,18 +7,23 @@ IMAGE frame "chrome/frame.png" FAST
IMAGE wall1 "bg/wall1.png" FAST
IMAGE rock1 "fg/rock1.png" FAST
IMAGE rock1l "fg/rock1l.png" FAST
IMAGE rock1r "fg/rock1r.png" FAST
IMAGE rock1b "fg/rock1b.png" FAST
IMAGE rock1Bottom "fg/rock1bottom.png" FAST
IMAGE rock1Top "fg/rock1top.png" FAST
IMAGE obstacle1LeftBottom "fg/obstacle1leftbottom.png" FAST
IMAGE obstacle1RightBottom "fg/obstacle1rightbottom.png" FAST
IMAGE obstacle1MiddleBottom "fg/obstacle1middlebottom.png" FAST
IMAGE obstacle1LeftTop "fg/obstacle1lefttop.png" FAST
IMAGE obstacle1RightTop "fg/obstacle1righttop.png" FAST
IMAGE obstacle1MiddleTop "fg/obstacle1middletop.png" FAST
IMAGE rock1t "fg/rock1t.png" FAST
IMAGE rock1lt "fg/rock1lt.png" FAST
IMAGE rock1rt "fg/rock1rt.png" FAST
SPRITE nitori "player/nitori.png" 4 4 FAST
SPRITE fairy1 "enemies/fairy1.png" 6 4 FAST
SPRITE fairy1 "enemies/fairy1.png" 5 4 FAST
SPRITE smallRedBullet "bullets/smallred.png" 1 1 FAST 5
SPRITE smallBlueBullet "bullets/smallblue.png" 1 1 FAST 5

View File

@ -2,7 +2,7 @@
#define FG_I 576
#define FG_W 64
#define OBSTACLE_COUNT 8
#define OBSTACLE_COUNT 24
#define FG_SPEED FIX16(2)
#define FG_SPEED_NORM FIX16(1.414)
@ -23,15 +23,15 @@ struct obstacle obstacles[OBSTACLE_COUNT];
static void drawFg(){
for(u16 x = 0; x < FG_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);
VDP_drawImageEx(BG_B, &rock1Top, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I), x, CEIL_Y, 0, DMA);
VDP_drawImageEx(BG_B, &rock1Bottom, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 16), x, FLOOR_Y, 0, DMA);
}
}
}
// obstacle
#define OBS_CEIL_Y 7
#define OBS_CEIL_Y 3
#define OBS_FLOOR_Y 20
#define OBS_X 32
@ -40,7 +40,12 @@ static void drawFg(){
s16 fgPos, obsX;
static void spawnObstacle(bool top){
#define OBS_I FG_I + 32
SpriteDefinition* obstacleImage;
s16 obstacleI;
static void spawnObstacle(bool top, s16 offset, u8 type){
s16 i = -1;
for(s16 j = 0; j < OBSTACLE_COUNT; j++) if(!obstacles[j].active && i == -1) i = j;
if(i > -1){
@ -50,29 +55,45 @@ static void spawnObstacle(bool top){
obstacles[i].top = top;
obstacles[i].pos.x = FIX16(256);
obstacles[i].pos.y = top ? OBS_TOP_Y : OBS_BOTTOM_Y;
obstacles[i].size.x = FIX16(64);
obstacles[i].size.x = FIX16(32);
obstacles[i].size.y = FIX16(32);
obstacles[i].startX = obsX;
for(u8 j = 0; j < 4; j++){
VDP_drawImageEx(BG_B,
top ? (j == 0 ? &rock1lt : (j == 1 ? &rock1t : (j == 2 ? &rock1rt : &rock1b))) : (j == 0 ? &rock1l : (j == 1 ? &rock1 : (j == 2 ? &rock1r : &rock1b))),
TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + (top ? (j == 0 ? 32 : (j == 1 ? 48 : (j == 2 ? 64 : 80))) : (j == 0 ? 112 : (j == 1 ? 128 : (j == 2 ? 144 : 80))))),
obsX + (top ? (j == 1 || j == 3 ? 2 : (j == 2 ? 6 : 0)) : ((j == 1 || j == 3 ? 2 : (j == 2 ? 6 : 0)))),
top ? (OBS_CEIL_Y - (j == 0 || j == 2 ? 2 : (j == 3 ? 4 : 0))) : (OBS_FLOOR_Y + (j == 3 ? 4 : 0)),
0, DMA_QUEUE);
if(offset){
obstacles[i].pos.x = fix16Sub(obstacles[i].pos.x, FIX16(offset));
obsX -= offset / 8;
}
obstacles[i].startX = obsX;
switch(type){
case 0: obstacleImage = top ? &obstacle1LeftTop : &obstacle1LeftBottom; break;
case 1: obstacleImage = top ? &obstacle1MiddleTop : &obstacle1MiddleBottom; break;
case 2: obstacleImage = top ? &obstacle1RightTop : &obstacle1RightBottom; break;
}
obstacleI = type * 32;
if(top) obstacleI += 128;
VDP_drawImageEx(BG_B, obstacleImage,
TILE_ATTR_FULL(PAL2, 1, 0, 0, OBS_I + obstacleI),
obsX, top ? OBS_CEIL_Y : OBS_FLOOR_Y, 0, DMA);
// VDP_drawImageEx(BG_B,
// top ? (j == 0 ? &rock1lt : (j == 1 ? &rock1t : (j == 2 ? &rock1rt : &rock1b))) : (j == 0 ? &rock1l : (j == 1 ? &rock1 : (j == 2 ? &rock1r : &rock1b))),
// TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + (top ? (j == 0 ? 32 : (j == 1 ? 48 : (j == 2 ? 64 : 80))) : (j == 0 ? 112 : (j == 1 ? 128 : (j == 2 ? 144 : 80))))),
// obsX + (top ? (j == 1 || j == 3 ? 2 : (j == 2 ? 6 : 0)) : ((j == 1 || j == 3 ? 2 : (j == 2 ? 6 : 0)))),
// top ? (OBS_CEIL_Y - (j == 0 || j == 2 ? 2 : (j == 3 ? 4 : 0))) : (OBS_FLOOR_Y + (j == 3 ? 4 : 0)),
// 0, DMA);
}
}
#define OBSTACLE_MOD FIX16(8)
#define OBSTACLE_LIMIT_X FIX16(-64)
SpriteDefinition* obstacleImage;
static void killObstacle(s16 i){
obstacles[i].active = FALSE;
VDP_clearTileMapRect(BG_B, obstacles[i].startX, obstacles[i].top ? OBS_CEIL_Y : OBS_FLOOR_Y, 8, 4);
for(u8 x = 0; x < 2; x++)
VDP_drawImageEx(BG_B, obstacles[i].top ? &rock1t : &rock1, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + (obstacles[i].top ? 0 : 16)),
obstacles[i].startX + 4 * x, obstacles[i].top ? CEIL_Y : FLOOR_Y, 0, DMA);
VDP_clearTileMapRect(BG_B, obstacles[i].startX, obstacles[i].top ? OBS_CEIL_Y + 4 : OBS_FLOOR_Y, 8, 4);
for(u8 x = 0; x < 2; x++){
VDP_drawImageEx(BG_B, obstacles[i].top ? &rock1Top : &rock1Bottom, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + (obstacles[i].top ? 0 : 16)),
obstacles[i].startX + 4 * x, obstacles[i].top ? CEIL_Y : FLOOR_Y, 0, DMA_QUEUE);
}
}
static void collideObstacle(s16 i){
@ -118,5 +139,4 @@ void updateFg(){
VDP_setHorizontalScrollTile(BG_B, 0, fgPosX, GAME_H_T, DMA);
scrollFg();
for(s16 i = 0; i < OBSTACLE_COUNT; i++) if(obstacles[i].active) updateObstacle(i);
if(clock % 60 == 0) spawnObstacle(clock % 120 < 60);
}

View File

@ -15,6 +15,7 @@
#include "stage.h"
#include "chrome.h"
// game loop
static void loadInternals(){

View File

@ -5,25 +5,24 @@
// waves
static void waveOne(){
static void waveOne(s16 off, bool big){
struct enemySpawner spawner = {
.angle = 512,
.speed = FIX16(0.75),
.x = GAME_W + 24,
.y = SPAWN_MID,
.speed = FIX16(0.8),
.x = GAME_W + 20,
.y = SPAWN_MID + off,
.image = &fairy1,
.offX = 24,
.offX = 20,
.offY = 16
};
spawner.fixes[0] = FIX16(spawner.y);
spawner.fixes[1] = FIX16(8);
spawner.fixes[2] = FIX16(12);
spawner.fixes[3] = FIX16(0.1);
spawner.fixes[2] = FIX16(8);
spawner.fixes[3] = FIX16(0.25);
void updater(s16 i){
enemies[i].pos.y = fix16Sub(enemies[i].fixes[0], fix16Mul(sinFix16(enemies[i].fixes[1]), enemies[i].fixes[2]));
enemies[i].fixes[1] = fix16Add(enemies[i].fixes[1], enemies[i].fixes[3]);
if(enemies[i].clock == 30){
if(enemies[i].clock == 30 && enemies[i].bools[0]){
struct bulletSpawner spawner = {
.x = enemies[i].pos.x,
.y = enemies[i].pos.y,
@ -31,13 +30,19 @@ static void waveOne(){
.angle = 512,
.speed = FIX16(1.5)
};
if(enemies[i].bools[1]){
spawner.image = &bigRedBullet;
spawner.big = TRUE;
}
spawner.vel = hone(enemies[i].pos, player.pos, spawner.speed, 0);
spawnBullet(spawner, EMPTY);
}
}
for(u8 j = 0; j < 3; j++){
spawner.bools[0] = j == 2;
spawner.bools[1] = big ? TRUE : FALSE;
spawnEnemy(spawner, updater, EMPTY);
spawner.x += 50;
spawner.x += 40;
}
}
@ -48,7 +53,13 @@ s16 stageClock;
static void updateWaves(){
switch(stageClock){
case 5: waveOne(); break;
case 0:
for(s16 i = 0; i < 8; i++)
for(s16 j = 0; j < 2; j++) spawnObstacle(j == 0 ? TRUE : FALSE, 256 - 32 * i, i == 7 ? 2 : 1);
break;
// case 0: waveOne(-32, FALSE); break;
// case 180: waveOne(32, FALSE); break;
// case 360: waveOne(0, TRUE); break;
}
}