Settings for sound and speedup

This commit is contained in:
kg 2019-11-07 20:37:36 +01:00
parent 1c232d8998
commit 0d8e679db3
1 changed files with 20 additions and 10 deletions

View File

@ -119,12 +119,22 @@ void setup () // flow chart from page 17 of datasheet
ht1632_senddata(i, 0,ht1632_cs[j]); // clear the display! ht1632_senddata(i, 0,ht1632_cs[j]); // clear the display!
} }
randomSeed(analogRead(3)); randomSeed(analogRead(3));
sbatsize=EEPROM.read(0);
ssound=EEPROM.read(1);
sballspeed=EEPROM.read(2);
sballspeedup=EEPROM.read(3);
if(digitalRead(button)==0){ if(digitalRead(button)==0){
gamesetup(); gamesetup();
} }
} }
void sound(int freq, int duration){
if (ssound==1){
tone(speaker,freq,duration);
}
}
void plot (char x, char y, char val) void plot (char x, char y, char val)
{ {
char addr, bitval, offset; char addr, bitval, offset;
@ -199,7 +209,7 @@ int game() {
if(countdown>0){ if(countdown>0){
if(countdown%2==1){ if(countdown%2==1){
plot(16,8,1); plot(16,8,1);
tone(speaker,1000,10); sound(1000,10);
} else { } else {
plot(16,8,0); plot(16,8,0);
} }
@ -207,7 +217,7 @@ int game() {
} }
} }
if(countdown==0){ if(countdown==0){
tone(speaker,1400,20); sound(1400,20);
// bat(16,0,16,1); // bat(16,0,16,1);
gamecountdown=0; gamecountdown=0;
} }
@ -221,26 +231,26 @@ int game() {
// p1 scores // p1 scores
if(X>255){ if(X>255){
tone(speaker,100,10); sound(100,10);
return(1); return(1);
} }
// p2 scores // p2 scores
if(X<1){ if(X<1){
tone(speaker,100,10); sound(100,10);
return(2); return(2);
} }
// bounce onderkant // bounce onderkant
if(Y>127) { if(Y>127) {
tone(speaker,500,1); sound(500,1);
Y=127; Y=127;
YRC=-YRC; YRC=-YRC;
} }
// bounce bovenkant // bounce bovenkant
if(Y<0) { if(Y<0) {
tone(speaker,500,1); sound(500,1);
Y=0; Y=0;
YRC=-YRC; YRC=-YRC;
} }
@ -256,10 +266,10 @@ int game() {
// p1 paddle check // p1 paddle check
if((X>>3) == 3) { if((X>>3) == 3) {
if(((Y>>3)>=(p1b>>3)) & ((Y>>3)<((p1b>>3)+batsize))){ if(((Y>>3)>=(p1b>>3)) & ((Y>>3)<((p1b>>3)+batsize))){
tone(speaker,400,5); sound(400,5);
XRC=-XRC; XRC=-XRC;
if(ballspeed>0){ if(ballspeed>0){
ballspeed-=5; ballspeed-=sballspeedup;
} }
if(YRC>=0){ if(YRC>=0){
YRC=map(Y-p1b,0,batsize<<3,0,16); YRC=map(Y-p1b,0,batsize<<3,0,16);
@ -272,10 +282,10 @@ int game() {
// p2 paddle check // p2 paddle check
if((X>>3) == 28) { if((X>>3) == 28) {
if(((Y>>3)>=(p2b>>3)) & ((Y>>3)<((p2b>>3)+batsize))){ if(((Y>>3)>=(p2b>>3)) & ((Y>>3)<((p2b>>3)+batsize))){
tone(speaker,400,5); sound(400,5);
XRC=-XRC; XRC=-XRC;
if(ballspeed>0){ if(ballspeed>0){
ballspeed-=5; ballspeed-=sballspeedup;
} }
if(YRC>=0){ if(YRC>=0){
YRC=map(Y-p2b,0,batsize<<3,0,16); YRC=map(Y-p2b,0,batsize<<3,0,16);