Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed the extension to ino from pde for the VGS examples, also added …

…the trodoss games elventure and poofy adventure
  • Loading branch information...
commit d49e9b2daed9c76a9c929907c31b444c69ed3592 1 parent 560910e
matthewbeckler authored September 01, 2012

Showing 80 changed files with 4,278 additions and 74 deletions. Show diff stats Hide diff stats

  1. 2  README.txt
  2. 0  VideoGameHelper/examples/tetris/{tetris.pde → tetris.ino}
  3. 0  VideoGameHelper/examples/tic_tac_toe/{tic_tac_toe.pde → tic_tac_toe.ino}
  4. 1  VideoGameHelper/examples/trodoss_elventure/README.txt
  5. 101  VideoGameHelper/examples/trodoss_elventure/bitmap_funcs.cpp
  6. 8  VideoGameHelper/examples/trodoss_elventure/bitmap_funcs.h
  7. 63  VideoGameHelper/examples/trodoss_elventure/display.cpp
  8. 9  VideoGameHelper/examples/trodoss_elventure/display.h
  9. 41  VideoGameHelper/examples/trodoss_elventure/display_bitmap.cpp
  10. 8  VideoGameHelper/examples/trodoss_elventure/display_bitmap.h
  11. 284  VideoGameHelper/examples/trodoss_elventure/elf.cpp
  12. 39  VideoGameHelper/examples/trodoss_elventure/elf.h
  13. 125  VideoGameHelper/examples/trodoss_elventure/elf_bitmap.cpp
  14. 8  VideoGameHelper/examples/trodoss_elventure/elf_bitmap.h
  15. 189  VideoGameHelper/examples/trodoss_elventure/elventure.ino
  16. 94  VideoGameHelper/examples/trodoss_elventure/item.cpp
  17. 8  VideoGameHelper/examples/trodoss_elventure/item.h
  18. 145  VideoGameHelper/examples/trodoss_elventure/item_bitmap.cpp
  19. 8  VideoGameHelper/examples/trodoss_elventure/item_bitmap.h
  20. 20  VideoGameHelper/examples/trodoss_elventure/logo.cpp
  21. 6  VideoGameHelper/examples/trodoss_elventure/logo.h
  22. 125  VideoGameHelper/examples/trodoss_elventure/logo_bitmap.cpp
  23. 8  VideoGameHelper/examples/trodoss_elventure/logo_bitmap.h
  24. 93  VideoGameHelper/examples/trodoss_elventure/map.cpp
  25. 16  VideoGameHelper/examples/trodoss_elventure/map.h
  26. 75  VideoGameHelper/examples/trodoss_elventure/map_bitmap.cpp
  27. 8  VideoGameHelper/examples/trodoss_elventure/map_bitmap.h
  28. 174  VideoGameHelper/examples/trodoss_elventure/map_data.h
  29. 123  VideoGameHelper/examples/trodoss_elventure/monster.cpp
  30. 8  VideoGameHelper/examples/trodoss_elventure/monster.h
  31. 95  VideoGameHelper/examples/trodoss_elventure/monster_bitmap.cpp
  32. 8  VideoGameHelper/examples/trodoss_elventure/monster_bitmap.h
  33. 127  VideoGameHelper/examples/trodoss_elventure/room.cpp
  34. 42  VideoGameHelper/examples/trodoss_elventure/room.h
  35. 69  VideoGameHelper/examples/trodoss_elventure/room_data.h
  36. 127  VideoGameHelper/examples/trodoss_elventure/sound.cpp
  37. 9  VideoGameHelper/examples/trodoss_elventure/sound.h
  38. 185  VideoGameHelper/examples/trodoss_elventure/sound_data.h
  39. 1  VideoGameHelper/examples/trodoss_poofy_adventure/README.txt
  40. 132  VideoGameHelper/examples/trodoss_poofy_adventure/bitmap_funcs.cpp
  41. 8  VideoGameHelper/examples/trodoss_poofy_adventure/bitmap_funcs.h
  42. 18  VideoGameHelper/examples/trodoss_poofy_adventure/display.cpp
  43. 7  VideoGameHelper/examples/trodoss_poofy_adventure/display.h
  44. 24  VideoGameHelper/examples/trodoss_poofy_adventure/fruit.cpp
  45. 8  VideoGameHelper/examples/trodoss_poofy_adventure/fruit.h
  46. 35  VideoGameHelper/examples/trodoss_poofy_adventure/fruit_bitmap.cpp
  47. 8  VideoGameHelper/examples/trodoss_poofy_adventure/fruit_bitmap.h
  48. 146  VideoGameHelper/examples/trodoss_poofy_adventure/level.cpp
  49. 16  VideoGameHelper/examples/trodoss_poofy_adventure/level.h
  50. 35  VideoGameHelper/examples/trodoss_poofy_adventure/level_bitmap.cpp
  51. 8  VideoGameHelper/examples/trodoss_poofy_adventure/level_bitmap.h
  52. 10  VideoGameHelper/examples/trodoss_poofy_adventure/logo.cpp
  53. 6  VideoGameHelper/examples/trodoss_poofy_adventure/logo.h
  54. 31  VideoGameHelper/examples/trodoss_poofy_adventure/logo_bitmap.cpp
  55. 8  VideoGameHelper/examples/trodoss_poofy_adventure/logo_bitmap.h
  56. 85  VideoGameHelper/examples/trodoss_poofy_adventure/map_data.h
  57. 238  VideoGameHelper/examples/trodoss_poofy_adventure/poofy.cpp
  58. 40  VideoGameHelper/examples/trodoss_poofy_adventure/poofy.h
  59. 157  VideoGameHelper/examples/trodoss_poofy_adventure/poofy_adventure.ino
  60. 105  VideoGameHelper/examples/trodoss_poofy_adventure/poofy_bitmap.cpp
  61. 8  VideoGameHelper/examples/trodoss_poofy_adventure/poofy_bitmap.h
  62. 93  VideoGameHelper/examples/trodoss_poofy_adventure/room.cpp
  63. 34  VideoGameHelper/examples/trodoss_poofy_adventure/room.h
  64. 35  VideoGameHelper/examples/trodoss_poofy_adventure/room_data.h
  65. 116  VideoGameHelper/examples/trodoss_poofy_adventure/snake.cpp
  66. 8  VideoGameHelper/examples/trodoss_poofy_adventure/snake.h
  67. 45  VideoGameHelper/examples/trodoss_poofy_adventure/snake_bitmap.cpp
  68. 8  VideoGameHelper/examples/trodoss_poofy_adventure/snake_bitmap.h
  69. 127  VideoGameHelper/examples/trodoss_poofy_adventure/sound.cpp
  70. 9  VideoGameHelper/examples/trodoss_poofy_adventure/sound.h
  71. 145  VideoGameHelper/examples/trodoss_poofy_adventure/sound_data.h
  72. 2  VideoGameHelper/examples/tv_2p_pong/{tv_2p_pong.pde → tv_2p_pong.ino}
  73. 34  ...per/examples/tv_2p_pong_potentiometers/{tv_2p_pong_potentiometers.pde → tv_2p_pong_potentiometers.ino}
  74. 0  VideoGameHelper/examples/tv_2p_test/{tv_2p_test.pde → tv_2p_test.ino}
  75. 12  VideoGameHelper/examples/tv_data_collection/{tv_data_collection.pde → tv_data_collection.ino}
  76. 10  VideoGameHelper/examples/tv_life/{help.pde → help.ino}
  77. 3  VideoGameHelper/examples/tv_life/{life.pde → life.ino}
  78. 11  VideoGameHelper/examples/tv_life/{tv_life.pde → tv_life.ino}
  79. 38  VideoGameHelper/examples/tv_raycaster/{tv_raycaster.pde → tv_raycaster.ino}
  80. 37  VideoGameHelper/examples/tv_snake/{tv_snake.pde → tv_snake.ino}
