diff options
| author | Preston Pan <preston@nullring.xyz> | 2023-02-06 23:59:58 -0800 |
|---|---|---|
| committer | Preston Pan <preston@nullring.xyz> | 2023-02-06 23:59:58 -0800 |
| commit | e092bb5586904e525b7c8860efb3e6b4f4dc7d34 (patch) | |
| tree | 595fb2907c333f814bf3891085f7aa2e79444cc6 | |
| parent | 2b2ec2f98948f2b9e98913a057c33b179632319e (diff) | |
fixed stupid bug that someone wrote
| -rw-r--r-- | snake.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -191,19 +191,22 @@ int main(int argc, char **argv) { } /* move the food */ while(1) { + uint8 overlap = 0; foodPos = init_vector(1 + (rand() % (boardSize - 2)), 1 + (rand() % (boardSize - 2))); /* if food overlaps snake or obstacles, try again */ for(int i = 0; i < snakePositions.length; i++) { if((snakePositions.vectors[i].mx == foodPos.mx) && (snakePositions.vectors[i].my == foodPos.my)) { - continue; + overlap = 1; } } for(int i = 0; i < obstaclePositions.length; i++) { if((obstaclePositions.vectors[i].mx == foodPos.mx) && (obstaclePositions.vectors[i].my == foodPos.my)) { - continue; + overlap = 1; } } + if(!overlap) { break; + } } } /* move the snake */ |
