changeset 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
files src/main.c
diffstat 1 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.c	Sun Jan 12 18:16:51 2014 -0800
+++ b/src/main.c	Sun Jan 12 18:49:29 2014 -0800
@@ -1,6 +1,7 @@
 #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,
@@ -40,26 +41,46 @@
 
 };
 
+#define EMPTY 0
+#define WALL 'O' + TILE_FONTINDEX
+#define TOWER 'T' + TILE_FONTINDEX
+#define GOAL 'G' + TILE_FONTINDEX
+
 u16 tilemap[40*28];
 u16 countdown;
 
-int cursor_x = 0;
-int cursor_y = 0;
-const int cursor_size_px = 2 * 8; // two tiles of 8 pixels each
+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;
 
 void joy_event_handler(u16 joy, u16 changed, u16 state) {
 	u16 went_down = changed & state;
 	if (went_down & BUTTON_UP) {
-		cursor_y -= cursor_size_px;
+		cursor_y -= cursor_width;
 	}
 	if (went_down & BUTTON_DOWN) {
-		cursor_y += cursor_size_px;
+		cursor_y += cursor_width;
 	}
 	if (went_down & BUTTON_LEFT) {
-		cursor_x -= cursor_size_px;
+		cursor_x -= cursor_width;
 	}
 	if (went_down & BUTTON_RIGHT) {
-		cursor_x += cursor_size_px;
+		cursor_x += cursor_width;
+	}
+	if (went_down & BUTTON_A) {
+		tilemap[cursor_x     + (cursor_y    ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
+		tilemap[cursor_x + 1 + (cursor_y    ) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
+		tilemap[cursor_x     + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
+		tilemap[cursor_x + 1 + (cursor_y + 1) * 40] = TILE_ATTR_FULL(1, 0, 0, 0, WALL);
 	}
 }
 
@@ -98,7 +119,7 @@
 		{
 			VDP_setTileMapRectByIndex(VDP_PLAN_B, tilemap + i*40, i*64, 40, 0);
 		}
-		VDP_setSprite(0, cursor_x, cursor_y, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), spriteDefCache[0].link);
+		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 (countdown)
 			--countdown;
 		else if (cur_creeps < 4)