2  README.txt
... ...
@@ -1,6 +1,6 @@
1 1
 Video Game Shield
2 2
 by Wayne and Layne, LLC
3  
-http://wayneandlayne.com/project/video-game-shield/
  3
+http://www.wayneandlayne.com/projects/video-game-shield/
4 4
 ==================================================
5 5
 
6 6
 This includes libraries and examples for the Video Game Shield.  The Video Game Shield is an expansion board for the Arduino microcontroller board.  It provides circuitry to enable analog black and white TV output as well as use two Wii Nunchucks.
0  VideoGameHelper/examples/tetris/tetris.pde → VideoGameHelper/examples/tetris/tetris.ino
File renamed without changes
0  VideoGameHelper/examples/tic_tac_toe/tic_tac_toe.pde → VideoGameHelper/examples/tic_tac_toe/tic_tac_toe.ino
File renamed without changes
1  VideoGameHelper/examples/trodoss_elventure/README.txt
... ...
@@ -0,0 +1 @@
  1
+This Elventure code was downloaded and added to the Video Game Shield archive on September 1, 2012. For the latest code, please visit http://code.google.com/p/trodoss-arduino/.
101  VideoGameHelper/examples/trodoss_elventure/bitmap_funcs.cpp
... ...
@@ -0,0 +1,101 @@
  1
+//bitmap_funcs.cpp from Parachute by pocketscience
  2
+//for full source of that sketch, see: http://nootropicdesign.com/hackvision/downloads/games/Parachute.zip
  3
+#include <avr/pgmspace.h>
  4
+#include <TVout.h>
  5
+#include "bitmap_funcs.h"
  6
+extern TVout TV;
  7
+
  8
+void overlaybitmap(uint8_t x, uint8_t y, const unsigned char * bmp ) {
  9
+
  10
+	uint8_t temp, lshift, rshift, save, xtra;
  11
+	uint16_t si = 0;
  12
+	uint16_t i;
  13
+        uint8_t width;
  14
+        uint8_t lines;
  15
+        
  16
+	rshift = x&7;
  17
+	lshift = 8-rshift;
  18
+	width = pgm_read_byte((uint32_t)(bmp) + i);
  19
+	i++;
  20
+	lines = pgm_read_byte((uint32_t)(bmp) + i);
  21
+	i++;
  22
+	
  23
+	if (width&7) {
  24
+	  xtra = width&7;
  25
+	  width = width/8;
  26
+	  width++;
  27
+	}
  28
+	else {
  29
+	  xtra = 8;
  30
+	  width = width/8;
  31
+	}
  32
+	
  33
+	for (uint8_t l = 0; l < lines; l++) {
  34
+	  si = (y + l)*display.hres + x/8;
  35
+	  save = display.screen[si];
  36
+	  temp = pgm_read_byte((uint32_t)(bmp) + i++);
  37
+	  display.screen[si++] |= temp >> rshift;
  38
+	  for ( uint16_t b = i + width-1; i < b; i++) {
  39
+	    save = display.screen[si];
  40
+	    display.screen[si] |= temp << lshift;
  41
+	    temp = pgm_read_byte((uint32_t)(bmp) + i);
  42
+	    display.screen[si++] |= temp >> rshift;
  43
+	  }
  44
+	  display.screen[si] |= temp << lshift;
  45
+	}
  46
+} // end of bitmap
  47
+
  48
+void erasebitmap(uint8_t x, uint8_t y, const unsigned char * bmp )
  49
