Some more simple test code for the Gameduino

June 11, 2011 | Arduino, Gameduino | By: Mark VandeWettering

Without explanation or screen dump, here’s a little program I hacked together.

Update: The syntax highlighter I was using is munging this stuff. So, here’s a link to a zip file containing the code.

[sourcecode lang=”C++”]
#include
#include
#include

unsigned char h, m, s, f ;

static PROGMEM prog_uchar pacman_img[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 68, 68, 68, 68, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 68, 68, 68, 68, 68, 68, 68, 68, 0, 0, 0, 0,
0, 0, 0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0, 0, 0,
0, 0, 68, 68, 68, 17, 17, 68, 68, 68, 68, 17, 17, 68, 0, 0,
0, 0, 68, 68, 17, 17, 17, 17, 68, 68, 17, 17, 17, 17, 0, 0,
0, 0, 68, 68, 17, 17, 34, 34, 68, 68, 17, 17, 34, 34, 0, 0,
0, 68, 68, 68, 17, 17, 34, 34, 68, 68, 17, 17, 34, 34, 68, 0,
0, 68, 68, 68, 68, 17, 17, 68, 68, 68, 68, 17, 17, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 4, 68, 64, 68, 4, 4, 68, 64, 68, 4, 68, 68, 0,
0, 64, 4, 4, 0, 64, 64, 4, 4, 64, 64, 0, 4, 4, 64, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 85, 85, 85, 85, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 85, 85, 85, 85, 85, 85, 85, 85, 0, 0, 0, 0,
0, 0, 0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0, 0, 0,
0, 0, 85, 85, 85, 17, 17, 85, 85, 85, 85, 17, 17, 85, 0, 0,
0, 0, 85, 85, 17, 17, 17, 17, 85, 85, 17, 17, 17, 17, 0, 0,
0, 0, 85, 85, 17, 17, 34, 34, 85, 85, 17, 17, 34, 34, 0, 0,
0, 85, 85, 85, 17, 17, 34, 34, 85, 85, 17, 17, 34, 34, 85, 0,
0, 85, 85, 85, 85, 17, 17, 85, 85, 85, 85, 17, 17, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 5, 85, 80, 85, 5, 5, 85, 80, 85, 5, 85, 85, 0,
0, 80, 5, 5, 0, 80, 80, 5, 5, 80, 80, 0, 5, 5, 80, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 102, 102, 102, 102, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 102, 102, 102, 102, 102, 102, 102, 102, 0, 0, 0, 0,
0, 0, 0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0, 0, 0,
0, 0, 102, 102, 102, 17, 17, 102, 102, 102, 102, 17, 17, 102, 0, 0,
0, 0, 102, 102, 17, 17, 17, 17, 102, 102, 17, 17, 17, 17, 0, 0,
0, 0, 102, 102, 17, 17, 34, 34, 102, 102, 17, 17, 34, 34, 0, 0,
0, 102, 102, 102, 17, 17, 34, 34, 102, 102, 17, 17, 34, 34, 102, 0,
0, 102, 102, 102, 102, 17, 17, 102, 102, 102, 102, 17, 17, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 6, 102, 96, 102, 6, 6, 102, 96, 102, 6, 102, 102, 0,
0, 96, 6, 6, 0, 96, 96, 6, 6, 96, 96, 0, 6, 6, 96, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 119, 119, 119, 119, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 119, 119, 119, 119, 119, 119, 119, 119, 0, 0, 0, 0,
0, 0, 0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0, 0, 0,
0, 0, 119, 119, 119, 17, 17, 119, 119, 119, 119, 17, 17, 119, 0, 0,
0, 0, 119, 119, 17, 17, 17, 17, 119, 119, 17, 17, 17, 17, 0, 0,
0, 0, 119, 119, 17, 17, 34, 34, 119, 119, 17, 17, 34, 34, 0, 0,
0, 119, 119, 119, 17, 17, 34, 34, 119, 119, 17, 17, 34, 34, 119, 0,
0, 119, 119, 119, 119, 17, 17, 119, 119, 119, 119, 17, 17, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 7, 119, 112, 119, 7, 7, 119, 112, 119, 7, 119, 119, 0,
0, 112, 7, 7, 0, 112, 112, 7, 7, 112, 112, 0, 7, 7, 112, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

} ;

