Repository navigation
Addressing PR comments #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dfc5d19
6b70e5f
2aaf887
5747b13
15c47a6
c70ae53
d721906
a80bbf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,63 +15,44 @@ int origYV=-1; | |
| byte scoreBreakout = 0; | ||
|
|
||
| bool outOfBounds(int xV, int yV) { | ||
| return (xV > 8 || xV < 0 || yV > 8 || yV < 0); | ||
| return (xV >= 8 || xV < 0 || yV >= 8 || yV < 0); | ||
| } | ||
|
|
||
| // Helper: checks if a position is free (LOW) and in bounds | ||
| inline bool isFree(int x, int y) { | ||
| return !outOfBounds(x, y) && gamer.display[x][y] == LOW; | ||
| } | ||
|
|
||
| void physics() { | ||
| if(gamer.display[currentXBreakout+velocity[0]][currentYBreakout+velocity[1]]==HIGH || outOfBounds(currentXBreakout+velocity[0],currentYBreakout+velocity[1])) { | ||
| //Collided with something!!! | ||
| int nextX = currentXBreakout + velocity[0]; | ||
| int nextY = currentYBreakout + velocity[1]; | ||
|
|
||
| // Check if we hit something at the next position | ||
| if(outOfBounds(nextX, nextY) || gamer.display[nextX][nextY] == HIGH) { | ||
| // Collision detected! | ||
|
Comment on lines
+30
to
+32
|
||
| startLEDFlash(); | ||
| if(soundEnabled) { | ||
| if(currentYBreakout==6) { | ||
| gamer.playTone(NOTE_C8); | ||
| } | ||
| else { | ||
| gamer.playTone(NOTE_E8); | ||
| } | ||
| gamer.playTone((currentYBreakout == 6) ? NOTE_C8 : NOTE_E8); | ||
| } | ||
| if(velocity[0]==1) { | ||
| if(velocity[1]==1) { | ||
| if(gamer.display[currentXBreakout+velocity[0]][currentYBreakout-1]==LOW && !outOfBounds(currentXBreakout+velocity[0],currentYBreakout-1)) { | ||
| velocity[1]=-1; | ||
| } | ||
| else if(gamer.display[currentXBreakout-1][currentYBreakout-1]==LOW && !outOfBounds(currentXBreakout-1,currentYBreakout-1)) { | ||
| velocity[1]=-1; | ||
| velocity[0]=-1; | ||
| } | ||
| } | ||
| else if(velocity[1]==-1) { | ||
| if(gamer.display[currentXBreakout+velocity[0]][currentYBreakout+1]==LOW && !outOfBounds(currentXBreakout+velocity[0],currentYBreakout+1)) { | ||
| velocity[1]=1; | ||
| } | ||
| else if(gamer.display[currentXBreakout-1][currentYBreakout+1]==LOW && !outOfBounds(currentXBreakout-1,currentYBreakout+1)) { | ||
| velocity[1]=1; | ||
| velocity[0]=-1; | ||
| } | ||
| } | ||
| } | ||
| else if(velocity[0]==-1) { | ||
| if(velocity[1]==1) { | ||
| if(gamer.display[currentXBreakout+velocity[0]][currentYBreakout-1]==LOW && !outOfBounds(currentXBreakout+velocity[0],currentYBreakout-1)) { | ||
| velocity[1]=-1; | ||
| } | ||
| else if(gamer.display[currentXBreakout+1][currentYBreakout-1]==LOW && !outOfBounds(currentXBreakout-1,currentYBreakout-1)) { | ||
| velocity[1]=-1; | ||
| velocity[0]=1; | ||
| } | ||
| } | ||
| else if(velocity[1]==-1) { | ||
| if(gamer.display[currentXBreakout+velocity[0]][currentYBreakout+1]==LOW && !outOfBounds(currentXBreakout+velocity[0],currentYBreakout+1)) { | ||
| velocity[1]=1; | ||
| } | ||
| else if(gamer.display[currentXBreakout+1][currentYBreakout+1]==LOW && !outOfBounds(currentXBreakout-1,currentYBreakout+1)) { | ||
| velocity[1]=1; | ||
| velocity[0]=1; | ||
| } | ||
| } | ||
|
|
||
| // Try to bounce off edges intelligently | ||
| // Check if we can bounce just horizontally or just vertically | ||
| bool canBounceY = isFree(nextX, currentYBreakout - velocity[1]); | ||
| bool canBounceX = isFree(currentXBreakout - velocity[0], nextY); | ||
|
|
||
| if(canBounceY) { | ||
| velocity[1] *= -1; // Bounce vertically | ||
| } else if(canBounceX) { | ||
| velocity[0] *= -1; // Bounce horizontally | ||
| } else { | ||
| // Corner hit - bounce both directions | ||
| velocity[0] *= -1; | ||
| velocity[1] *= -1; | ||
| } | ||
| if(!outOfBounds(currentXBreakout+origXV,currentYBreakout+origYV)) { | ||
| blocks[currentXBreakout+origXV][currentYBreakout+origYV]=0; | ||
|
|
||
| // Clear the block we hit (if in bounds) | ||
| if(!outOfBounds(currentXBreakout + origXV, currentYBreakout + origYV)) { | ||
| blocks[currentXBreakout + origXV][currentYBreakout + origYV] = 0; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -106,9 +87,7 @@ void startBreakoutReset() { | |
| } | ||
|
|
||
| void breakoutLoop() { | ||
| checkSoundToggle(); | ||
| updateLEDFlash(); | ||
| if(soundEnabled) gamer.stopTone(); | ||
| updateGameInput(); | ||
| if(breakoutCounter>2) { | ||
| for(byte x=0;x<8;x++) { | ||
| for(byte y=0;y<8;y++) { | ||
|
|
@@ -142,42 +121,14 @@ void breakoutLoop() { | |
| } | ||
| } | ||
| physics(); | ||
| // Propagate block destruction to adjacent blocks in a checkerboard pattern | ||
| for(byte x=0;x<8;x++) { | ||
| for(byte y=0;y<8;y++) { | ||
| if(blocks[x][y]==0) { | ||
| if(x%2==0) { | ||
| if(y%2==0) { | ||
| if(x<7) { | ||
| blocks[x+1][y]=0; | ||
| } else { | ||
| blocks[0][y]=0; | ||
| } | ||
| } | ||
| else { | ||
| if(x>0) { | ||
| blocks[x-1][y]=0; | ||
| } else { | ||
| blocks[7][y]=0; | ||
| } | ||
| } | ||
| } | ||
| else { | ||
| if(y%2==0) { | ||
| if(x>0) { | ||
| blocks[x-1][y]=0; | ||
| } else { | ||
| blocks[7][y]=0; | ||
| } | ||
| } | ||
| else { | ||
| if(x<7) { | ||
| blocks[x+1][y]=0; | ||
| } else { | ||
| blocks[0][y]=0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // Determine adjacent block based on checkerboard pattern | ||
| byte adjX = ((x % 2) == (y % 2)) ? ((x < 7) ? x + 1 : 0) : ((x > 0) ? x - 1 : 7); | ||
| blocks[adjX][y] = 0; | ||
| } | ||
| } | ||
| } | ||
| for(byte x=0;x<8;x++) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.