comparison src/main.c @ 15:f71eb24b3896

placement of red walls with a button
author William Morgan <bill@mrgn.org>
date Sun, 12 Jan 2014 18:49:29 -0800
parents 5c7f33441e43
children a9500e8bff93 ea345aa9cc30
comparison
equal deleted inserted replaced
14:5c7f33441e43 15:f71eb24b3896
1 #include <genesis.h> 1 #include <genesis.h>
2 #include "creep.h" 2 #include "creep.h"
3 3
4 // I now realize this should be one tile that uses the flipping flags. oops.
4 const u32 cursor_tiles[4*8] = { 5 const u32 cursor_tiles[4*8] = {
5 0x21100000, // top left 6 0x21100000, // top left
6 0x10000000, 7 0x10000000,
7 0x10000000, 8 0x10000000,
8 0x00000000, 9 0x00000000,
38 0x00000001, 39 0x00000001,
39 0x00000112, 40 0x00000112,
40 41
41 }; 42 };
42 43
44 #define EMPTY 0
45 #define WALL 'O' + TILE_FONTINDEX
46 #define TOWER 'T' + TILE_FONTINDEX
47 #define GOAL 'G' + TILE_FONTINDEX
48
43 u16 tilemap[40*28]; 49 u16 tilemap[40*28];
44 u16 countdown; 50 u16 countdown;
45 51
46 int cursor_x = 0; 52 int cursor_x = 0; // tiles
47 int cursor_y = 0; 53 int cursor_y = 0; // tiles
48 const int cursor_size_px = 2 * 8; // two tiles of 8 pixels each 54 int pixels_per_tile = 8;
55 const int cursor_width = 2; // tiles
56
57
58 u16 build_order[3] = {
59 EMPTY,
60 WALL,
61 TOWER,
62 };
63 u8 build_order_size = 3;
49 64
50 void joy_event_handler(u16 joy, u16 changed, u16 state) { 65 void joy_event_handler(u16 joy, u16 changed, u16 state) {
51 u16 went_down = changed & state; 66 u16 went_down = changed & state;
52 if (went_down & BUTTON_UP) { 67 if (went_down & BUTTON_UP) {
53 cursor_y -= cursor_size_px; 68 cursor_y -= cursor_width;
54 } 69 }
55 if (went_down & BUTTON_DOWN) { 70 if (went_down & BUTTON_DOWN) {
56 cursor_y += cursor_size_px; 71 cursor_y += cursor_width;
57 } 72 }
58 if (went_down & BUTTON_LEFT) { 73 if (went_down & BUTTON_LEFT) {
59 cursor_x -= cursor_size_px; 74 cursor_x -= cursor_width;
60 } 75 }
61 if (went_down & BUTTON_RIGHT) { 76 if (went_down & BUTTON_RIGHT) {
62 cursor_x += cursor_size_px; 77 cursor_x += cursor_width;
78 }
79 if (went_down & BUTTON_A) {
80 tilemap[cursor_x + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
81 tilemap[cursor_x + 1 + (cursor_y ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
82 tilemap[cursor_x + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
83 tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
63 } 84 }
64 } 85 }
65 86
66 int main(void) 87 int main(void)
67 { 88 {
96 VDP_updateSprites(); 117 VDP_updateSprites();
97 for (i = 0; i < 28; i++) 118 for (i = 0; i < 28; i++)
98 { 119 {
99 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0); 120 VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0);
100 } 121 }
101 VDP_setSprite(0, cursor_x, cursor_y, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), spriteDefCache[0].link); 122 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);
102 if (countdown) 123 if (countdown)
103 --countdown; 124 --countdown;
104 else if (cur_creeps < 4) 125 else if (cur_creeps < 4)
105 { 126 {
106 spawn_creep(CREEP_NORMAL, 4, 122); 127 spawn_creep(CREEP_NORMAL, 4, 122);