X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgamescr.c;h=56e390010241d330a6d0f672fe92784834fe42cf;hb=fb3b2fcb8626823232533d59dad1be5dc27d6a78;hp=a84aa123b48154843fb22d079d16b4d3f87af545;hpb=198dd3b315f6e04fe6843d4d371e97e5d60e6309;p=gbajam22 diff --git a/src/gamescr.c b/src/gamescr.c index a84aa12..56e3900 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -8,6 +8,7 @@ #include "input.h" #include "gba.h" #include "sprite.h" +#include "timer.h" #include "debug.h" #include "voxscape.h" #include "data.h" @@ -16,12 +17,16 @@ #define NEAR 2 #define FAR 85 +#define P_RATE 250 +#define E_RATE 250 +#define SHOT_TIME 50 + static int gamescr_start(void); static void gamescr_stop(void); static void gamescr_frame(void); static void gamescr_vblank(void); -static void update(void); +static int update(void); static void draw(void); static struct screen gamescr = { @@ -36,8 +41,9 @@ struct enemy { struct vox_object vobj; short hp; short anm; - short last_fire; + int last_shot; }; +#define ENEMY_VALID(e) ((e)->anm != 0) static uint16_t *framebuf; @@ -45,7 +51,7 @@ static int nframes, backbuf; static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 }; static int32_t pos[2], angle, horizon = 80; -static struct voxscape *vox; +static long last_shot; #define COLOR_HORIZON 192 #define COLOR_ZENITH 255 @@ -55,12 +61,14 @@ static uint16_t oam[4 * MAX_SPR]; static int dynspr_base, dynspr_count; -#define MAX_ENEMIES 64 +#define MAX_ENEMIES (255 - CMAP_SPAWN0) struct enemy enemies[MAX_ENEMIES]; -int num_enemies, total_enemies; +int num_kills, total_enemies; static int energy; #define MAX_ENERGY 5 +#define ENEMY_ENERGY 4 + #define XFORM_PIXEL_X(x, y) (xform_ca * (x) - xform_sa * (y) + (120 << 8)) #define XFORM_PIXEL_Y(x, y) (xform_sa * (x) + xform_ca * (y) + (80 << 8)) @@ -68,6 +76,7 @@ static int32_t xform_sa, xform_ca; /* for viewport bank/zoom */ static int xform_s; static short vblcount; +static void *prev_iwram_top; static inline void xform_pixel(int *xp, int *yp); @@ -78,38 +87,44 @@ struct screen *init_game_screen(void) return &gamescr; } +static void setup_palette(void) +{ + int i; + unsigned char *cmap = gba_colors ? color_gba_cmap : color_cmap; + + emuprint("setting up %s palette", gba_colors ? "GBA" : "NDS/Emu"); + + for(i=0; i<256; i++) { + int r = cmap[i * 3]; + int g = cmap[i * 3 + 1]; + int b = cmap[i * 3 + 2]; + gba_bgpal[i] = RGB555(r, g, b); + } +} + static int gamescr_start(void) { - int i, sidx; + int i, j, sidx; + uint8_t *cptr; + struct enemy *enemy; + + prev_iwram_top = iwram_sbrk(0); gba_setmode(4, DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1); + fillblock_16byte(gba_vram_lfb1, 0, 240 * 160 / 16); vblperf_setcolor(0); - pos[0] = VOX_SZ << 15; - pos[1] = (VOX_SZ << 15) + 0x100000; + pos[0] = pos[1] = VOX_SZ << 15; angle = 0x8000; + last_shot = -P_RATE - 1; - if(!(vox = vox_create(VOX_SZ, VOX_SZ, height_pixels, color_pixels))) { - panic(get_pc(), "vox_create"); - } - vox_proj(vox, FOV, NEAR, FAR); - vox_view(vox, pos[0], pos[1], -40, angle); + vox_init(VOX_SZ, VOX_SZ, height_pixels, color_pixels); + vox_proj(FOV, NEAR, FAR); + vox_view(pos[0], pos[1], -40, angle); /* setup color image palette */ - for(i=0; i<256; i++) { - int r = color_cmap[i * 3]; - int g = color_cmap[i * 3 + 1]; - int b = color_cmap[i * 3 + 2]; - gba_bgpal[i] = (((uint16_t)b << 7) & 0x7c00) | (((uint16_t)g << 2) & 0x3e0) | (((uint16_t)r >> 3) & 0x1f); - } - /* - intr_disable(); - interrupt(INTR_HBLANK, hblank); - REG_DISPSTAT |= DISPSTAT_IEN_HBLANK; - unmask(INTR_HBLANK); - intr_enable(); - */ + setup_palette(); spr_setup(16, 16, spr_game_pixels, spr_game_cmap); wait_vblank(); @@ -128,30 +143,75 @@ static int gamescr_start(void) spr_oam(oam, sidx++, SPRID_UISLASH, 216, 144, SPR_VRECT | SPR_256COL); dynspr_base = sidx; - wait_vblank(); - dma_copy32(3, (void*)OAM_ADDR, oam, sidx * 2, 0); - - num_enemies = 0; - total_enemies = 8; + num_kills = total_enemies = 0; energy = 5; - srand(0); + memset(enemies, 0, sizeof enemies); + cptr = color_pixels; + for(i=0; i= CMAP_SPAWN0 && *cptr != 255) { + /* enemy spawn point */ + int idx = *cptr - CMAP_SPAWN0; + enemy = enemies + idx; + if(enemy->anm) { + panic(get_pc(), "double spawn %d at %d,%d (prev: %d,%d)", idx, + j, i, enemy->vobj.x, enemy->vobj.y); + } + enemy->vobj.x = j; + enemy->vobj.y = i; + enemy->vobj.px = -1; + enemy->anm = 0xff; + enemy->hp = ENEMY_ENERGY; + enemy->last_shot = timer_msec > E_RATE ? timer_msec - E_RATE : 0; + if(++total_enemies >= MAX_ENEMIES) { + goto endspawn; + } + } + cptr++; + } + } +endspawn: + /* check continuity */ for(i=0; i= P_RATE)) { + last_shot = timer_msec; + for(i=0; i= 0) { + int dx = enemies[i].vobj.px - 120; + int dy = enemies[i].vobj.py - 80; + int rad = enemies[i].vobj.scale >> 5; + + /*emuprint("rad: %d (%d,%d)", rad, enemies[i].vobj.px, enemies[i].vobj.py);*/ + if(rad < 1) rad = 1; + + if(abs(dx) < rad && abs(dy) < (rad << 1)) { + enemies[i].hp--; + break; + } + } + } } if(keystate & BN_UP) { if(horizon > 40) horizon -= ELEV_SPEED; @@ -242,13 +321,13 @@ static void update(void) pos[1] -= right[1]; } - vox_view(vox, pos[0], pos[1], -40, angle); + vox_view(pos[0], pos[1], -40, angle); } snum = 0; /* turrets number */ - spr_oam(oam, dynspr_base + snum++, numspr[num_enemies][0], 200, 144, SPR_VRECT | SPR_256COL); - spr_oam(oam, dynspr_base + snum++, numspr[num_enemies][1], 208, 144, SPR_VRECT | SPR_256COL); + spr_oam(oam, dynspr_base + snum++, numspr[num_kills][0], 200, 144, SPR_VRECT | SPR_256COL); + spr_oam(oam, dynspr_base + snum++, numspr[num_kills][1], 208, 144, SPR_VRECT | SPR_256COL); spr_oam(oam, dynspr_base + snum++, numspr[total_enemies][0], 224, 144, SPR_VRECT | SPR_256COL); spr_oam(oam, dynspr_base + snum++, numspr[total_enemies][1], 232, 144, SPR_VRECT | SPR_256COL); /* energy bar */ @@ -265,26 +344,30 @@ static void update(void) /*spr_oam(oam, dynspr_base + snum++, SPRID_ENEMY, 50, 50, SPR_VRECT | SPR_SZ64 | SPR_256COL);*/ enemy = enemies; for(i=0; ivobj.px >= 0) { - flags = SPR_SZ32 | SPR_DBLSZ | SPR_256COL | SPR_ROTSCL | SPR_ROTSCL_SEL(0); + flags = SPR_DBLSZ | SPR_256COL | SPR_ROTSCL | SPR_ROTSCL_SEL(0); if(enemies->hp > 0) { anm = (enemies->anm + (vblcount >> 3)) & 0xf; sid = SPRID_ENEMY0 + ((anm & 7) << 2); - flags |= SPR_VRECT; + flags |= SPR_SZ32 | SPR_VRECT; + yoffs = 32; } else { + anm = 0; sid = SPRID_HUSK; + flags |= SPR_SZ16; + yoffs = 16; } px = enemy->vobj.px - 120; py = enemy->vobj.py - 80; xform_pixel(&px, &py); - spr_oam(oam, dynspr_base + snum++, sid, px - 20, py - 32, flags); + spr_oam(oam, dynspr_base + snum++, sid, px - 16, py - yoffs, flags); scale = enemy->vobj.scale; if(scale > 0x10000) scale = 0x10000; @@ -300,6 +383,17 @@ static void update(void) } enemy++; } + if(timer_msec - last_shot <= SHOT_TIME) { + spr_oam(oam, dynspr_base + snum++, SPRID_LAS0, -8, 118, SPR_SZ32 | SPR_256COL); + spr_oam(oam, dynspr_base + snum++, SPRID_LAS1, 22, 103, SPR_SZ32 | SPR_256COL); + spr_oam(oam, dynspr_base + snum++, SPRID_LAS2, 54, 88, SPR_SZ32 | SPR_256COL); + spr_oam(oam, dynspr_base + snum++, SPRID_LAS3, 86, 72, SPR_SZ32 | SPR_256COL); + + spr_oam(oam, dynspr_base + snum++, SPRID_LAS0, 240 + 8 - 32, 118, SPR_SZ32 | SPR_256COL | SPR_HFLIP); + spr_oam(oam, dynspr_base + snum++, SPRID_LAS1, 240 - 22 - 32, 103, SPR_SZ32 | SPR_256COL | SPR_HFLIP); + spr_oam(oam, dynspr_base + snum++, SPRID_LAS2, 240 - 54 - 32, 88, SPR_SZ32 | SPR_256COL | SPR_HFLIP); + spr_oam(oam, dynspr_base + snum++, SPRID_LAS3, 240 - 86 - 32, 72, SPR_SZ32 | SPR_256COL | SPR_HFLIP); + } for(i=snum; i