+{
  50
+	uint8_t temp, lshift, rshift, save, xtra;
  51
+	uint16_t si = 0;
  52
+	uint16_t i = 0;
  53
+        uint8_t width;
  54
+        uint8_t lines;
  55
+        
  56
+	rshift = x&7;
  57
+	lshift = 8-rshift;
  58
+	width = pgm_read_byte((uint32_t)(bmp) + i);
  59
+	i++;
  60
+	lines = pgm_read_byte((uint32_t)(bmp) + i);
  61
+	i++;
  62
+	if (width&7) {
  63
+		xtra = width&7;
  64
+		width = width/8;
  65
+		width++;
  66
+	}
  67
+	else {
  68
+		xtra = 8;
  69
+		width = width/8;
  70
+	}
  71
+	
  72
+	for (uint8_t l = 0; l < lines; l++) {
  73
+	  si = (y + l)*display.hres + x/8;
  74
+		save = display.screen[si];
  75
+		temp = pgm_read_byte((uint32_t)(bmp) + i++);
  76
+		display.screen[si++] &= ~(temp >> rshift);
  77
+		for ( uint16_t b = i + width-1; i < b; i++) {
  78
+			save = display.screen[si];
  79
+			display.screen[si] &= ~(temp << lshift);
  80
+			temp = pgm_read_byte((uint32_t)(bmp) + i);
  81
+			display.screen[si++] &= ~(temp >> rshift);
  82
+		}
  83
+		if (rshift + xtra - 8 > 0)
  84
+{
  85
+		  display.screen[si] &= ~(temp << lshift);
  86
+}
  87
+	}
  88
+} // end of bitmap
  89
+
  90
+// erases a rectangle on the screen the size of the passed bitmap
  91
+void eraseBitmapRect( uint8_t x, uint8_t y, const unsigned char * bmp )
  92
+{
  93
+  uint8_t w, h;
  94
+  
  95
+  // extract width and height from bitmap
  96
+  w = pgm_read_byte((uint32_t)(bmp));
  97
+  h = pgm_read_byte((uint32_t)(bmp) + 1);
  98
+  
  99
+  TV.draw_rect( x, y, w, h, BLACK, BLACK ); 
  100
+}
  101
+
8  VideoGameHelper/examples/trodoss_elventure/bitmap_funcs.h
... ...
@@ -0,0 +1,8 @@
  1
+#ifndef __BITMAP_FUNCS__
  2
+#define __BITMAP_FUNCS__
  3
+
  4
+void overlaybitmap(uint8_t x, uint8_t y, const unsigned char * bmp );
  5
+void erasebitmap(uint8_t x, uint8_t y, const unsigned char * bmp );
  6
+void eraseBitmapRect( uint8_t x, uint8_t y, const unsigned char * bmp );
  7
+
  8
+#endif __BITMAP_FUNCS__
63  VideoGameHelper/examples/trodoss_elventure/display.cpp
... ...
@@ -0,0 +1,63 @@
  1
+#include <avr/pgmspace.h>
  2
+#include <TVout.h>
  3
+#include "display_bitmap.h"
  4
+#include "elf.h"
  5
+#include "display.h"
  6
+#include "room.h"
  7
+
  8
+extern TVout TV;
  9
+
  10
+#define SIZEOF_DISPLAY_RECORD 6
  11
+
  12
+void updateDisplay(Elf elf)
  13
+{
  14
+  //draw hearts
  15
+  char x_offset = 98;
  16
+  for (char i=1; i <= MAX_HEARTS; i++)
  17
+  {
  18
+    if (i <= elf.hearts)
  19
+    {
  20
+      //draw hearts
  21
+      TV.bitmap(x_offset, 4, display_bitmap + SIZEOF_DISPLAY_RECORD);
  22
+    } else {
  23
+      //draw blanks
  24
+      TV.bitmap(x_offset, 4, display_bitmap);
  25
+    }	
  26
+    x_offset += 5;
  27
+  }
  28
+   
  29
+  //draw crystals (inventory)
  30
+  x_offset = 98;
  31
+  for (char j=0; j < MAX_ITEMS; j++)
  32
+  {
  33
+    switch (elf.items[j])
  34
+    {
  35
+	  case ITEM_CRYSTAL:
  36
+        //draw crystals
  37
+        TV.bitmap(x_offset, 12, display_bitmap + (SIZEOF_DISPLAY_RECORD * 2 ));
  38
+		break;
  39
+		
  40
+	  case ITEM_ARMOR:
  41
+        //draw crystals
  42
+        TV.bitmap(x_offset, 12, display_bitmap + (SIZEOF_DISPLAY_RECORD * 3 ));
  43
+		break;
  44
+
  45
+	  case ITEM_ORB:
  46
+        //draw crystals
  47
+        TV.bitmap(x_offset, 12, display_bitmap + (SIZEOF_DISPLAY_RECORD * 4 ));
  48
+		break;
  49
+
  50
+	  case ITEM_STAFF:
  51
+        //draw crystals
  52
+        TV.bitmap(x_offset, 12, display_bitmap + (SIZEOF_DISPLAY_RECORD * 5 ));
  53
+		break;
  54
+		
  55
+      default:
  56
+        //draw blanks
  57
+        TV.bitmap(x_offset, 12, display_bitmap);
  58
+        break;
  59
+    }	
  60
+    x_offset += 5;
  61
+  }   
  62
+}
  63
+
9  VideoGameHelper/examples/trodoss_elventure/display.h
... ...
@@ -0,0 +1,9 @@
  1
+#ifndef __DISPLAY__
  2
+#define __DISPLAY__
  3
+#include "elf.h"
  4
+
  5
+#define MAX_HEARTS 4
  6
