From d7bb1f2eccfb9feca6533cb59196ec66a51d5278 Mon Sep 17 00:00:00 2001 From: tangstad Date: Mon, 14 Nov 2005 01:18:38 +0000 Subject: [PATCH] Tried using a more generic way of controlling animation in a sprite. No longer shows animated tetris-piece sprite though, but working on a nice way of adding motion paths to sprites. --- gba/logosplash/src/logosplash.c | 75 +++++++++++++++++---------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/gba/logosplash/src/logosplash.c b/gba/logosplash/src/logosplash.c index 3daf250..351a1a2 100644 --- a/gba/logosplash/src/logosplash.c +++ b/gba/logosplash/src/logosplash.c @@ -26,10 +26,20 @@ // storage space for palette data //--------------------------------------------------------------------------------- u16 PaletteBuffer[256]; -OBJATTR s_sprite, frog_sprite, turret_sprite; +OBJATTR s_sprite, frog_sprite; unsigned int frame; +typedef struct +{ + OBJATTR oam; + u8 frames; + u8 direction; + s8 frame; +} AnimSprite; + +AnimSprite turret; + //--------------------------------------------------------------------------------- void VblankInterrupt() //--------------------------------------------------------------------------------- @@ -47,25 +57,11 @@ void move_show_and_wait(u16 x, u16 y, u16 wait_ticks) { for (i=0; i=0; pos--) { - turret_sprite.attr2 = OBJ_CHAR(522 + pos*8); - CpuFastSet(&turret_sprite, OAM + sizeof(s_sprite) + sizeof(frog_sprite), - COPY32 | sizeof(turret_sprite)/4); - for (i=0; ioam.attr2 = OBJ_CHAR(char_base + sprite->frame*8); + VBlankIntrWait(); + CpuFastSet(&sprite->oam, OAM + oam_index*sizeof(OBJATTR), + COPY32 | sizeof(OBJATTR)/4); } //--------------------------------------------------------------------------------- @@ -101,36 +97,41 @@ int main(void) memset(&s_sprite, 0, sizeof(s_sprite)); memset(&frog_sprite, 0, sizeof(frog_sprite)); - memset(&turret_sprite, 0, sizeof(turret_sprite)); + memset(&turret, 0, sizeof(turret)); s_sprite.attr2 = OBJ_CHAR(512); frog_sprite.attr2 = OBJ_CHAR(514); frog_sprite.attr1 = OBJ_SIZE(1) | OBJ_X(175); frog_sprite.attr0 = OBJ_256_COLOR | OBJ_Y(49); - turret_sprite.attr2 = OBJ_CHAR(516); - turret_sprite.attr1 = OBJ_SIZE(1) | OBJ_X(43); - turret_sprite.attr0 = OBJ_256_COLOR | OBJ_Y(73); + // each frame is 16x16=256 bytes + turret.frames = 5; + turret.oam.attr2 = OBJ_CHAR(516); + turret.oam.attr1 = OBJ_SIZE(1) | OBJ_X(43); + turret.oam.attr0 = OBJ_256_COLOR | OBJ_Y(73); VBlankIntrWait(); CpuFastSet(&frog_sprite, OAM + sizeof(s_sprite), COPY32 | sizeof(frog_sprite)/4); + u16 i; + while (1) { - move_turret(3); - move_turret(3); - move_turret(3); - move_turret(3); + for (i=0; i<3; i++) VBlankIntrWait(); - move_show_and_wait(147, 74, 30); - move_show_and_wait(147, 76, 30); - move_show_and_wait(147, 78, 15); - move_show_and_wait(145, 78, 15); - move_show_and_wait(145, 80, 30); - move_show_and_wait(145, 82, 30); - move_show_and_wait(145, 84, 30); - move_show_and_wait(145, 86, 30); - move_show_and_wait(145, 88, 30); + if (turret.direction) + turret.frame += 1; + else + turret.frame -= 1; + + if (turret.frame >= turret.frames) { + turret.frame = turret.frames - 1; + turret.direction = 0; + } else if (turret.frame < 0) { + turret.frame = 0; + turret.direction = 1; + } + update_sprite(&turret, 522, 2); } }