tangstad/helds
tangstad
/
helds
Archived
1
0
Fork 0

Added movement and sprite rotation.. you can now actually drive the car along.

This commit is contained in:
Truls Alexander Tangstad 2005-11-22 23:25:24 +00:00
parent a179e39eaa
commit eebf8f326e
1 changed files with 82 additions and 16 deletions

View File

@ -23,7 +23,10 @@
// storage space for palette data // storage space for palette data
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
u16 PaletteBuffer[256]; u16 PaletteBuffer[256];
OBJATTR car;
// 4 sprites and one
OBJATTR oe_buffer[4];
OBJAFFINE *const oa_buffer = (OBJAFFINE*)oe_buffer;
unsigned int frame; unsigned int frame;
@ -41,6 +44,9 @@ void VblankInterrupt()
int main(void) int main(void)
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
{ {
OBJATTR*car = &oe_buffer[0];
OBJAFFINE*car_aff = &oa_buffer[0];
// Set up the interrupt handlers // Set up the interrupt handlers
InitInterrupt(); InitInterrupt();
@ -55,36 +61,96 @@ int main(void)
// screen mode, background and objects to display // screen mode, background and objects to display
SetMode( MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP ); SetMode( MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP );
u32 white = 0x10101010; CpuFastSet(&white, (void*)VRAM, FILL | 240*160/4); u32 white = 0x10101010;
CpuFastSet(&white, (void*)VRAM, FILL | 240*160/4);
FadeToPalette((void*)car_pal_bin, 1); FadeToPalette((void*)car_pal_bin, 1);
CpuFastSet(car_bin, BITMAP_OBJ_BASE_ADR, COPY32 | car_bin_size/4); CpuFastSet(car_bin, BITMAP_OBJ_BASE_ADR, COPY32 | car_bin_size/4);
CpuFastSet(car_pal_bin, OBJ_COLORS, COPY32 | car_pal_bin_size/4); CpuFastSet(car_pal_bin, OBJ_COLORS, COPY32 | car_pal_bin_size/4);
memset(&car, 0, sizeof(car)); // u32 nothing = 0;
car.attr2 = OBJ_CHAR(512); // CpuFastSet(&nothing, (void*)oe_buffer, FILL | sizeof(oe_buffer)/4);
car.attr1 = OBJ_SIZE(1) | OBJ_X(100); // memset(oe_buffer, 0, sizeof(oe_buffer));
car.attr0 = OBJ_256_COLOR | OBJ_Y(49); car->attr2 = OBJ_CHAR(512);
// car->attr1 = OBJ_SIZE(1) | OBJ_X(100);
// car->attr0 = OBJ_256_COLOR | OBJ_ROT_SCALE_ON | OBJ_Y(49);
s32 base = (s32)(0.707106781 * 256);
s32 one = 1 << 8;
car_aff->pa = 1 << 8;
car_aff->pb = 0;
car_aff->pc = 0;;
car_aff->pd = 1 << 8;
int x = 112;
int y = 72;
while (1) { while (1) {
int xadjust = 0;
int yadjust = 0;
// This isn't very tidy, but a cleanup is always
// imminent...
if ((KeysHeld() & KEY_RIGHT) && (KeysHeld() & KEY_UP)) {
car_aff->pa = base;
car_aff->pb = base;
car_aff->pc = -base;
car_aff->pd = base;
} else if ((KeysHeld() & KEY_RIGHT) && (KeysHeld() & KEY_DOWN)) {
car_aff->pa = -base;
car_aff->pb = base;
car_aff->pc = -base;
car_aff->pd = -base;
} else if ((KeysHeld() & KEY_LEFT) && (KeysHeld() & KEY_DOWN)) {
car_aff->pa = -base;
car_aff->pb = -base;
car_aff->pc = base;
car_aff->pd = -base;
} else if ((KeysHeld() & KEY_LEFT) && (KeysHeld() & KEY_UP)) {
car_aff->pa = base;
car_aff->pb = -base;
car_aff->pc = base;
car_aff->pd = base;
} else if (KeysHeld() & KEY_UP) {
car_aff->pa = 1 << 8;
car_aff->pb = 0;
car_aff->pc = 0;;
car_aff->pd = 1 << 8;
} else if (KeysHeld() & KEY_RIGHT) {
car_aff->pa = 0;
car_aff->pb = one;
car_aff->pc = -one;
car_aff->pd = 0;
} else if (KeysHeld() & KEY_DOWN) {
car_aff->pa = -one;
car_aff->pb = 0;
car_aff->pc = 0;
car_aff->pd = -one;
} else if (KeysHeld() & KEY_LEFT) {
car_aff->pa = 0;
car_aff->pb = -one;
car_aff->pc = one;
car_aff->pd = 0;
}
if (KeysHeld() & KEY_RIGHT) if (KeysHeld() & KEY_RIGHT)
car.attr1 = OBJ_SIZE(1) | OBJ_X(172); x += 1;
else if (KeysHeld() & KEY_LEFT) else if (KeysHeld() & KEY_LEFT)
car.attr1 = OBJ_SIZE(1) | OBJ_X(52); x -= 1;
else
car.attr1 = OBJ_SIZE(1) | OBJ_X(112);
if (KeysHeld() & KEY_UP) if (KeysHeld() & KEY_UP)
car.attr0 = OBJ_256_COLOR | OBJ_Y(32); y -= 1;
else if (KeysHeld() & KEY_DOWN) else if (KeysHeld() & KEY_DOWN)
car.attr0 = OBJ_256_COLOR | OBJ_Y(112); y += 1;
else
car.attr0 = OBJ_256_COLOR | OBJ_Y(72); car->attr1 = OBJ_SIZE(1) | OBJ_X(x+xadjust);
car->attr0 = OBJ_256_COLOR | OBJ_DOUBLE | OBJ_ROT_SCALE_ON | OBJ_Y(y+yadjust);
VBlankIntrWait(); VBlankIntrWait();
CpuFastSet(&car, OAM, COPY32 | sizeof(car)/4); CpuFastSet(oa_buffer, OAM, COPY32 | sizeof(OBJAFFINE)/4);
} }
} }