+
  7
+void updateDisplay(Elf elf);
  8
+
  9
+#endif __DISPLAY__
41  VideoGameHelper/examples/trodoss_elventure/display_bitmap.cpp
... ...
@@ -0,0 +1,41 @@
  1
+#include "display_bitmap.h"
  2
+
  3
+PROGMEM prog_uchar display_bitmap[] = {
  4
+
  5
+4,4,
  6
+0b00000000,
  7
+0b00000000,
  8
+0b00000000,
  9
+0b00000000,
  10
+
  11
+4,4,
  12
+0b11010000,
  13
+0b11110000,
  14
+0b01100000,
  15
+0b01000000,
  16
+
  17
+4,4,
  18
+0b00110000,
  19
+0b01010000,
  20
+0b10100000,
  21
+0b11000000,
  22
+
  23
+4,4,
  24
+0b11110000,
  25
+0b11110000,
  26
+0b11110000,
  27
+0b01100000,
  28
+
  29
+4,4,
  30
+0b01100000,
  31
+0b10010000,
  32
+0b10010000,
  33
+0b01100000,
  34
+
  35
+4,4,
  36
+0b00110000,
  37
+0b00110000,
  38
+0b01000000,
  39
+0b10000000,
  40
+
  41
+};
8  VideoGameHelper/examples/trodoss_elventure/display_bitmap.h
... ...
@@ -0,0 +1,8 @@
  1
+#ifndef DISPLAY_BITMAP_H
  2
+#define DISPLAY_BITMAP_H
  3
+
  4
+#include <avr/pgmspace.h>
  5
+
  6
+extern prog_uchar display_bitmap[];
  7
+
  8
+#endif
284  VideoGameHelper/examples/trodoss_elventure/elf.cpp
... ...
@@ -0,0 +1,284 @@
  1
+#include <avr/pgmspace.h>
  2
+#include <string.h>
  3
+#include <TVout.h>
  4
+#include "elf.h"
  5
+#include "elf_bitmap.h"
  6
+#include "map_bitmap.h"
  7
+#include "map.h"
  8
+#include "room.h"
  9
+#include "item.h"
  10
+#include "display.h"
  11
+#include "sound.h"
  12
+#include "bitmap_funcs.h"
  13
+extern TVout TV;
  14
+
  15
+#define SIZEOF_ELF_RECORD 10
  16
+
  17
+Elf elf = {FACING_DOWN, 1, 36, 24, 3, {0,0,0,0}, ELFSTATE_PLAYING};
  18
+
  19
+void resetElf(bool reset_items)
  20
+{
  21
+  elf.facing = FACING_DOWN;
  22
+  elf.step = 1;
  23
+  elf.x =  36;
  24
+  elf.y = 24;
  25
+  elf.hearts = 3;
  26
+  elf.state = ELFSTATE_PLAYING;
  27
+  if (reset_items) memset(elf.items, 0, sizeof(elf.items));
  28
+}
  29
+
  30
+void showElf()
  31
+{
  32
+  moveElf(elf.facing);
  33
+}
  34
+
  35
+void moveElf(unsigned char facing)
  36
+{
  37
+  //erase the old elf image (using blank map tile)
  38
+  TV.bitmap(elf.x, elf.y, map_bitmap);
  39
+  TV.bitmap(elf.x, elf.y + 8, map_bitmap);
  40
+  
  41
+  //if it is a new facing, then reset the step
  42
+  if (facing != elf.facing)
  43
+  {
  44
+     elf.step = 1;
  45
+  } else {
  46
+     elf.step++;
  47
+	 if (elf.step > 2) elf.step = 1;
  48
+  }
  49
+  
  50
+  elf.facing = facing;
  51
+  
  52
+  switch (facing)
  53
+  {
  54
+     case FACING_DOWN:
  55
+	   if (elf.y < 48)
  56
+           {
  57
+             if (checkMapRoomMove(elf.x, elf.y + 16) == 0) 
  58
+	        if (checkMapRoomMove(elf.x+4, elf.y + 16) == 0) elf.y += STEP_LENGTH;
  59
+           } else {
  60
+	     scrollMap(SCROLL_DOWN);
  61
+    	     elf.x = 36;
  62
+             elf.y = 8;
  63
+             elf.facing = FACING_DOWN;
  64
+	   }
  65
+	   break;
  66
+		
  67
+	case FACING_UP:
  68
+           if (elf.y > 4)
  69
+           {
  70
+             if (checkMapRoomMove(elf.x, elf.y - 4) == 0)
  71
+	        if (checkMapRoomMove(elf.x + 4, elf.y - 4) == 0) elf.y -= STEP_LENGTH;
  72
+           } else {
  73
+	     scrollMap(SCROLL_UP);
  74
+	     elf.x = 36;
  75
+	     elf.y = 32;
  76
+	     elf.facing = FACING_UP;
  77
+	   }
  78
+	   break;
  79
+	   
  80
+	case FACING_LEFT:
  81
+	   if (elf.x > 4)
  82
+           {
  83
+             if (checkMapRoomMove(elf.x - 4, elf.y) == 0)
  84
+                if (checkMapRoomMove(elf.x - 4, elf.y + 12) == 0) elf.x -= STEP_LENGTH;
  85
+           } else {
  86
+	       scrollMap(SCROLL_LEFT);
  87
+	       elf.x = 64;
  88
+	       elf.y = 24;
  89
+	       elf.facing = FACING_LEFT;
  90
+	   }
  91
+           break;
  92
+
  93
+        case FACING_RIGHT:
  94
+           if (elf.x < 80)
  95
+           {
  96
+             if (checkMapRoomMove(elf.x + 12, elf.y) == 0)
  97
+               if (checkMapRoomMove(elf.x + 12, elf.y + 12) == 0) elf.x += STEP_LENGTH;	
  98
+           } else {
  99
+	       scrollMap(SCROLL_RIGHT);
  100
+	       elf.x = 16;
  101
+	       elf.y = 24;
  102
+	       elf.facing = FACING_RIGHT;
  103
+	   }
  104
+           break;
  105
+  }
  106
+  
  107
+  //draw new elf bitmap
  108
+  overlaybitmap(elf.x, elf.y, elf_bitmap + ( elf.facing * SIZEOF_ELF_RECORD));
  109
+  overlaybitmap(elf.x, elf.y+8, elf_bitmap + ((elf.facing + elf.step) * SIZEOF_ELF_RECORD)); 
  110
+}
  111