int px[4] = {0, 0, 0, 0} ;
int vx[4] = { 11, 12, 14, 16 } ;
int cnt = 0 ;

void
setup()
{
int i;

delay(2500) ;
GD.begin() ;

GD.ascii() ;

h = m = s = 0 ;

GD.copy(RAM_SPRIMG, pacman_img, sizeof(pacman_img)) ;
GD.copy(RAM_SPRIMG, pacman_img, sizeof(pacman_img)) ;
GD.wr16(PALETTE16A+0, TRANSPARENT) ;
GD.wr16(PALETTE16A+2, RGB(255,255,255)) ;
GD.wr16(PALETTE16A+4, RGB(0, 0, 64)) ;
GD.wr16(PALETTE16A+14, RGB(255, 0, 0)) ;
GD.wr16(PALETTE16A+12, RGB(0, 192, 192)) ;
GD.wr16(PALETTE16A+10, RGB(255, 128, 128)) ;
GD.wr16(PALETTE16A+8, RGB(255, 160, 0)) ;

GD.fill(RAM_PIC+22*64, 1, 64) ;
GD.wr16(RAM_CHR+16*1+0, 0) ;
GD.wr16(RAM_CHR+16*1+2, 0) ;
GD.wr16(RAM_CHR+16*1+4, 0) ;
GD.wr16(RAM_CHR+16*1+6, 0x4001) ;
GD.wr16(RAM_CHR+16*1+8, 0x4001) ;
GD.wr16(RAM_CHR+16*1+10, 0) ;
GD.wr16(RAM_CHR+16*1+12, 0) ;
GD.wr16(RAM_CHR+16*1+14, 0) ;
GD.wr16(RAM_PAL+8*1+0, TRANSPARENT) ;
GD.wr16(RAM_PAL+8*1+2, RGB(255,255,0)) ;

GD.putstr(15, 17, “It’s time for PacMan!”) ;

for (i=0; i<4; i++)
px[i] = random(-16*16, 400*16) ;

}

void
loop()
{
char timebuf[9] ;
int i ;

for (;;) {
for (i=0; i<4; i++) {
px[i] += vx[i] ;
if (vx[i] >= 400*16)
px[i] -= 401 * 16 ;
}

cnt = cnt + 1 ;
if (cnt >= 16) cnt = 0 ;
f ++ ;
if (f >= 72) {
f = 0 ;
s++ ;
if (s >= 60) {
s = 0 ;
m ++ ;
if (m >= 60) {
m = 0 ;
h++ ;
if (h >= 24) h = 0 ;
}
}
}
GD.waitvblank() ;
for (i=0; i<4; i++)
GD.sprite(i, px[i]/16, 180-8, i, 4+2*(cnt >= 8), 0, 0) ;
sprintf(timebuf, “%02d:%02d:%02d”, h, m, s) ;
GD.putstr(21, 19, timebuf) ;
}
}
[/sourcecode]

Comments

Comment from James, N9XLC
Time 6/11/2011 at 9:30 pm

Let me guess.. it’s a clock that displays the pacman ghosts in some manner?

Comment from Mark VandeWettering
Time 6/11/2011 at 10:36 pm

Very good!

Comment from Fungus
Time 6/12/2011 at 12:13 pm

You’ll be needing this:

http://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php

Comment from Ruslan
Time 9/23/2014 at 9:28 am

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: “Arduino Diecimila or Duemilanove w/ ATmega168”
D:\game\arduino 106\Arduino\libraries\Gameduino\GD.cpp:14:22: error: WProgram.h: No such file or directory
What’s the problem?

Comment from Ruslan
Time 9/25/2014 at 9:11 am

Ok it’s work) why made this? – http://arduino-project.net/analog-clock-arduino-mega/