tangstad/helds
tangstad
/
helds
Archived
1
0
Fork 0

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.
This commit is contained in:
Truls Alexander Tangstad 2005-11-14 01:18:38 +00:00
parent abd3ed414f
commit d7bb1f2ecc
1 changed files with 38 additions and 37 deletions

View File

@ -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<wait_ticks; i++) VBlankIntrWait();
}
void move_turret(u16 frame_delay) {
// assume we are in vblank
s8 pos;
u16 i;
for (pos=0; pos<5; 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; i<frame_delay; i++) VBlankIntrWait();
}
for (pos=4; pos>=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; i<frame_delay; i++) VBlankIntrWait();
}
void update_sprite(AnimSprite* sprite, u16 char_base, u16 oam_index) {
sprite->oam.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);
}
}