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 lut_cos(x) _sinLUT[(x + (SIN_SIZE>>2)) & SIN_MASK]
#define NUMSMOKES 30 #define NUMSMOKES 20
unsigned int frame; unsigned int frame;
@ -45,9 +45,10 @@ class Smoke {
int num_entries; int num_entries;
s8* smoke_frame; s8* smoke_frame;
u8 next_smoke; u8 next_smoke;
u16 sprite_start;
public: public:
Smoke(int num_entries, OBJATTR* start) { Smoke(int num_entries, OBJATTR* start, u16 sprite_index) {
oam = start; oam = start;
smoke_frame = new s8[num_entries]; smoke_frame = new s8[num_entries];
next_smoke = 0; next_smoke = 0;
@ -58,6 +59,7 @@ public:
// 6 == off // 6 == off
smoke_frame[i] = 6; smoke_frame[i] = 6;
} }
sprite_start = sprite_index;
} }
void increase_frame_counts() { void increase_frame_counts() {
for (u8 i=0; i<num_entries; i++) { for (u8 i=0; i<num_entries; i++) {
@ -79,7 +81,7 @@ public:
void update_sprites() { void update_sprites() {
for (u8 i=0; i<num_entries; i++) 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() { ~Smoke() {
@ -156,6 +158,24 @@ public:
int speed, angle; 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) int main(void)
{ {
OBJATTR oe_buffer[2+NUMSMOKES+10]; OBJATTR oe_buffer[2+NUMSMOKES+10];
@ -163,37 +183,29 @@ int main(void)
// Set up the interrupt handlers // Set up the interrupt handlers
InitInterrupt(); InitInterrupt();
SetInterrupt( IE_VBL, VblankInterrupt); SetInterrupt( IE_VBL, VblankInterrupt);
// Enable Vblank Interrupt to allow VblankIntrWait // Enable Vblank Interrupt to allow VblankIntrWait
EnableInterrupt(IE_VBL); EnableInterrupt(IE_VBL);
// Allow Interrupts // Allow Interrupts
REG_IME = 1; REG_IME = 1;
// screen mode, background and objects to display // screen mode, background and objects to display
SetMode((LCDC_BITS)(MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP )); SetMode((LCDC_BITS)(MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP ));
u32 white = 0x10101010; u32 white = 0x10101010;
CpuFastSet(&white, (void*)VRAM, FILL | 240*160/4); CpuFastSet(&white, (void*)VRAM, FILL | 240*160/4);
FadeToPalette((const u16*)car_pal_bin, 1); FadeToPalette((const u16*)car_pal_bin, 1);
u32 free_space = (u32)BITMAP_OBJ_BASE_ADR; SpriteLoader loader;
CpuFastSet(car_bin, (void*)free_space, COPY32 | car_bin_size/4);
free_space += car_bin_size; u16 red_index = loader.load_from_memory(car_bin, car_bin_size/8);
CpuFastSet(car_blue_bin, (void*)free_space, COPY32 | car_bin_size/4); u16 blue_index = loader.load_from_memory(car_blue_bin, car_bin_size/8);
free_space += car_blue_bin_size; 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); CpuFastSet(car_pal_bin, OBJ_COLORS, COPY32 | car_pal_bin_size/4);
// load smoke Car red(102, 72, &oa_buffer[0], &oe_buffer[0], 0, red_index);
CpuFastSet(smoke_bin, (void*)free_space, COPY32 | smoke_bin_size/4); Car blue(122, 72, &oa_buffer[1], &oe_buffer[1], 1, blue_index);
free_space += smoke_bin_size; Smoke smoke(NUMSMOKES, &oe_buffer[2], smoke_index);
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]);
while (1) { while (1) {
if (KeysHeld() & KEY_RIGHT) { if (KeysHeld() & KEY_RIGHT) {