diff --git a/gba/cartest/data/car_blue.bin b/gba/cartest/data/car_blue.bin new file mode 100644 index 0000000..0bb59a9 Binary files /dev/null and b/gba/cartest/data/car_blue.bin differ diff --git a/gba/cartest/data/car_blue_orig.pcx b/gba/cartest/data/car_blue_orig.pcx new file mode 100644 index 0000000..37acc82 Binary files /dev/null and b/gba/cartest/data/car_blue_orig.pcx differ diff --git a/gba/cartest/src/cartest.c b/gba/cartest/src/cartest.c index f345176..a92ab56 100644 --- a/gba/cartest/src/cartest.c +++ b/gba/cartest/src/cartest.c @@ -14,6 +14,7 @@ // headers for binary data generated by bin2o macro in makefile #include "car_pal_bin.h" #include "car_bin.h" +#include "car_blue_bin.h" #include "smoke_bin.h" #include "sinlut.h" @@ -32,7 +33,7 @@ typedef s32 FIXED; // 32bit FIXED in 24.8 format #define NUMSMOKES 20 u16 PaletteBuffer[256]; -OBJATTR oe_buffer[1+NUMSMOKES]; +OBJATTR oe_buffer[2+NUMSMOKES+10]; OBJAFFINE *const oa_buffer = (OBJAFFINE*)oe_buffer; s8 smoke_frame[NUMSMOKES]; @@ -46,10 +47,12 @@ void VblankInterrupt() int main(void) { - OBJATTR*car = &oe_buffer[0]; - OBJAFFINE*car_aff = &oa_buffer[0]; + OBJATTR*red_car = &oe_buffer[0]; + OBJATTR*blue_car = &oe_buffer[1]; + OBJAFFINE*red_car_aff = &oa_buffer[0]; + OBJAFFINE*blue_car_aff = &oa_buffer[1]; // We'll make a few smoke clouds - OBJATTR*smokes = &oe_buffer[1]; + OBJATTR*smokes = &oe_buffer[2]; // Set up the interrupt handlers InitInterrupt(); @@ -72,6 +75,8 @@ int main(void) void* free_space = BITMAP_OBJ_BASE_ADR; CpuFastSet(car_bin, free_space, COPY32 | car_bin_size/4); free_space += car_bin_size; + CpuFastSet(car_blue_bin, free_space, COPY32 | car_bin_size/4); + free_space += car_blue_bin_size; CpuFastSet(car_pal_bin, OBJ_COLORS, COPY32 | car_pal_bin_size/4); @@ -79,7 +84,8 @@ int main(void) CpuFastSet(smoke_bin, free_space, COPY32 | smoke_bin_size/4); free_space += smoke_bin_size; - car->attr2 = OBJ_CHAR(512); + red_car->attr2 = OBJ_CHAR(512); + blue_car->attr2 = OBJ_CHAR(520); u8 next_smoke = 0; @@ -91,74 +97,137 @@ int main(void) smoke_frame[i] = 6; } - FIXED x = INT2FIX(112); - FIXED y = INT2FIX(72); - int speed = 0; - int angle = 0; + FIXED red_x = INT2FIX(102); + FIXED red_y = INT2FIX(72); + FIXED blue_x = INT2FIX(122); + FIXED blue_y = INT2FIX(72); + int red_speed = 0; + int red_angle = 0; + int blue_speed = 0; + int blue_angle = 0; while (1) { if (KeysHeld() & KEY_RIGHT) { - angle -= 8; + red_angle -= 8; } else if (KeysHeld() & KEY_LEFT) { - angle += 8; + red_angle += 8; } - if (angle < 0) { - angle += 512; - } else if (angle >= 512) { - angle -= 512; + if (red_angle < 0) { + red_angle += 512; + } else if (red_angle >= 512) { + red_angle -= 512; } if (KeysHeld() & KEY_A) { - if ((speed<30) && (speed>=0)) { + blue_angle -= 8; + } else if (KeysHeld() & KEY_B) { + blue_angle += 8; + } + if (blue_angle < 0) { + blue_angle += 512; + } else if (blue_angle >= 512) { + blue_angle -= 512; + } + + if (KeysHeld() & KEY_L) { + if ((red_speed<30) && (red_speed>=0)) { // slow speedup - speed += 1; - } else if (speed<0) { + red_speed += 1; + } else if (red_speed<0) { // break if we're going backward - speed += 2; + red_speed += 2; } } - if (KeysHeld() & KEY_B) { - if ((speed>=-5) && (speed<=0)) { + + if (KeysHeld() & KEY_R) { + if ((blue_speed<30) && (blue_speed>=0)) { // slow speedup - speed -= 1; - } else if (speed>0) { - // break if we're going forward - speed -= 2; + blue_speed += 1; + } else if (blue_speed<0) { + // break if we're going backward + blue_speed += 2; } - } + } + + + /* Disabled */ +/* if (KeysHeld() & KEY_B) { */ +/* if ((red_speed>=-5) && (red_speed<=0)) { */ +/* // slow speedup */ +/* red_speed -= 1; */ +/* } else if (red_speed>0) { */ +/* // break if we're going forward */ +/* red_speed -= 2; */ +/* } */ +/* } */ + // slow down if we're not doing anything - if (!(KeysHeld() & KEY_A) && !(KeysHeld() & KEY_B)) { - if (speed>0) { - speed -= 1; - } else if (speed<0) { - speed += 1; + if (!(KeysHeld() & KEY_L)) { + if (red_speed>0) { + red_speed -= 1; + } else if (red_speed<0) { + red_speed += 1; } } - int fspeed = speed >> 3; + if (!(KeysHeld() & KEY_R)) { + if (blue_speed>0) { + blue_speed -= 1; + } else if (blue_speed<0) { + blue_speed += 1; + } + } + + int fred_speed = red_speed >> 3; - x -= fspeed*lut_sin(angle); - y -= fspeed*lut_cos(angle); + red_x -= fred_speed*lut_sin(red_angle); + red_y -= fred_speed*lut_cos(red_angle); - if (x>=INT2FIX(232)) { - x -= INT2FIX(256); - } else if (x=INT2FIX(232)) { + red_x -= INT2FIX(256); + } else if (red_x=INT2FIX(152)) { - y -= INT2FIX(176); - } else if (y=INT2FIX(152)) { + red_y -= INT2FIX(176); + } else if (red_ypa = lut_cos(angle); - car_aff->pb = -lut_sin(angle); - car_aff->pc = lut_sin(angle); - car_aff->pd = lut_cos(angle); + red_car_aff->pa = lut_cos(red_angle); + red_car_aff->pb = -lut_sin(red_angle); + red_car_aff->pc = lut_sin(red_angle); + red_car_aff->pd = lut_cos(red_angle); - car->attr1 = OBJ_SIZE(1) | OBJ_X(FIX2INT(x)); - car->attr0 = OBJ_256_COLOR | OBJ_DOUBLE | OBJ_ROT_SCALE_ON | OBJ_Y(FIX2INT(y)); + red_car->attr1 = OBJ_SIZE(1) | OBJ_X(FIX2INT(red_x)); + red_car->attr0 = OBJ_256_COLOR | OBJ_DOUBLE | OBJ_ROT_SCALE_ON | OBJ_Y(FIX2INT(red_y)); + + + int fblue_speed = blue_speed >> 3; + + blue_x -= fblue_speed*lut_sin(blue_angle); + blue_y -= fblue_speed*lut_cos(blue_angle); + + if (blue_x>=INT2FIX(232)) { + blue_x -= INT2FIX(256); + } else if (blue_x=INT2FIX(152)) { + blue_y -= INT2FIX(176); + } else if (blue_ypa = lut_cos(blue_angle); + blue_car_aff->pb = -lut_sin(blue_angle); + blue_car_aff->pc = lut_sin(blue_angle); + blue_car_aff->pd = lut_cos(blue_angle); + + blue_car->attr1 = OBJ_SIZE(1) | OBJ_ROT_SCALE(1) | OBJ_X(FIX2INT(blue_x)); + blue_car->attr0 = OBJ_256_COLOR | OBJ_DOUBLE | OBJ_ROT_SCALE_ON | OBJ_Y(FIX2INT(blue_y)); // Update smoke cloud frames if ((frame & 3) == 3) { @@ -171,12 +240,12 @@ int main(void) // place a new smoke cloud after car if driving // forwards - if ((speed!=0) && ((frame & 1) == 1)) { + if ((red_speed!=0) && ((frame & 1) == 1)) { for (i=0; i