Skip to content
Snippets Groups Projects
Unverified Commit 8a73d9ad authored by Clément REPEL's avatar Clément REPEL Committed by GitHub
Browse files

Merge pull request #15 from eliasmorio/asteroides-spawn

:art: implement asteroid spawn
parents 6fa84af3 70ea126a
Branches
No related tags found
No related merge requests found
...@@ -38,6 +38,15 @@ void Game::init() { ...@@ -38,6 +38,15 @@ void Game::init() {
asteroids.add(new Asteroid(FIXED(150, 1), FIXED(100, 1), FIXED(-1, -1), FIXED(3, 10), AsteroidSize::LARGE)); asteroids.add(new Asteroid(FIXED(150, 1), FIXED(100, 1), FIXED(-1, -1), FIXED(3, 10), AsteroidSize::LARGE));
asteroids.add(new Asteroid(FIXED(180, 1), FIXED(125, 1), FIXED(1, 1), FIXED(1, 1), AsteroidSize::LARGE)); asteroids.add(new Asteroid(FIXED(180, 1), FIXED(125, 1), FIXED(1, 1), FIXED(1, 1), AsteroidSize::LARGE));
const int32_t safeZoneRadius = 80;
for (int i = 0; i < asteroids.getSize(); ++i) {
while (Physics::checkCollision(playerShip->getPosition(), safeZoneRadius, asteroids.get(i)->getPosition(), asteroids.get(i)->getRadius())) {
Vec2 newPosition(FIXED(random(0, 319), 1), FIXED(random(0, 179), 1));
asteroids.get(i)->setPosition(newPosition);
}
}
score = 0; score = 0;
lives = 3; lives = 3;
level = 1; level = 1;
...@@ -155,8 +164,7 @@ void Game::drawEntity(Entity* entity) { ...@@ -155,8 +164,7 @@ void Game::drawEntity(Entity* entity) {
} else { } else {
draw_sprite(sprite->pixels, sprite->width, sprite->height, px, py); draw_sprite(sprite->pixels, sprite->width, sprite->height, px, py);
} }
// drawHitbox(position, entity->getRadius(), 0xFF);
//drawHitbox(position, entity->getRadius(), 0xFF);
} }
void Game::update() { void Game::update() {
......
...@@ -31,4 +31,11 @@ void intToStr(int num, char* str) { ...@@ -31,4 +31,11 @@ void intToStr(int num, char* str) {
str[j] = str[k]; str[j] = str[k];
str[k] = temp; str[k] = temp;
} }
}
static unsigned int seed = 12345; // Seed for the random number generator
int random(int min, int max) {
seed = (1103515245 * seed + 12345) % 2147483648; // Linear Congruential Generator
return min + (seed % (max - min + 1));
} }
\ No newline at end of file
...@@ -4,4 +4,6 @@ ...@@ -4,4 +4,6 @@
// Function to convert an integer to a string without using std library // Function to convert an integer to a string without using std library
void intToStr(int num, char* str); void intToStr(int num, char* str);
int random(int min, int max);
#endif // UTILS_H #endif // UTILS_H
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment