Skip to content

Commit f9bf6ad

Browse files
committed
Fixed log spawning issue.
Made collisions with logs a little more forgiving.
1 parent b44cea7 commit f9bf6ad

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

game.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#define MAX_VELOCITY 300
2020

2121
#define SCROLL_SPEED 30
22-
#define LOG_SPAWN_GAP 100
23-
#define LOG_MIN_GAP 60
22+
#define LOG_SPAWN_GAP 110
23+
#define LOG_MIN_GAP 55
2424

2525
#define GAP_SIZE 3
2626

@@ -64,6 +64,7 @@ int localHighscore = 0;
6464
float offset = 0;
6565

6666
int treeNumber = 0;
67+
int treeGap = 0;
6768

6869
Squirrel player;
6970
std::vector<Log> logs;
@@ -88,12 +89,13 @@ float max(float a, float b) {
8889

8990
Log generate_log() {
9091
treeNumber++;
92+
treeGap += max(LOG_SPAWN_GAP - treeNumber * 2, LOG_MIN_GAP);
9193

9294
Log log;
9395

9496
log.gapPosition = (rand() % ((SCREEN_HEIGHT / SPRITE_SIZE) - (GAP_SIZE * 2))) + GAP_SIZE;
9597

96-
log.xPosition = (1 + treeNumber) * max(LOG_SPAWN_GAP - treeNumber * 2, LOG_MIN_GAP);//SCREEN_WIDTH + SPRITE_SIZE;
98+
log.xPosition = treeGap;
9799

98100
log.passed = false;
99101

@@ -181,6 +183,7 @@ void start_game() {
181183
player.onGround = false;
182184
offset = 0;
183185
treeNumber = 0;
186+
treeGap = SCREEN_WIDTH / 2;
184187
logs.clear();
185188
logs.push_back(generate_log());
186189
}
@@ -301,7 +304,7 @@ void update(uint32_t time) {
301304
player.score++;
302305
}
303306

304-
if ((logs.at(i).xPosition - SPRITE_SIZE - offset) < (PLAYER_X + SPRITE_SIZE / 2) && (logs.at(i).xPosition + SPRITE_SIZE - offset) > (PLAYER_X - SPRITE_SIZE / 2)) {
307+
if ((logs.at(i).xPosition - SPRITE_SIZE - offset) < (PLAYER_X + SPRITE_SIZE / 2) && (logs.at(i).xPosition + SPRITE_SIZE - offset - TOLERANCE) > (PLAYER_X - SPRITE_SIZE / 2)) {
305308
if (get_min_y(logs.at(i).gapPosition) - TOLERANCE < (player.yPosition - SPRITE_SIZE / 2) && get_max_y(logs.at(i).gapPosition) + TOLERANCE > (player.yPosition + SPRITE_SIZE / 2)) {
306309

307310
}

metadata.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ splash:
55
file: assets/image.png
66
icon:
77
file: assets/icon.png
8-
version: v1.0.1
8+
version: v1.1.0
99

0 commit comments

Comments
 (0)