changeset 13:d118fe8fb1db

Make cursor and creeps play nice
author Mike Pavone <pavone@retrodev.com>
date Sun, 12 Jan 2014 17:19:42 -0800
parents 1ee4a5c23c95
children 5c7f33441e43
files src/creep.c src/main.c
diffstat 2 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/creep.c	Sun Jan 12 17:07:43 2014 -0800
+++ b/src/creep.c	Sun Jan 12 17:19:42 2014 -0800
@@ -12,7 +12,7 @@
 	u16 index;
 	for (index = 0; index < MAX_SPRITE; index++)
 	{
-		if (spriteDefCache[index].posx <= 0) {
+		if (spriteDefCache[index].posx == -0x80) {
 			break;
 		}
 	}
--- a/src/main.c	Sun Jan 12 17:07:43 2014 -0800
+++ b/src/main.c	Sun Jan 12 17:19:42 2014 -0800
@@ -45,31 +45,31 @@
 
 int cursor_x = 0;
 int cursor_y = 0;
-const int cursor_size_px = 2 * 8; // two tiles of 8 pixels each
+const int cursor_size_px = 2 * 8; // two tiles of 8 pixels each
 
-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;
-	}
-	if (went_down & BUTTON_DOWN) {
-		cursor_y += cursor_size_px;
-	}
-	if (went_down & BUTTON_LEFT) {
-		cursor_x -= cursor_size_px;
-	}
-	if (went_down & BUTTON_RIGHT) {
-		cursor_x += cursor_size_px;
-	}
+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;
+	}
+	if (went_down & BUTTON_DOWN) {
+		cursor_y += cursor_size_px;
+	}
+	if (went_down & BUTTON_LEFT) {
+		cursor_x -= cursor_size_px;
+	}
+	if (went_down & BUTTON_RIGHT) {
+		cursor_x += cursor_size_px;
+	}
 }
 
 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);
+	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);
@@ -85,16 +85,20 @@
 	tilemap[38 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX);
 	tilemap[39 + 15*40] = TILE_ATTR_FULL(1, 0, 0, 0, 'G' + TILE_FONTINDEX);
 	gen_distances(38, 14);
+	for (i = 0; i < MAX_SPRITE; i++)
+	{
+		spriteDefCache[i].posx = -0x80;
+	}
 	//print_distances();
 	for (;;)
 	{
-		VDP_setSprite(0, cursor_x, cursor_y, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), 0);
 		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, cursor_y, SPRITE_SIZE(2,2), TILE_ATTR_FULL(PAL0, 1, 0, 0, cursor_tile_index), spriteDefCache[0].link);
 		if (cur_creeps < 4)
 		{
 			if (countdown)