tangstad/helds
tangstad
/
helds
Archived
1
0
Fork 0

Hacked in a twoplayer-mode with a blue car.

This commit is contained in:
Truls Alexander Tangstad 2005-12-04 18:14:19 +00:00
parent e93a967cb0
commit d4b5d8cf44
3 changed files with 121 additions and 52 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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;
x -= fspeed*lut_sin(angle);
y -= fspeed*lut_cos(angle);
if (x>=INT2FIX(232)) {
x -= INT2FIX(256);
} else if (x<INT2FIX(-24)) {
x += INT2FIX(256);
if (!(KeysHeld() & KEY_R)) {
if (blue_speed>0) {
blue_speed -= 1;
} else if (blue_speed<0) {
blue_speed += 1;
}
}
if (y>=INT2FIX(152)) {
y -= INT2FIX(176);
} else if (y<INT2FIX(-24)) {
y += INT2FIX(176);
int fred_speed = red_speed >> 3;
red_x -= fred_speed*lut_sin(red_angle);
red_y -= fred_speed*lut_cos(red_angle);
if (red_x>=INT2FIX(232)) {
red_x -= INT2FIX(256);
} else if (red_x<INT2FIX(-24)) {
red_x += INT2FIX(256);
}
car_aff->pa = lut_cos(angle);
car_aff->pb = -lut_sin(angle);
car_aff->pc = lut_sin(angle);
car_aff->pd = lut_cos(angle);
if (red_y>=INT2FIX(152)) {
red_y -= INT2FIX(176);
} else if (red_y<INT2FIX(-24)) {
red_y += INT2FIX(176);
}
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_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);
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(-24)) {
blue_x += INT2FIX(256);
}
if (blue_y>=INT2FIX(152)) {
blue_y -= INT2FIX(176);
} else if (blue_y<INT2FIX(-24)) {
blue_y += INT2FIX(176);
}
blue_car_aff->pa = 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<NUMSMOKES; i++) {
if (smoke_frame[i] == 6) {
smoke_frame[i] = 0;
smokes[i].attr1 = OBJ_X(FIX2INT(x)+12);
smokes[i].attr0 = OBJ_256_COLOR | OBJ_Y(FIX2INT(y)+12);
smokes[i].attr1 = OBJ_X(FIX2INT(red_x)+12);
smokes[i].attr0 = OBJ_256_COLOR | OBJ_Y(FIX2INT(red_y)+12);
break;
}
}
@ -187,7 +256,7 @@ int main(void)
}
for (i=0; i<NUMSMOKES; i++)
smokes[i].attr2 = OBJ_CHAR(520 + 2*smoke_frame[i]);
smokes[i].attr2 = OBJ_CHAR(528 + 2*smoke_frame[i]);
VBlankIntrWait();
CpuFastSet(oe_buffer, OAM, COPY32 | sizeof(oe_buffer)/4);