final version
This commit is contained in:
parent
4740d1d3dd
commit
2209c7feee
|
@ -1,6 +1,6 @@
|
||||||
-- title screen
|
-- title screen
|
||||||
0012345678901234567890123456789012
|
0012345678901234567890123456789012
|
||||||
01.##### ..####..#...##..####..##.
|
01.#####...####..#...##..####..##.
|
||||||
02.######.######.##..##.######.##.
|
02.######.######.##..##.######.##.
|
||||||
03.##..##.##..##.###.##.##..##.##.
|
03.##..##.##..##.###.##.##..##.##.
|
||||||
04.##..##.##..##.######.##.....##.
|
04.##..##.##..##.######.##.....##.
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
14.##.....##..##.##..##.##..##....
|
14.##.....##..##.##..##.##..##....
|
||||||
15.##.....######.##..##.######.##.
|
15.##.....######.##..##.######.##.
|
||||||
16.##......####..##..##..####..##.
|
16.##......####..##..##..####..##.
|
||||||
|
##
|
||||||
-- anim 1
|
-- anim 1
|
||||||
0012345678901234567890123456789012
|
0012345678901234567890123456789012
|
||||||
01##..##..##..##..##..##..##..##..
|
01##..##..##..##..##..##..##..##..
|
||||||
|
@ -34,3 +35,4 @@
|
||||||
14..##..##..##..##..##..##..##..##
|
14..##..##..##..##..##..##..##..##
|
||||||
15#..##..##..##..##..##..##..##..#
|
15#..##..##..##..##..##..##..##..#
|
||||||
16##..##..##..##..##..##..##..##..
|
16##..##..##..##..##..##..##..##..
|
||||||
|
##
|
84
convert.php
84
convert.php
|
@ -4,60 +4,48 @@ $max=0;
|
||||||
|
|
||||||
$in=fopen("bitmaps.txt","r");
|
$in=fopen("bitmaps.txt","r");
|
||||||
while(!feof($in)) {
|
while(!feof($in)) {
|
||||||
$line=fgets($in,100);
|
$line=trim(fgets($in,100));
|
||||||
//print_r($line);
|
//print_r($line);
|
||||||
$cmd=substr($line,0,2);
|
$cmd=substr($line,0,2);
|
||||||
$cnt=substr($line,2);
|
$cnt=substr($line,2);
|
||||||
|
if($cmd=="--"){
|
||||||
|
$name=$cnt;
|
||||||
|
}
|
||||||
if(is_numeric($cmd) and $cmd!="00"){
|
if(is_numeric($cmd) and $cmd!="00"){
|
||||||
$data[$cmd]=$cnt;
|
$data[$cmd]=$cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen($data0)>$max) $max=strlen($data0);
|
if($cmd=="##"){
|
||||||
for($i=0;$i<strlen($data0);$i++){
|
echo "//$name \n {";
|
||||||
$d0=($data0[$i]=='.'?0:1<<3);
|
for($i=0;$i<32;$i++){
|
||||||
$d1=($data1[$i]=='.'?0:1<<2);
|
$d0=($data["01"][$i]=='.'?0:1<<3);
|
||||||
$d2=($data2[$i]=='.'?0:1<<1);
|
$d1=($data["02"][$i]=='.'?0:1<<2);
|
||||||
$d3=$data3[$i]=='.'?0:1;
|
$d2=($data["03"][$i]=='.'?0:1<<1);
|
||||||
$D=$d0+$d1+$d2+$d3;
|
$d3=$data["04"][$i]=='.'?0:1;
|
||||||
$d0=($data4[$i]=='.'?0:1<<3);
|
$D=$d0+$d1+$d2+$d3;
|
||||||
$d1=($data5[$i]=='.'?0:1<<2);
|
print("$D,");
|
||||||
$d2=($data6[$i]=='.'?0:1<<1);
|
$d0=($data["05"][$i]=='.'?0:1<<3);
|
||||||
$d3=$data7[$i]=='.'?0:1;
|
$d1=($data["06"][$i]=='.'?0:1<<2);
|
||||||
$L=$d0+$d1+$d2+$d3;
|
$d2=($data["07"][$i]=='.'?0:1<<1);
|
||||||
$upper[$z][]=$D;
|
$d3=$data["08"][$i]=='.'?0:1;
|
||||||
$lower[$z][]=$L;
|
$D=$d0+$d1+$d2+$d3;
|
||||||
|
print("$D,");
|
||||||
|
}
|
||||||
|
for($i=0;$i<32;$i++){
|
||||||
|
$d0=($data["09"][$i]=='.'?0:1<<3);
|
||||||
|
$d1=($data["10"][$i]=='.'?0:1<<2);
|
||||||
|
$d2=($data["11"][$i]=='.'?0:1<<1);
|
||||||
|
$d3=$data["12"][$i]=='.'?0:1;
|
||||||
|
$D=$d0+$d1+$d2+$d3;
|
||||||
|
print("$D,");
|
||||||
|
$d0=($data["13"][$i]=='.'?0:1<<3);
|
||||||
|
$d1=($data["14"][$i]=='.'?0:1<<2);
|
||||||
|
$d2=($data["15"][$i]=='.'?0:1<<1);
|
||||||
|
$d3=$data["16"][$i]=='.'?0:1;
|
||||||
|
$D=$d0+$d1+$d2+$d3;
|
||||||
|
print("$D,");
|
||||||
|
}
|
||||||
|
echo "}\n";
|
||||||
}
|
}
|
||||||
$z++;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "char f_width[$z]={";
|
|
||||||
for($i=0;$i<$z;$i++) echo $width[$i].",";
|
|
||||||
echo "};\n";
|
|
||||||
echo "char f_upper[$z][$max]={";
|
|
||||||
for($i=0;$i<$z;$i++){
|
|
||||||
echo "{";
|
|
||||||
for($j=0;$j<$max;$j++) {
|
|
||||||
if(isset($upper[$i][$j]))
|
|
||||||
echo $upper[$i][$j].",";
|
|
||||||
else
|
|
||||||
echo "0,";
|
|
||||||
}
|
|
||||||
echo "},";
|
|
||||||
}
|
|
||||||
echo "};\n";
|
|
||||||
echo "char f_lower[$z][$max]={";
|
|
||||||
for($i=0;$i<$z;$i++){
|
|
||||||
echo "{";
|
|
||||||
for($j=0;$j<$max;$j++) {
|
|
||||||
if(isset($lower[$i][$j]))
|
|
||||||
echo $lower[$i][$j].",";
|
|
||||||
else
|
|
||||||
echo "0,";
|
|
||||||
}
|
|
||||||
echo "},";
|
|
||||||
}
|
|
||||||
echo "};\n";
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
340
pong.ino
340
pong.ino
|
@ -1,33 +1,30 @@
|
||||||
#include <avr/pgmspace.h>
|
|
||||||
#include "ht1632.h"
|
#include "ht1632.h"
|
||||||
|
|
||||||
#define P1WIN 0
|
#define WIN 0
|
||||||
#define P2WIN 1
|
#define PONG 1
|
||||||
#define PONG 2
|
#define CLS 2
|
||||||
#define FIVE 3
|
|
||||||
#define FOUR 4
|
|
||||||
#define THREE 5
|
|
||||||
#define TWO 6
|
|
||||||
#define ONE 7
|
|
||||||
#define CLS 8
|
|
||||||
/*
|
/*
|
||||||
* Set these constants to the values of the pins connected to the SureElectronics Module
|
* Set these constants to the values of the pins connected to the SureElectronics Module
|
||||||
*/
|
*/
|
||||||
static const byte ht1632_data = 6; // Data pin (pin 7)
|
//static const byte ht1632_data = 6; // Data pin (pin 7)
|
||||||
static const byte ht1632_wrclk = 7; // Write clock pin (pin 5)
|
//static const byte ht1632_wrclk = 7; // Write clock pin (pin 5)
|
||||||
static const byte ht1632_cs[] = {8,9}; // Chip Select (1, 2, 3, or 4)
|
//static const byte ht1632_cs[] = {8,9}; // Chip Select (1, 2, 3, or 4)
|
||||||
|
static const byte ht1632_data = 3; // Data pin (pin 7)
|
||||||
|
static const byte ht1632_wrclk = 4; // Write clock pin (pin 5)
|
||||||
|
static const byte ht1632_cs[] = {5,6}; // Chip Select (1, 2, 3, or 4)
|
||||||
static const byte ht1632_displays = 2; // Number of displays
|
static const byte ht1632_displays = 2; // Number of displays
|
||||||
|
|
||||||
|
static const byte p1control = 0;
|
||||||
|
static const byte p2control = 1;
|
||||||
|
static const byte button = 2;
|
||||||
|
static const byte speaker = 12;
|
||||||
|
|
||||||
|
unsigned long prevmillis = 0;
|
||||||
|
|
||||||
static const byte bitmaps[][128]={
|
static const byte bitmaps[][128]={
|
||||||
{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,1,8,3,12,6,6,12,3,8,1,0,0,15,15,15,15,0,3,0,6,0,12,0,12,0,6,0,3,15,15,15,15,0,0,0,0,15,15,15,15,0,0,0,0,15,15,15,15,6,0,3,0,1,8,0,12,0,6,0,3,15,15,15,15,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},
|
{12,12,9,9,3,3,6,6,12,12,9,9,3,3,6,6,12,12,9,9,3,3,6,6,12,12,9,9,3,3,6,6,12,12,9,9,3,3,6,6,12,12,9,9,3,3,6,6,12,12,9,9,3,3,6,6,12,12,9,9,3,3,6,6,3,3,9,9,12,12,6,6,3,3,9,9,12,12,6,6,3,3,9,9,12,12,6,6,3,3,9,9,12,12,6,6,3,3,9,9,12,12,6,6,3,3,9,9,12,12,6,6,3,3,9,9,12,12,6,6,3,3,9,9,12,12,6,6},
|
||||||
{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,15,15,15,15,0,3,0,6,0,12,0,12,0,6,0,3,15,15,15,15,0,0,0,0,15,15,15,15,0,0,0,0,15,15,15,15,6,0,3,0,1,8,0,12,0,6,0,3,15,15,15,15,0,0,8,1,12,3,6,6,3,12,1,8,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,15,15,15,15,12,12,12,12,15,12,7,8,0,0,7,15,15,15,12,0,12,0,15,15,7,15,0,0,15,15,7,15,3,0,1,8,15,15,15,15,0,0,7,15,15,15,12,0,12,0,14,0,6,0,0,0,15,15,15,15,0,0,0,0,15,15,15,15,0,0,0,0,0,0,0,0,0,0,15,14,15,15,0,3,0,3,15,15,15,14,0,0,15,15,15,15,0,0,0,0,15,15,15,15,0,0,15,14,15,15,0,3,3,3,3,15,3,14,0,0,15,11,15,11,0,0},
|
||||||
{1,2,3,4,15,0,15,0,13,0,8,0,13,0,8,0,13,0,8,0,15,0,8,0,7,0,0,0,0,0,0,0,7,0,14,0,15,0,15,12,3,12,3,12,3,15,15,7,14,0,0,15,15,15,15,6,0,3,0,1,8,0,12,15,15,15,15,0,0,7,14,15,15,12,3,13,11,13,11,13,15,5,14},
|
{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,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,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,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,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,15,10,15,11,13,11,13,11,13,11,13,11,13,15,12,14,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,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,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,3,8,7,8,13,8,13,8,13,8,15,15,15,15,1,8,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,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,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,4,2,12,3,12,3,13,11,13,11,13,11,15,15,7,14,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,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,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,4,3,12,7,12,15,12,11,13,11,13,3,15,3,6,3,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,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,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,6,3,15,15,15,15,0,3,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,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,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,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,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}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,6 +94,8 @@ static void ht1632_sendshadowram ()
|
||||||
|
|
||||||
void setup () // flow chart from page 17 of datasheet
|
void setup () // flow chart from page 17 of datasheet
|
||||||
{
|
{
|
||||||
|
// Serial.begin(115200);
|
||||||
|
pinMode(button,INPUT_PULLUP);
|
||||||
pinMode(ht1632_wrclk, OUTPUT);
|
pinMode(ht1632_wrclk, OUTPUT);
|
||||||
pinMode(ht1632_data, OUTPUT);
|
pinMode(ht1632_data, OUTPUT);
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ void setup () // flow chart from page 17 of datasheet
|
||||||
for (byte i=0; i<64; i++)
|
for (byte i=0; i<64; i++)
|
||||||
ht1632_senddata(i, 0,ht1632_cs[j]); // clear the display!
|
ht1632_senddata(i, 0,ht1632_cs[j]); // clear the display!
|
||||||
}
|
}
|
||||||
randomSeed(analogRead(0));
|
randomSeed(analogRead(3));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,126 +153,207 @@ void showbitmap(char bitmap){
|
||||||
ht1632_sendshadowram();
|
ht1632_sendshadowram();
|
||||||
}
|
}
|
||||||
|
|
||||||
void game()
|
void bat(byte x, byte y, byte bs, byte value){
|
||||||
{
|
for(bs; bs>0; bs--){
|
||||||
// x & y scaled by 8
|
plot(x,y+bs-1,value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int X=16*8;
|
|
||||||
int Y=4*8;
|
|
||||||
int Xo=X;
|
|
||||||
int Yo=Y;
|
|
||||||
int XRC=8;
|
|
||||||
int YRC=2;
|
|
||||||
byte p1s=0; //p1 score
|
|
||||||
byte p2s=0; //p2 score
|
|
||||||
byte i;
|
|
||||||
signed char p1b=7;
|
|
||||||
signed char p2b=56;
|
|
||||||
byte bs=2;
|
|
||||||
|
|
||||||
while(p1s<8 && p2s<8) {
|
int game() {
|
||||||
X+=XRC;
|
// x & y scaled by 8 zodat er interger math gedaan kan worden voor de rc
|
||||||
Y=Yo+YRC;
|
signed int X=16*8; // ball x
|
||||||
|
signed int Y=8*8; // ball y
|
||||||
|
signed int Xo=X; // ball x previous
|
||||||
|
signed int Yo=Y; // ball y previos
|
||||||
|
signed int XRC; // X direction
|
||||||
|
signed int YRC=0; // y direction
|
||||||
|
signed int p1b=300; // player 1 bat position
|
||||||
|
signed int p2b=300; // player 2 bat position
|
||||||
|
signed int p1bo=400; // player 1 bat old position
|
||||||
|
signed int p2bo=400; // player 2 bat old position
|
||||||
|
unsigned int ballspeed=80; // ball speed
|
||||||
|
byte batsize=5;
|
||||||
|
byte gamecountdown=1;
|
||||||
|
byte countdown=7;
|
||||||
|
|
||||||
if(X>231){X=231; XRC=-XRC; YRC=random(0,16);}
|
if(random(2)==1){
|
||||||
if(X<23) {
|
XRC=8;
|
||||||
if((p1b>Y-13) & (p1b<Y+13)){
|
}else{
|
||||||
X=23;
|
XRC=-8;
|
||||||
XRC=-XRC;
|
}
|
||||||
YRC=(Y-p1b)>>1;
|
YRC=random(-4,4);
|
||||||
} else {
|
|
||||||
p2s++;
|
|
||||||
delay(500);
|
|
||||||
Y=32;
|
|
||||||
X=128;
|
|
||||||
XRC=8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(Y>127) {Y=127; YRC=-YRC;}
|
|
||||||
if(Y<0) {Y=0; YRC=-YRC;}
|
|
||||||
|
|
||||||
plot(X>>3,Y>>3,1);
|
while(true) {
|
||||||
if((X>>3!=Xo>>3) | (Y>>3!=Yo>>3)) plot(Xo>>3,Yo>>3,0);
|
// pre game beeping
|
||||||
Xo=X;
|
if(gamecountdown==1){
|
||||||
Yo=Y;
|
if((millis()-prevmillis)>150){
|
||||||
|
prevmillis=millis();
|
||||||
|
if(countdown>0){
|
||||||
|
if(countdown%2==1){
|
||||||
|
plot(16,8,1);
|
||||||
|
tone(speaker,1000,10);
|
||||||
|
} else {
|
||||||
|
plot(16,8,0);
|
||||||
|
}
|
||||||
|
countdown--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(countdown==0){
|
||||||
|
tone(speaker,1400,20);
|
||||||
|
// bat(16,0,16,1);
|
||||||
|
gamecountdown=0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
// plot score
|
// ball shizzle
|
||||||
// if(p1s>0) plot(0,p1s-1,1);
|
if ((millis()-prevmillis)>ballspeed){
|
||||||
// if(p2s>0) plot(31,8-p2s,1);
|
prevmillis=millis();
|
||||||
|
X+=XRC;
|
||||||
|
Y+=YRC;
|
||||||
|
|
||||||
if(random(0,2)==1){
|
if(X>255){
|
||||||
if(random(0,50)==1) p1s++;
|
tone(speaker,100,10);
|
||||||
if(p1s>8){
|
return(1);
|
||||||
p1s=0;
|
}
|
||||||
for(i=0;i<8;i++) {plot(0,i,0);}
|
|
||||||
|
// p1 paddle check
|
||||||
|
if((X>>3) == 3) {
|
||||||
|
if(((Y>>3)>=(p1b>>3)) & ((Y>>3)<((p1b>>3)+batsize))){
|
||||||
|
tone(speaker,400,5);
|
||||||
|
XRC=-XRC;
|
||||||
|
if(ballspeed>0){
|
||||||
|
ballspeed-=5;
|
||||||
|
}
|
||||||
|
if(YRC>=0){
|
||||||
|
YRC=map(Y-p1b,0,batsize<<3,0,16);
|
||||||
|
} else {
|
||||||
|
YRC=map(Y-p1b,0,batsize<<3,-16,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// p2 paddle check
|
||||||
|
if((X>>3) == 28) {
|
||||||
|
if(((Y>>3)>=(p2b>>3)) & ((Y>>3)<((p2b>>3)+batsize))){
|
||||||
|
tone(speaker,400,5);
|
||||||
|
XRC=-XRC;
|
||||||
|
if(ballspeed>0){
|
||||||
|
ballspeed-=5;
|
||||||
|
}
|
||||||
|
if(YRC>=0){
|
||||||
|
YRC=map(Y-p2b,0,batsize<<3,0,16);
|
||||||
|
} else {
|
||||||
|
YRC=map(Y-p2b,0,batsize<<3,-16,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// p2 scores , reset ball
|
||||||
|
if(X<1){
|
||||||
|
tone(speaker,100,10);
|
||||||
|
return(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// bounce onderkant
|
||||||
|
if(Y>127) {
|
||||||
|
tone(speaker,500,1);
|
||||||
|
Y=127;
|
||||||
|
YRC=-YRC;
|
||||||
|
}
|
||||||
|
// bounce bovenkant
|
||||||
|
if(Y<0) {
|
||||||
|
tone(speaker,500,1);
|
||||||
|
Y=0;
|
||||||
|
YRC=-YRC;
|
||||||
|
}
|
||||||
|
|
||||||
|
// plot bal, en verwijder de oude
|
||||||
|
plot(X>>3,Y>>3,1);
|
||||||
|
if((X>>3!=Xo>>3) | (Y>>3!=Yo>>3)) {
|
||||||
|
plot(Xo>>3,Yo>>3,0);
|
||||||
|
Xo=X;
|
||||||
|
Yo=Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// player 1 pad
|
||||||
|
p1b=map(analogRead(p1control)>>1,0,512,0,128-((batsize-1)<<3));
|
||||||
|
if((p1b>>3)!=(p1bo>>3)){
|
||||||
|
bat(2,p1bo>>3,batsize,0);
|
||||||
|
bat(2,p1b>>3,batsize,1);
|
||||||
|
p1bo=p1b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// player 2 pad
|
||||||
|
p2b=map(analogRead(p2control)>>1,0,512,0,128-((batsize-1)<<3));
|
||||||
// for(i=0;i<8;i++) {plot(2,i,0);}
|
// p2b=0;
|
||||||
// p1b=analogRead(1)>>6;
|
if((p2b>>3)!=(p2bo>>3)){
|
||||||
|
bat(29,p2bo>>3,batsize,0);
|
||||||
// if(p1b>Y){
|
bat(29,p2b>>3,batsize,1);
|
||||||
// p1b+=bs;
|
p2bo=p2b;
|
||||||
// }else{
|
}
|
||||||
// p1b+=-bs;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if(p1b<8) {plot(2,0,1);plot(2,1,1);plot(2,2,1);p1b=7;}
|
|
||||||
// else if(p1b>55) {plot(2,5,1);plot(2,6,1);plot(2,7,1);p1b=56;}
|
|
||||||
// else {plot(2,(p1b>>3)-1,1);plot(2,(p1b>>3),1);plot(2,(p1b>>3)+1,1);}
|
|
||||||
|
|
||||||
// for(i=0;i<8;i++) {plot(29,i,0);}
|
|
||||||
// if(p2b>Y){
|
|
||||||
// p2b+=bs;
|
|
||||||
// }else{
|
|
||||||
// p2b+=-bs;
|
|
||||||
// }
|
|
||||||
// p2b=Y;
|
|
||||||
// if(p2b<8) {plot(29,0,1);plot(29,1,1);plot(29,2,1); p2b=7;}
|
|
||||||
// else if(p2b>55) {plot(29,5,1);plot(29,6,1);plot(29,7,1);p2b=56;}
|
|
||||||
// else {plot(29,(p2b>>3)-1,1);plot(29,(p2b>>3),1);plot(29,(p2b>>3)+1,1);}
|
|
||||||
delay(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(p1s==8){
|
|
||||||
showbitmap(P1WIN);
|
|
||||||
} else {
|
|
||||||
showbitmap(P2WIN);
|
|
||||||
}
|
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void test(){
|
|
||||||
plot(1,0,1);
|
|
||||||
plot(1,1,1);
|
|
||||||
plot(1,2,1);
|
|
||||||
plot(1,3,1);
|
|
||||||
plot(1,4,1);
|
|
||||||
plot(1,5,1);
|
|
||||||
plot(1,6,1);
|
|
||||||
plot(1,7,1);
|
|
||||||
plot(1,8,1);
|
|
||||||
plot(1,9,1);
|
|
||||||
plot(2,8,1);
|
|
||||||
|
|
||||||
|
void p1winanim(byte loops, int dely ){
|
||||||
|
for (loops ; loops>0 ; loops--){
|
||||||
|
for (byte offset=0;offset<8;offset+=2){
|
||||||
|
for (byte i=0;i<64;i++){
|
||||||
|
ht1632_shadowram[i]=bitmaps[WIN][(i+offset)&63];
|
||||||
|
ht1632_shadowram[i+64]=bitmaps[WIN][64+((i+offset)&63)];
|
||||||
|
}
|
||||||
|
ht1632_sendshadowram();
|
||||||
|
delay(dely);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void p2winanim(byte loops, int dely){
|
||||||
|
for (loops ; loops>0 ; loops--){
|
||||||
|
for (byte offset=8;offset>0;offset-=2){
|
||||||
|
for (byte i=0;i<64;i++){
|
||||||
|
ht1632_shadowram[i+64]=bitmaps[WIN][(i+offset)&63];
|
||||||
|
ht1632_shadowram[i]=bitmaps[WIN][64+((i+offset)&63)];
|
||||||
|
}
|
||||||
|
ht1632_sendshadowram();
|
||||||
|
delay(dely);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
|
byte p1s;
|
||||||
|
byte p2s;
|
||||||
|
p1s=0;
|
||||||
|
p2s=0;
|
||||||
|
|
||||||
showbitmap(PONG);
|
showbitmap(PONG);
|
||||||
// delay(500);
|
while(digitalRead(button)==1){
|
||||||
// showbitmap(FIVE);
|
delay(10);
|
||||||
// delay(500);
|
}
|
||||||
// showbitmap(FOUR);
|
|
||||||
// delay(500);
|
|
||||||
// showbitmap(THREE);
|
|
||||||
// delay(500);
|
while(true){
|
||||||
// showbitmap(TWO);
|
showbitmap(CLS);
|
||||||
// delay(500);
|
bat(0,0,p1s,1);
|
||||||
// showbitmap(ONE);
|
bat(0,16-p1s,p1s,1);
|
||||||
// delay(500);
|
bat(31,0,p2s,1);
|
||||||
// showbitmap(CLS);
|
bat(31,16-p2s,p2s,1);
|
||||||
// game();
|
|
||||||
// test();
|
if(game()==1){
|
||||||
}
|
p1s++;
|
||||||
|
}else{
|
||||||
|
p2s++;
|
||||||
|
}
|
||||||
|
if(p1s==9){
|
||||||
|
p1winanim(10,100);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(p2s==9){
|
||||||
|
p2winanim(10,100);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue