Mercurial > repos > genjam1
view src/main.c @ 25:2f56bc29a3d6 default tip
Beefed up the cursor a bit. Cleaned up my unused build order array.
author | William Morgan <bill@mrgn.org> |
---|---|
date | Tue, 14 Jan 2014 00:06:22 -0800 |
parents | 2cee3dc5fe4d |
children |
line wrap: on
line source
#include <genesis.h> #include "creep.h" #include "map.h" const u32 cursor_tiles[4*8] = { 0x11111000, // top left 0x13322100, 0x13111000, 0x12100000, 0x12100000, 0x01000000, 0x00000000, 0x00000000, 0x00000000, // bottom left 0x00000000, 0x01000000, 0x12100000, 0x12100000, 0x13111000, 0x13322100, 0x11111000, 0x00011111, // top right 0x00122331, 0x00011131, 0x00000121, 0x00000121, 0x00000010, 0x00000000, 0x00000000, 0x00000000, // bottom right 0x00000000, 0x00000010, 0x00000121, 0x00000121, 0x00011131, 0x00122331, 0x00011111, }; u16 countdown; s16 cursor_x = 0; // tiles s16 cursor_y = 0; // tiles u16 cursor_selection = WALL; #define CURSOR_BLINK_RATE 16 #define CURSOR_WIDTH 2; // tiles #define PIXELS_PER_TILE 8 u8 running = 0; void clear_cursor() { VDP_setTileMap(VDP_PLAN_A, 0, cursor_x, cursor_y); VDP_setTileMap(VDP_PLAN_A, 0, cursor_x + 1, cursor_y); VDP_setTileMap(VDP_PLAN_A, 0, cursor_x, cursor_y + 1); VDP_setTileMap(VDP_PLAN_A, 0, cursor_x + 1, cursor_y + 1); } void joy_event_handler(u16 joy, u16 changed, u16 state) { u16 went_down = changed & state; if (went_down & BUTTON_UP) { clear_cursor(); cursor_y -= CURSOR_WIDTH; } if (went_down & BUTTON_DOWN) { clear_cursor(); cursor_y += CURSOR_WIDTH; } if (went_down & BUTTON_LEFT) { clear_cursor(); cursor_x -= CURSOR_WIDTH; } if (went_down & BUTTON_RIGHT) { clear_cursor(); cursor_x += CURSOR_WIDTH; } if (went_down & BUTTON_B && !running) { cursor_selection = (cursor_selection + 1) % GOAL; } if (went_down & BUTTON_A && !running) { place_object(cursor_selection, cursor_x, cursor_y); gen_distances(38, 14); if (distances[122/16] == 0xFFFF) { place_object(EMPTY, cursor_x, cursor_y); } } if (went_down & BUTTON_START) { running = 1; } } int main(void) { JOY_init(); JOY_setEventHandler(&joy_event_handler); u8 cursor_tile_index = 1; VDP_loadTileData((const u32 *)cursor_tiles, cursor_tile_index, 4, 0); u16 i; VDP_setPlanSize(64, 32); /*for (i = 6; i < 40*28; i += 4) if ((i > 80 || i & 4) && (i < 40*26 || !(i & 4)) && i % 40 < 38) { tilemap[i] = WALL; tilemap[i+1] = WALL; } */ place_object(GOAL, 38, 14); place_object(SPAWN, 0, 14); gen_distances(38, 14); for (i = 0; i < MAX_SPRITE; i++) { spriteDefCache[i].posx = -0x80; } //print_distances(); for (;;) { VDP_waitVSync(); VDP_updateSprites(); if ((getTick() % CURSOR_BLINK_RATE) == 0 && !running) { VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][0], cursor_x, cursor_y); VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][1], cursor_x + 1, cursor_y); VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][2], cursor_x, cursor_y + 1); VDP_setTileMap(VDP_PLAN_A, tileinfo[cursor_selection][3], cursor_x + 1, cursor_y + 1); } if ((getTick() % CURSOR_BLINK_RATE) == CURSOR_BLINK_RATE >> 1) { clear_cursor(); } for (i = 0; i < 28; i++) { VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); } VDP_setSprite(0, cursor_x * PIXELS_PER_TILE, cursor_y * PIXELS_PER_TILE, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), spriteDefCache[0].link); if (running) { if (countdown) --countdown; else if (cur_creeps < 4) { spawn_creep(CREEP_NORMAL, 0+4, 14*8+4); countdown = 300; } update_creeps(); } } return 0; }