tangstad/helds
tangstad
/
helds
Archived
1
0
Fork 0

Added spriteloader.

This commit is contained in:
Truls Alexander Tangstad 2005-12-05 22:18:43 +00:00
parent 5d7fc8384f
commit b06fef8700
1 changed files with 33 additions and 21 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 30
#define NUMSMOKES 20
unsigned int frame;
@ -45,9 +45,10 @@ class Smoke {
int num_entries;
s8* smoke_frame;
u8 next_smoke;
u16 sprite_start;
public:
Smoke(int num_entries, OBJATTR* start) {
Smoke(int num_entries, OBJATTR* start, u16 sprite_index) {
oam = start;
smoke_frame = new s8[num_entries];
next_smoke = 0;
@ -58,6 +59,7 @@ public:
// 6 == off
smoke_frame[i] = 6;
}
sprite_start = sprite_index;
}
void increase_frame_counts() {
for (u8 i=0; i<num_entries; i++) {
@ -79,7 +81,7 @@ public:
void update_sprites() {
for (u8 i=0; i<num_entries; i++)
oam[i].attr2 = OBJ_CHAR(528 + 2*smoke_frame[i]);
oam[i].attr2 = OBJ_CHAR(sprite_start + 2*smoke_frame[i]);
}
~Smoke() {
@ -156,6 +158,24 @@ public:
int speed, angle;
};
class SpriteLoader {
u32 free_space;
u16 sprite_index;
public:
SpriteLoader() {
free_space = (u32)BITMAP_OBJ_BASE_ADR;
sprite_index = 512;
}
u16 load_from_memory(const void *source, u8 blocks) {
int bytes = blocks*8;
CpuFastSet(source, (void*)free_space, COPY32 | bytes/4);
free_space += bytes;
u16 pre_index = sprite_index;
sprite_index += blocks * 2 / 8;
return pre_index;
}
};
int main(void)
{
OBJATTR oe_buffer[2+NUMSMOKES+10];
@ -163,15 +183,11 @@ int main(void)
// Set up the interrupt handlers
InitInterrupt();
SetInterrupt( IE_VBL, VblankInterrupt);
// Enable Vblank Interrupt to allow VblankIntrWait
EnableInterrupt(IE_VBL);
// Allow Interrupts
REG_IME = 1;
// screen mode, background and objects to display
SetMode((LCDC_BITS)(MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP ));
@ -179,21 +195,17 @@ int main(void)
CpuFastSet(&white, (void*)VRAM, FILL | 240*160/4);
FadeToPalette((const u16*)car_pal_bin, 1);
u32 free_space = (u32)BITMAP_OBJ_BASE_ADR;
CpuFastSet(car_bin, (void*)free_space, COPY32 | car_bin_size/4);
free_space += car_bin_size;
CpuFastSet(car_blue_bin, (void*)free_space, COPY32 | car_bin_size/4);
free_space += car_blue_bin_size;
SpriteLoader loader;
u16 red_index = loader.load_from_memory(car_bin, car_bin_size/8);
u16 blue_index = loader.load_from_memory(car_blue_bin, car_bin_size/8);
u16 smoke_index = loader.load_from_memory(smoke_bin, smoke_bin_size/8);
CpuFastSet(car_pal_bin, OBJ_COLORS, COPY32 | car_pal_bin_size/4);
// load smoke
CpuFastSet(smoke_bin, (void*)free_space, COPY32 | smoke_bin_size/4);
free_space += smoke_bin_size;
Car red(102, 72, &oa_buffer[0], &oe_buffer[0], 0, 512);
Car blue(122, 72, &oa_buffer[1], &oe_buffer[1], 1, 520);
Smoke smoke(NUMSMOKES, &oe_buffer[2]);
Car red(102, 72, &oa_buffer[0], &oe_buffer[0], 0, red_index);
Car blue(122, 72, &oa_buffer[1], &oe_buffer[1], 1, blue_index);
Smoke smoke(NUMSMOKES, &oe_buffer[2], smoke_index);
while (1) {
if (KeysHeld() & KEY_RIGHT) {