+
  112
+void throwSword()
  113
+{
  114
+  //retrieve the sword room element
  115
+  RoomElement element = getRoomElement(0);
  116
+
  117
+  //if it is already active, do nothing, otherwise
  118
+  //initiate the sword being thrown
  119
+  if (element.state == STATE_HIDDEN)
  120
+  {
  121
+	  switch (elf.facing)
  122
+	  {
  123
+		case FACING_DOWN:
  124
+			element.state = STATE_MOVE_DOWN;
  125
+			element.x = elf.x;
  126
+			element.y = elf.y + 16;
  127
+			break;
  128
+			
  129
+		case FACING_UP:
  130
+			element.state = STATE_MOVE_UP;
  131
+			element.x = elf.x;
  132
+			element.y = elf.y - 8;			
  133
+			break;
  134
+
  135
+		case FACING_LEFT:
  136
+			element.state = STATE_MOVE_LEFT;
  137
+			element.x = elf.x - 8;
  138
+			element.y = elf.y;				
  139
+			break;
  140
+		
  141
+		case FACING_RIGHT:
  142
+			element.state = STATE_MOVE_RIGHT;
  143
+			element.x = elf.x + 8;
  144
+			element.y = elf.y;	
  145
+			break;
  146
+	  }  
  147
+	  updateRoomElement(element);
  148
+  }
  149
+}
  150
+
  151
+RoomElement hitElf(RoomElement element)
  152
+{
  153
+  //hit by a monster
  154
+  if (element.type < 50)
  155
+  {
  156
+    //check the counter, so hearts are not 
  157
+	//removed unless the monster has not been 'hit'
  158
+	//already
  159
+    if (element.counter == 0)
  160
+	{
  161
+      element.counter = COUNTER_START;
  162
+      elf.hearts--;
  163
+      if (elf.hearts < 1)
  164
+      {
  165
+        //game over
  166
+		elf.state = ELFSTATE_DEAD;
  167
+      }
  168
+	}
  169
+	
  170
+	//when the elf and a monster 'bump,' move the monster
  171
+	//in the opposite direction
  172
+	switch (element.state)
  173
+	{
  174
+	  case STATE_MOVE_UP:
  175
+	     element.state = STATE_MOVE_DOWN;
  176
+		 break;
  177
+		 
  178
+	  case STATE_MOVE_DOWN:
  179
+	     element.state = STATE_MOVE_UP;
  180
+		 break;
  181
+
  182
+	  case STATE_MOVE_LEFT:
  183
+	     element.state = STATE_MOVE_RIGHT;
  184
+		 break;		 
  185
+
  186
+	  case STATE_MOVE_RIGHT:
  187
+	     element.state = STATE_MOVE_LEFT;
  188
+		 break;	 
  189
+	}
  190
+  } else {
  191
+	switch (element.type)
  192
+	{
  193
+       case ITEM_HEART:
  194
+         if (elf.hearts < MAX_HEARTS) elf.hearts++;
  195
+         //handle the rest of the item hit
  196
+         element = hitItem(element);
  197
+         play_sfx(5);		 
  198
+		 break;
  199
+		 
  200
+       case ITEM_CRYSTAL:
  201
+	   case ITEM_ORB:
  202
+	   case ITEM_ARMOR:
  203
+	   case ITEM_STAFF:
  204
+	      addElfItem(element.type);
  205
+          //handle the rest of the item hit
  206
+          element = hitItem(element);			  
  207
+	      break;
  208
+		  
  209
+	   case ITEM_PORTAL:
  210
+             //handle the rest of the item hit
  211
+              element = hitItem(element);
  212
+              
  213
+	      if (getMapCurrentRoom() > 63)
  214
+		  {
  215
+		    //go to the bottom half of the map (underworld)
  216
+		    setMapRoom(0);
  217
+		    play_song(0);
  218
+		  } else {
  219
+		    //back to top half of the map (overworld)
  220
+		    setMapRoom(64);
  221
+	            play_song(1);
  222
+		  }
  223
+		  elf.x = 36;
  224
+		  elf.y = 24;
  225
+		  elf.facing = FACING_DOWN;
  226
+                  showElf();
  227
+	      break;
  228
+	} 	
  229
+  }
  230
+  
  231
+  //update the display
  232
+  updateDisplay(elf);
  233
+  
  234
+  return element;
  235
+}
  236
+  
  237
+Elf getElf()
  238
+{
  239
+    return elf;
  240
+}
  241
+
  242
+//adds the item in the elf's inventory
  243
+void addElfItem(char type)
  244
+{
  245
+  char count = 0;
  246
+  for (char i=0; i< MAX_ITEMS; i++)
  247
+  {
  248
+    if (elf.items[i] == 0)
  249
+	{
  250
+	  elf.items[i] = type;
  251
+	  break;
  252
+	} else {
  253
+	  count++;
  254
+	}
  255
+  }
  256
+  
  257
+  if (count == MAX_ITEMS)
  258
+  {
  259
+    //won game
  260
+	elf.state = ELFSTATE_WON;
  261
+  } else {
  262
+    //otherwise, play the sound effect
  263
+    play_sfx(6);  
  264
+  }
  265
+}
  266
