Mercurial > repos > genjam1
view src/main.c @ 18:60bb690233cf
merge
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sun, 12 Jan 2014 19:11:54 -0800 |
parents | ea345aa9cc30 a9500e8bff93 |
children | 51a0972fcf76 |
line wrap: on
line source
#include <genesis.h> #include "creep.h" // I now realize this should be one tile that uses the flipping flags. oops. const u32 cursor_tiles[4*8] = { 0x21100000, // top left 0x10000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // bottom left 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x21100000, 0x00000112, // top right 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // bottom right 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x00000112, }; #define EMPTY 0 #define WALL 'O'-32 + TILE_FONTINDEX #define TOWER TILE_ATTR_FULL(1, 0, 0, 0, 'T'-32 + TILE_FONTINDEX) #define GOAL TILE_ATTR_FULL(1, 0, 0, 0, 'G'-32 + TILE_FONTINDEX) u16 tilemap[40*28]; u16 countdown; int cursor_x = 0; // tiles int cursor_y = 0; // tiles int pixels_per_tile = 8; const int cursor_width = 2; // tiles u16 build_order[3] = { EMPTY, WALL, TOWER, }; u8 build_order_size = 3; u8 running = 0; void joy_event_handler(u16 joy, u16 changed, u16 state) { u16 went_down = changed & state; if (went_down & BUTTON_UP) { cursor_y -= cursor_width; } if (went_down & BUTTON_DOWN) { cursor_y += cursor_width; } if (went_down & BUTTON_LEFT) { cursor_x -= cursor_width; } if (went_down & BUTTON_RIGHT) { cursor_x += cursor_width; } if (went_down & BUTTON_A && !running) { //u16 type_to_place = EMPTY; u16 type_to_place = WALL; tilemap[cursor_x + (cursor_y ) * 40] = type_to_place; tilemap[cursor_x + 1 + (cursor_y ) * 40] = type_to_place; tilemap[cursor_x + (cursor_y + 1) * 40] = type_to_place; tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = type_to_place; gen_distances(38, 14); if (distances[122/16] == 0xFFFF) { tilemap[cursor_x + (cursor_y ) * 40] = 0; tilemap[cursor_x + 1 + (cursor_y ) * 40] = 0; tilemap[cursor_x + (cursor_y + 1) * 40] = 0; tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = 0; } } 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; } */ tilemap[38 + 14*40] = GOAL; tilemap[39 + 14*40] = GOAL; tilemap[38 + 15*40] = GOAL; tilemap[39 + 15*40] = GOAL; for (i = 0; i < MAX_SPRITE; i++) { spriteDefCache[i].posx = -0x80; } gen_distances(38, 14); //print_distances(); for (;;) { VDP_waitVSync(); VDP_updateSprites(); 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, 4, 122); countdown = 300; } update_creeps(); } } return 0; }