tangstad/helds
tangstad
/
helds
Archived
1
0
Fork 0

Use struct for bundling car settings.

This commit is contained in:
Truls Alexander Tangstad 2005-12-04 18:38:35 +00:00
parent d4b5d8cf44
commit 7a870c4ade
1 changed files with 94 additions and 90 deletions

View File

@ -30,7 +30,7 @@ typedef s32 FIXED; // 32bit FIXED in 24.8 format
#define lut_cos(x) _sinLUT[(x + (SIN_SIZE>>2)) & SIN_MASK]
#define NUMSMOKES 20
#define NUMSMOKES 30
u16 PaletteBuffer[256];
OBJATTR oe_buffer[2+NUMSMOKES+10];
@ -45,6 +45,12 @@ void VblankInterrupt()
ScanKeys();
}
typedef struct {
FIXED x, y;
int speed, angle;
} Car;
int main(void)
{
OBJATTR*red_car = &oe_buffer[0];
@ -97,137 +103,134 @@ int main(void)
smoke_frame[i] = 6;
}
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;
Car red, blue;
red.x = INT2FIX(102);
red.y = INT2FIX(72);
blue.x = INT2FIX(122);
blue.y = INT2FIX(72);
red.speed = 0;
red.angle = 0;
blue.speed = 0;
blue.angle = 0;
while (1) {
if (KeysHeld() & KEY_RIGHT) {
red_angle -= 8;
red.angle -= 8;
} else if (KeysHeld() & KEY_LEFT) {
red_angle += 8;
red.angle += 8;
}
if (red_angle < 0) {
red_angle += 512;
} else if (red_angle >= 512) {
red_angle -= 512;
if (red.angle < 0) {
red.angle += 512;
} else if (red.angle >= 512) {
red.angle -= 512;
}
if (KeysHeld() & KEY_A) {
blue_angle -= 8;
blue.angle -= 8;
} else if (KeysHeld() & KEY_B) {
blue_angle += 8;
blue.angle += 8;
}
if (blue_angle < 0) {
blue_angle += 512;
} else if (blue_angle >= 512) {
blue_angle -= 512;
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)) {
if ((red.speed<30) && (red.speed>=0)) {
// slow speedup
red_speed += 1;
} else if (red_speed<0) {
red.speed += 1;
} else if (red.speed<0) {
// break if we're going backward
red_speed += 2;
red.speed += 2;
}
}
if (KeysHeld() & KEY_R) {
if ((blue_speed<30) && (blue_speed>=0)) {
if ((blue.speed<30) && (blue.speed>=0)) {
// slow speedup
blue_speed += 1;
} else if (blue_speed<0) {
blue.speed += 1;
} else if (blue.speed<0) {
// break if we're going backward
blue_speed += 2;
blue.speed += 2;
}
}
/* Disabled */
/* if (KeysHeld() & KEY_B) { */
/* if ((red_speed>=-5) && (red_speed<=0)) { */
/* if ((red.speed>=-5) && (red.speed<=0)) { */
/* // slow speedup */
/* red_speed -= 1; */
/* } else if (red_speed>0) { */
/* red.speed -= 1; */
/* } else if (red.speed>0) { */
/* // break if we're going forward */
/* red_speed -= 2; */
/* red.speed -= 2; */
/* } */
/* } */
// slow down if we're not doing anything
if (!(KeysHeld() & KEY_L)) {
if (red_speed>0) {
red_speed -= 1;
} else if (red_speed<0) {
red_speed += 1;
if (red.speed>0) {
red.speed -= 1;
} else if (red.speed<0) {
red.speed += 1;
}
}
if (!(KeysHeld() & KEY_R)) {
if (blue_speed>0) {
blue_speed -= 1;
} else if (blue_speed<0) {
blue_speed += 1;
if (blue.speed>0) {
blue.speed -= 1;
} else if (blue.speed<0) {
blue.speed += 1;
}
}
int fred_speed = red_speed >> 3;
red.x -= (red.speed >> 3)*lut_sin(red.angle);
red.y -= (red.speed >> 3)*lut_cos(red.angle);
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);
if (red.x>=INT2FIX(232)) {
red.x -= INT2FIX(256);
} else if (red.x<INT2FIX(-24)) {
red.x += INT2FIX(256);
}
if (red_y>=INT2FIX(152)) {
red_y -= INT2FIX(176);
} else if (red_y<INT2FIX(-24)) {
red_y += INT2FIX(176);
if (red.y>=INT2FIX(152)) {
red.y -= INT2FIX(176);
} else if (red.y<INT2FIX(-24)) {
red.y += INT2FIX(176);
}
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_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));
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));
blue.x -= (blue.speed >> 3)*lut_sin(blue.angle);
blue.y -= (blue.speed >> 3)*lut_cos(blue.angle);
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.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);
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_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));
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) {
@ -240,21 +243,22 @@ int main(void)
// place a new smoke cloud after car if driving
// forwards
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(red_x)+12);
smokes[i].attr0 = OBJ_256_COLOR | OBJ_Y(FIX2INT(red_y)+12);
break;
}
}
if ((red.speed!=0) && ((frame & 1) == 1)) {
smoke_frame[next_smoke] = 0;
smokes[next_smoke].attr1 = OBJ_X(FIX2INT(red.x)+12);
smokes[next_smoke].attr0 = OBJ_256_COLOR | OBJ_Y(FIX2INT(red.y)+12);
}
next_smoke += 1;
if (next_smoke>=NUMSMOKES) {
next_smoke = 1;
if ((blue.speed!=0) && ((frame & 1) == 1)) {
smoke_frame[next_smoke] = 0;
smokes[next_smoke].attr1 = OBJ_X(FIX2INT(blue.x)+12);
smokes[next_smoke].attr0 = OBJ_256_COLOR | OBJ_Y(FIX2INT(blue.y)+12);
}
next_smoke += 1;
if (next_smoke>=NUMSMOKES) {
next_smoke = 0;
}
for (i=0; i<NUMSMOKES; i++)
smokes[i].attr2 = OBJ_CHAR(528 + 2*smoke_frame[i]);