+
  267
+//check the elf's inventory for a specific item
  268
+bool elfHasItem(char type)
  269
+{
  270
+  for (char i=0; i< MAX_ITEMS; i++)
  271
+  {
  272
+    if ((elf.items[i] > 50) && (elf.items[i] == type)) return true;
  273
+  } 
  274
+  return false;  
  275
+}
  276
+
  277
+//check the elf's current state
  278
+char getElfState()
  279
+{
  280
+  return elf.state;
  281
+}
  282
+
  283
+
  284
+
39  VideoGameHelper/examples/trodoss_elventure/elf.h
... ...
@@ -0,0 +1,39 @@
  1
+#ifndef __ELF__
  2
+#define __ELF__
  3
+#include "room.h"
  4
+
  5
+#define FACING_DOWN  0
  6
+#define FACING_UP    3
  7
+#define FACING_LEFT  6
  8
+#define FACING_RIGHT 9
  9
+
  10
+#define STEP_LENGTH  4
  11
+
  12
+#define MAX_ITEMS 3
  13
+
  14
+#define ELFSTATE_PLAYING 0
  15
+#define ELFSTATE_DEAD 1
  16
+#define ELFSTATE_WON 2
  17
+
  18
+struct Elf
  19
+{
  20
+  unsigned char facing;
  21
+  unsigned char step;
  22
+  unsigned char x;
  23
+  unsigned char y;
  24
+  unsigned char hearts;
  25
+  unsigned char items[4];
  26
+  unsigned char state;
  27
+};
  28
+
  29
+void resetElf(bool reset_items);
  30
+void showElf();
  31
+void moveElf(unsigned char facing);
  32
+void throwSword();
  33
+RoomElement hitElf(RoomElement element);
  34
+Elf getElf();
  35
+void addElfItem(char type);
  36
+bool elfHasItem(char type);
  37
+char getElfState();
  38
+
  39
+#endif __ELF__
125  VideoGameHelper/examples/trodoss_elventure/elf_bitmap.cpp
... ...
@@ -0,0 +1,125 @@
  1
+#include "elf_bitmap.h"
  2
+
  3
+PROGMEM prog_uchar elf_bitmap[] = {
  4
+
  5
+8,8,
  6
+0b00000000,
  7
+0b00001000,
  8
+0b00011100,
  9
+0b01000001,
  10
+0b01101011,
  11
+0b00101010,
  12
+0b00011100,
  13
+0b00000000,
  14
+
  15
+8,8,
  16
+0b01010111,
  17
+0b10000111,
  18
+0b00101010,
  19
+0b00110000,
  20
+0b00000110,
  21
+0b00110000,
  22
+0b00000000,
  23
+0b00000000,
  24
+
  25
+8,8,
  26
+0b01010111,
  27
+0b11000111,
  28
+0b10010010,
  29
+0b00001100,
  30
+0b01100000,
  31
+0b00001100,
  32
+0b00000000,
  33
+0b00000000,
  34
+
  35
+8,8,
  36
+0b00000000,
  37
+0b00000000,
  38
+0b00010000,
  39
+0b10111010,
  40
+0b10111010,
  41
+0b01010100,
  42
+0b00111000,
  43
+0b00000000,
  44
+
  45
+8,8,
  46
+0b11011010,
  47
+0b11000011,
  48
+0b10111001,
  49
+0b00110000,
  50
+0b00000110,
  51
+0b00110000,
  52
+0b00000000,
  53
+0b00000000,
  54
+
  55
+8,8,
  56
+0b11011010,
  57
+0b11000001,
  58
+0b10011100,
  59
+0b00001100,
  60
+0b01100000,
  61
+0b00001100,
  62
+0b00000000,
  63
+0b00000000,
  64
+
  65
+8,8,
  66
+0b00000000,
  67
+0b00101100,
  68
+0b11110010,
  69
+0b00001110,
  70
+0b01011010,
  71
+0b11011000,
  72
+0b01110000,
  73
+0b00000000,
  74
+
  75
+8,8,
  76
+0b10111000,
  77
+0b11001100,
  78
+0b10110100,
  79
+0b01000000,
  80
+0b11001100,
  81
+0b00000000,
  82
+0b00000000,
  83
+0b00000000,
  84
+
  85
+8,8,
  86
+0b10111000,
  87
+0b11001000,
  88
+0b10110000,
  89
+0b00000000,
  90
+0b00110000,
  91
+0b00000000,
  92
+0b00000000,
  93
+0b00000000,
  94
+
  95
+8,8,
  96
+0b00000000,
  97
+0b00110100,
  98
+0b01001111,
  99
+0b01110000,
  100
+0b01011010,
  101
+0b00011011,
  102
+0b00001110,
  103
+0b00000000,
  104
+
  105
+8,8,
  106
+0b00011101,
  107
+0b00110011,
  108
+0b00101101,
  109
+0b00000010,
  110
+0b00110011,
  111
+0b00000000,
  112
+0b00000000,
  113
+0b00000000,
  114
+
  115
+8,8,
  116
+0b00011101,
  117
+0b00010011,
  118
+0b00001101,
  119
+0b00000000,
  120
+0b00001100,
  121
+0b00000000,
  122
+0b00000000,
  123
+0b00000000,
  124
+
  125
+};
8  VideoGameHelper/examples/trodoss_elventure/elf_bitmap.h
... ...
@@ -0,0 +1,8 @@
  1
