From d788b3931d751fe03a08848a5d18c6deddf914b1 Mon Sep 17 00:00:00 2001 From: Trevor Boddy Date: Tue, 16 Aug 2022 20:30:17 -0400 Subject: [PATCH] obstacle lifecycle --- res/fg/rock1lt.png | Bin 0 -> 5016 bytes res/fg/rock1rt.png | Bin 0 -> 5033 bytes res/resources.res | 2 ++ src/foreground.h | 66 ++++++++++++++++++++++++++++++++++++--------- 4 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 res/fg/rock1lt.png create mode 100644 res/fg/rock1rt.png diff --git a/res/fg/rock1lt.png b/res/fg/rock1lt.png new file mode 100644 index 0000000000000000000000000000000000000000..79c5297b4b92e5087104d0b17d5efae750140907 GIT binary patch literal 5016 zcmb_g2|QG5|39dR%2Jjnra@^LvzQq(!;rxs>qVDJWtM}%EX|Dl5*1n6Em4Y!kjfS* zbX$;YrEJMwNs=rf+1{hYdq3}c@BQD;`}xo3bLKqfdA`5zZ-1US6J=*(wo+1A5&(de z7Um}Q&|L<)P!eL$H!@5TglXW)zr(sWBc+#N!bd zZ8QLwM_q7mcXW8KK%VUUOtFj%jkDz1%S*uQDKVjrtjls|fJ;Y|LUB})I0G!q(5j}*N zgLaD5ZzKVY6~NV)@|P4KO$Na5(Mu1w2~?IG??;CI-lL1+=P9M+!u8&jYS!F4e{XuAhL=3!4>~ zVlqmA>tz`!2N8)0;QlEy(_uhDM?~vbT#o;9CzlQN4gfHm&y0C{CeCpwXTz=X^)7qw z_@@$djj!9a9$9|mz33f@cOY23sw&%kSgHV%AII0< zvr#7czH z3vg`;SvEo0V^>nWZ1Ai$EVn;Yb5Im`dU2?pf0$Zrgk9tzf-^ud54SpHti3IK zr`;0GT-hRu{9wfH%%fC-D1s+i|8QxsXiK+(e&{}>(03?FuIoA@8O%cy=SVy~G!fn$ zss7N^Z9|ATN-nH?LzKBB+%&Gro{6(R6sNwkYG0b_lq&H=vZ?k4auqpEdM!1?*dSG@ zdi%>vRnLgFOD>HnD=Al=O?gP(m8dh5YFO!^x%;px<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spNM! zjKw6wop9DDYo0Oa!7>lzgARc>EVrMTQ$KD1=cnzbqs`^JBhf@65sAVeF&G4d zKnMajLYhB*=qKv?u577CNK^&k({bYe* zbhJ@0Eo&Ns#aZCpyrAcY2xvkRf@C<9Hw*$rK%nuCXu?9?a5w}COG2T(L#?4wVA6!N z{{mxBB$N&b2g&{c%w@9N0{%}ZlR1iTIcL%``GutXe)AQEXP1V)!hW8y$O0|SCTv);C*aWt5QW7fXiOaj0;_|@>d?_RI?8R4&6dxCT8ifVN7ejn;codyLgn0g~*O=?g8(B?s`pkC8VE_O0efG{!<(kl~DldH|X5AJeQq z3FtpF{X4Cn2MCe=O_h9y3Ak=TKN=r2a)*Nd59$#4SLO?7zJG5#lSV{i2|CaggvSsN zSP-Nk=okhQp^L#`@k9&}Ph>*1`&Y&jNhmZ4hyGc$|C{kY*cl!)jyni#v`F~>?#@3e z?!R#7Kb!FX(;ei(2K&9vkpEeN|E}tvonZv^>_UMGe&m%xb6?D`!OxbVxuNiQEKwJM zr@KKdqYI@DYGw?AMr6{_L^PejAcFee^m?-(>2IU&M99C__zn4o!{MhebmA-w7tcEA zVezyCIZ)>K&{>FTph9P@h?0egk)zh>oed2qvQaW(&ve#uHpjQl&p&NK+-Ss3Z>LDv zmXEaNZ3+q5aEUS#L=2YgYDxUMp}<(vhQ%QP{k(PO$x{>O5vrtN_;Ro|2M6zA;|jYU#{gI+k~PWK29l-{qCF*7(AI PZ-9lVjmb@l>!E)E27W(a literal 0 HcmV?d00001 diff --git a/res/fg/rock1rt.png b/res/fg/rock1rt.png new file mode 100644 index 0000000000000000000000000000000000000000..3ade725c73d012e523f48a24badb904738a54aaf GIT binary patch literal 5033 zcmb_g2|QHm-#+LW0^l|6fE5Su4A7`f_d86r`Pb8a|s0169qnsGbkrWr@Our&?2Dp4!L1yPjOxA;#EAWGI z8)btYG)bSzhsPc<$)6Sq6VrIvr-66wk?c_nFB~k_V@>6jPZ4}BeoP5B1}wbt%q|?c zE=1cUHy#717~+x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WF{4~HZy`l zt|IAl8j*&l>EQKg1cWzU7l*)MK^%gtPs1bdI0}f<*QH?e(D)zg%~(|4QVo~Zf73IK zMTIz)Ge^{;QScZvS_eTOlf4lX3J!$W$QXnkS_g~6kwJnk75js2H=7Q%6gl9JtV>?e zAVytXj2;=((L)fZ7+nNT2h>FnCCxCF+zwDZ_0$6N27Hui#e;l`l z-d5QxZ+ZYU@gHxkOTzyuK%y0$164Wfdn-ACLEo6E)Gw?67U2Xq}{)Ao=LbTAP_TYnGJKa(rl{dSfv(R^j%SJxl)+NVhllh8|AfeRkzn~W06HZ&6e+L=uIu`VORJo z+{Y36_*_DyCU4If=$)ogVVK(Q)0JMI7=#QiIweSw+bp+kyU0RHW{a#If;G+)7}SIs z7$@jNCRh*MZtX;u&*4Un literal 0 HcmV?d00001 diff --git a/res/resources.res b/res/resources.res index da127e1..dd5dd7b 100644 --- a/res/resources.res +++ b/res/resources.res @@ -9,6 +9,8 @@ IMAGE rock1r "fg/rock1r.png" FAST IMAGE rock1b "fg/rock1b.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 diff --git a/src/foreground.h b/src/foreground.h index b6bc5bc..9a2f24b 100644 --- a/src/foreground.h +++ b/src/foreground.h @@ -4,9 +4,13 @@ #define FG_W GAME_W_T + 30 #define OBSTACLE_COUNT 8 +#define FG_SPEED FIX16(2) +#define FG_SPEED_NORM FIX16(1.414) + struct obstacle { - bool active; + bool active, top; Vect2D_f16 pos; + s16 startX; }; struct obstacle obstacles[OBSTACLE_COUNT]; @@ -27,24 +31,58 @@ static void drawFg(){ // obstacle +#define OBS_CEIL_Y CEIL_Y + 4 #define OBS_FLOOR_Y FLOOR_Y - 4 -s16 fgPos; -s16 obsX; +#define OBS_X 32 -static void spawnObstacle(){ - obsX = 32; - VDP_drawImageEx(BG_B, &rock1l, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 32), obsX, OBS_FLOOR_Y, 0, DMA); - VDP_drawImageEx(BG_B, &rock1, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 48), obsX + 2, OBS_FLOOR_Y, 0, DMA); - VDP_drawImageEx(BG_B, &rock1r, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 64), obsX + 2 + 4, OBS_FLOOR_Y, 0, DMA); - VDP_drawImageEx(BG_B, &rock1b, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 80), obsX + 2, OBS_FLOOR_Y + 4, 0, DMA); +s16 fgPos; + +static void spawnObstacle(bool top){ + s16 i = -1; + for(s16 j = 0; j < OBSTACLE_COUNT; j++) if(!obstacles[j].active && i == -1) i = j; + if(i > -1){ + obstacles[i].active = TRUE; + obstacles[i].top = top; + obstacles[i].pos.x = FIX16(256); + obstacles[i].startX = OBS_X; + if(top){ + VDP_drawImageEx(BG_B, &rock1lt, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 32), OBS_X, OBS_CEIL_Y - 2, 0, DMA); + VDP_drawImageEx(BG_B, &rock1t, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 48), OBS_X + 2, OBS_CEIL_Y, 0, DMA); + VDP_drawImageEx(BG_B, &rock1rt, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 64), OBS_X + 2 + 4, OBS_CEIL_Y - 2, 0, DMA); + VDP_drawImageEx(BG_B, &rock1b, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 80), OBS_X + 2, OBS_CEIL_Y - 4, 0, DMA); + } else { + VDP_drawImageEx(BG_B, &rock1l, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 32 + 80), OBS_X, OBS_FLOOR_Y, 0, DMA); + VDP_drawImageEx(BG_B, &rock1, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 48 + 80), OBS_X + 2, OBS_FLOOR_Y, 0, DMA); + VDP_drawImageEx(BG_B, &rock1r, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 64 + 80), OBS_X + 2 + 4, OBS_FLOOR_Y, 0, DMA); + VDP_drawImageEx(BG_B, &rock1b, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 80), OBS_X + 2, OBS_FLOOR_Y + 4, 0, DMA); + } + } +} + +#define OBSTACLE_MOD FIX16(8) +#define OBSTACLE_LIMIT_X FIX16(-64) + +static void killObstacle(s16 i){ + obstacles[i].active = FALSE; + if(obstacles[i].top){ + VDP_clearTileMapRect(BG_B, obstacles[i].startX, OBS_CEIL_Y, 8, 8); + for(u8 i = 0; i < 2; i++) VDP_drawImageEx(BG_B, &rock1t, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I),obstacles[i].startX + 4 * i, CEIL_Y, 0, DMA); + } else { + VDP_clearTileMapRect(BG_B, obstacles[i].startX, OBS_FLOOR_Y, 8, 8); + for(u8 i = 0; i < 2; i++) VDP_drawImageEx(BG_B, &rock1, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 16), obstacles[i].startX + 4 * i, FLOOR_Y, 0, DMA); + } +} + +static void updateObstacle(s16 i){ + obstacles[i].pos.x = fix16Sub(obstacles[i].pos.x, FG_SPEED); + if(obstacles[i].pos.x <= OBSTACLE_LIMIT_X){ + killObstacle(i); + } } // update -#define FG_SPEED FIX16(2) -#define FG_SPEED_NORM FIX16(1.414) - #define FG_SIZE 32 #define FG_LIMIT FIX16(-320) @@ -70,10 +108,12 @@ static void scrollFg(){ void loadFg(){ drawFg(); - spawnObstacle(); + spawnObstacle(FALSE); + spawnObstacle(TRUE); } 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); } \ No newline at end of file