+#ifndef ELF_BITMAP_H
  2
+#define ELF_BITMAP_H
  3
+
  4
+#include <avr/pgmspace.h>
  5
+
  6
+extern prog_uchar elf_bitmap[];
  7
+
  8
+#endif
189  VideoGameHelper/examples/trodoss_elventure/elventure.ino
... ...
@@ -0,0 +1,189 @@
  1
+/*                                   __    
  2
+                                   /___/
  3
+                                   / /
  4
+   /-------------/              __/_/__
  5
+     |  |-------/       //===//__<*>_ //===//
  6
+     |  .----/                 / / /
  7
+     |  .---/                 / / /
  8
+     |  |------/             / / /
  9
+   /----------/ L + V + E + N + T + U + R + E *=-
  10
+   An Adventure Game for the Arduino/Video Game Shield 
  11
+
  12
+   2011 - trodoss
  13
+   
  14
+   This program is free software; you can redistribute it and/or modify
  15
+   it under the terms of the GNU General Public License as published by
  16
+   the Free Software Foundation; either version 2 of the License, or
  17
+   (at your option) any later version.
  18
+   
  19
+   This program is distributed in the hope that it will be useful,
  20
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
  21
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22
+   GNU General Public License for more details.
  23
+   
  24
+   bitmap_funcs.cpp used from "Parachute" sketch by pocketscience.
  25
+   For a full copy of that sketch, see:
  26
+   http://nootropicdesign.com/hackvision/downloads/games/Parachute.zip
  27
+   
  28
+ */
  29
+ 
  30
+#include <stdlib.h> 
  31
+#include <i2cmaster.h>
  32
+#include <nunchuck.h>
  33
+#include <TVout.h>
  34
+#include <font4x6.h>
  35
+
  36
+#include "map.h"
  37
+#include "room.h"
  38
+#include "elf.h"
  39
+#include "sound.h"
  40
+#include "display.h"
  41
+#include "logo.h"
  42
+
  43
+#define SCREENWIDTH     128
  44
+#define SCREENHEIGHT    96
  45
+
  46
+#define PAUSE_BETWEEN_ACTIONS 100
  47
+
  48
+#define GAME_TITLE   0
  49
+#define GAME_PLAYING 1
  50
+#define GAME_PAUSED  2
  51
+#define GAME_WON     3
  52
+#define GAME_OVER    4
  53
+TVout TV;
  54
+Nunchuck player1;
  55
+char game_state;
  56
+
  57
+void setup()
  58
+{
  59
+  TV.begin(_NTSC, SCREENWIDTH, SCREENHEIGHT);
  60
+  TV.select_font(font4x6);
  61
+  
  62
+  randomSeed(analogRead(0));
  63
+  player1.begin(0);
  64
+  
  65
+  start_title();
  66
+}
  67
+
  68
+void loop()
  69
+{  
  70
+  static long next_action = 0;
  71
+  switch (game_state)
  72
+  {
  73
+    case GAME_TITLE:
  74
+	case GAME_OVER:
  75
+	case GAME_WON:
  76
+       if (TV.millis() >= next_action)
  77
+       {
  78
+         player1.update();
  79
+		 //wait for a button to be pressed to continue
  80
+         if ((player1.button_c()) || (player1.button_z()))
  81
+         {
  82
+		   
  83
+		   //check to see what we are doing when we start the game
  84
+		   if (game_state > GAME_TITLE)
  85
+		   {
  86
+		     if (game_state == GAME_WON)
  87
+			 {
  88
+			   //if the game has been won, then reset the inventory of the elf
  89
+			   resetElf(true);
  90
+			 } else {
  91
+			   //if the game was just over (died) then do not reset the inventory
  92
+		       resetElf(false);
  93
+			 }
  94
+		   }
  95
+		   
  96
+		   game_state = GAME_PLAYING;
  97
+		   start_game();
  98
+         }
  99
+		         
  100
+         next_action = TV.millis() + PAUSE_BETWEEN_ACTIONS; 
  101
+       }	
  102
+	   update_sound();
  103
+	   break;
  104
+	   
  105
+	case GAME_PLAYING:
  106
+       if (TV.millis() >= next_action)
  107
+       {      
  108
+         player1.update();
  109
+       
  110
+         if (player1.joy_up()) moveElf(FACING_UP);
  111
+         if (player1.joy_down()) moveElf(FACING_DOWN);
  112
+         if (player1.joy_right()) moveElf(FACING_RIGHT);
  113
+         if (player1.joy_left()) moveElf(FACING_LEFT);
  114
+         if (player1.button_z()) throwSword();
  115
+         if (player1.button_c()) game_state = GAME_PAUSED;
  116
+    
  117
+         next_action = TV.millis() + PAUSE_BETWEEN_ACTIONS; 
  118
+	
  119
+         handleRoomElements();
  120
+		 
  121
+		 //check the elf's state
  122
+		 if (getElfState() != ELFSTATE_PLAYING)
  123
+		 {
  124
+		   if (getElfState() == ELFSTATE_DEAD)
  125
+		   {
  126
+		     start_game_over();
  127
+		   } else {
  128
+		     start_game_won();
  129
+		   }
  130
+		 }
  131
+       }
  132
+       update_sound();
  133
+       break;
  134
+       
  135
+   case GAME_PAUSED:
  136
+       if (TV.millis() >= next_action)
  137
+       {
  138
+         player1.update();
  139
+		 
  140
+         if (player1.button_c()) game_state = GAME_PLAYING;
  141
+         
  142
+         next_action = TV.millis() + PAUSE_BETWEEN_ACTIONS; 
  143
+       }
  144
+       break;
  145
+  }
  146
+}
  147
+
  148
+void start_game()
  149
+{
  150
+  //clear the contents of the screen
  151
+  TV.clear_screen();
  152
+  
  153
+  //start the game
  154
+  setMapRoom(0);
  155
+  showElf();
  156
+  updateDisplay(getElf());
  157
+  play_song(0);
  158
+  game_state = GAME_PLAYING;  
  159
+}
  160
+
  161
+void start_title()
  162
+{
  163
+  //clear the contents of the screen
  164
+  TV.clear_screen();
  165
+  
  166
+  game_state = GAME_TITLE;
  167
+  drawLogo(0);
  168
+  play_song(4);
  169
+}
  170
+
  171
+void start_game_over()
  172
+{
  173
+  //clear the contents of the screen
  174
+  TV.clear_screen();
  175
+  
  176
+  game_state = GAME_OVER;
  177
+  drawLogo(4);
  178
+  play_song_once(2);
  179
+}
  180
+
  181
+void start_game_won()
  182
+{
  183
+  //clear the contents of the screen
  184
+  TV.clear_screen();
  185
+  
  186
+  game_state = GAME_WON;
  187
+  drawLogo(8);
  188
+  play_song(3);
  189
+}
94  VideoGameHelper/examples/trodoss_elventure/item.cpp
... ...
@@ -0,0 +1,94 @@
  1
+#include <avr/pgmspace.h>
  2
+#include <TVout.h>
  3
+#include "item.h"
  4
+#include "map.h"
  5
+#include "map_bitmap.h"
  6
+#include "item_bitmap.h"
  7
+#include "room.h"
  8
+#include "bitmap_funcs.h"
  9
+
  10
+extern TVout TV;
  11
+
  12
+#define STEP_LENGTH  4
  13
+#define SIZEOF_ITEM_RECORD 10
  14
+
  15
+RoomElement moveItem(RoomElement element)
  16
+{
  17
+   if (element.state > STATE_HIDDEN) 
  18
+   {
  19
+    //erase the old item image (using blank map tile)
  20
+    TV.bitmap(element.x, element.y, map_bitmap);
  21
+  
  22
+    element.step++;
  23
+    if (element.step > 2) element.step = 1;
  24
+   
  25
+    switch (element.state)
  26
+    {
  27
+	   case STATE_MOVE_UP:
  28
+           element.state = STATE_HIDDEN;
  29
+           if (element.y > 4)
  30
+           {
  31
+             if (checkMapRoomMove(element.x, element.y - 4) == 0)
  32
+			 {
  33
+			   element.y -= STEP_LENGTH;
  34
+               element.state = STATE_MOVE_UP;
  35
+			 }
  36
+		   }
  37
+	   break;
  38
+	   
  39
+	  case STATE_MOVE_DOWN:   
  40
+           element.state = STATE_HIDDEN;
  41
+           if (element.y < 48)
  42
+           {
  43
+             if (checkMapRoomMove(element.x, element.y + 8) == 0)
  44
+			 {
  45
+			   element.y += STEP_LENGTH;
  46
+			   element.state = STATE_MOVE_DOWN;
  47
+			 }
  48
+		   }
  49
+	   break;	   
  50
+
  51
+	  case STATE_MOVE_LEFT:
  52
+           element.state = STATE_HIDDEN;
  53
+           if (element.x > 4)
  54
+           {
  55
+             if (checkMapRoomMove(element.x - 4, element.y) == 0)
  56
+			 {
  57
+			   element.x -= STEP_LENGTH;
  58
+			   element.state = STATE_MOVE_LEFT;
  59
+			 }
  60
+		   }
  61
+	   break;	   
  62
+	   
  63
+	  case STATE_MOVE_RIGHT:
  64
+           element.state = STATE_HIDDEN;
  65
+           if (element.x < 80)
  66
+           {
  67
+             if (checkMapRoomMove(element.x + 12, element.y) == 0)
  68
+			 {
  69
+			   element.x += STEP_LENGTH;
  70
+			   element.state = STATE_MOVE_RIGHT;
  71
+			 }
  72
+		   }
  73
+	   break;		      
  74
+    }
  75
+
  76
+    //draw new item bitmap
  77
+    if (element.state > STATE_HIDDEN) overlaybitmap(element.x, element.y, item_bitmap + ( ((element.type - 51) + (element.step)) * SIZEOF_ITEM_RECORD));
  78
+	
  79
+	//decrement counter, if active
  80
+	if (element.counter > 0) element.counter--;	
  81
+  }
  82
+  return element;
  83
+}
  84
+
  85
+RoomElement hitItem(RoomElement element)
  86
+{
  87
+  //erase the old item image (using blank map tile)
  88
+  TV.bitmap(element.x, element.y, map_bitmap);
  89
+  
  90
+  element.state = STATE_HIDDEN;
  91
+  return element;
  92
+}
  93
+
  94
+
8  VideoGameHelper/examples/trodoss_elventure/item.h
... ...
@@ -0,0 +1,8 @@
  1
+#ifndef __ITEM__
  2
+#define __ITEM__
  3
+#include "room.h"
  4
+
  5
+RoomElement moveItem(RoomElement element);
  6
+RoomElement hitItem(RoomElement element);
  7
+
  8
+#endif __ITEM__
145  VideoGameHelper/examples/trodoss_elventure/item_bitmap.cpp
... ...
@@ -0,0 +1,145 @@
  1
+#include "item_bitmap.h"
  2
+
  3
+PROGMEM prog_uchar item_bitmap[] = {
  4
+
  5
+8,8,
  6
+0b00000011,
  7
+0b00000101,
  8
+0b00001010,
  9
+0b01010100,
  10
+0b01101000,
  11
+0b00110000,
  12
+0b01011000,