Skip to content
Snippets Groups Projects
Commit 6c9715ac authored by CLEMREP's avatar CLEMREP
Browse files

:sparkles: Introduce score

parent 8a73d9ad
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,15 @@ const Sprite* getAsteroidSprite(AsteroidSize size) {
}
}
int getAsteroidScore(AsteroidSize size) {
switch (size) {
case SMALL: return 100;
case MEDIUM: return 50;
case LARGE: return 20;
default: return 0;
}
}
Asteroid::Asteroid(fp32 x, fp32 y, fp32 vx, fp32 vt, AsteroidSize size)
: Entity(x, y, vx, vt, getAsteroidRadius(size)),
size(size) {}
......
......@@ -4,7 +4,8 @@
#define ASTEROID_H
#include "Entity.h"
#include "Game.h"
#include "Set.h"
#include "Bullet.h"
#include "drivers/sprite.h"
enum AsteroidSize {
......@@ -15,6 +16,7 @@ enum AsteroidSize {
int32_t getAsteroidRadius(AsteroidSize size);
const Sprite* getAsteroidSprite(AsteroidSize size);
int getAsteroidScore(AsteroidSize size);
class Asteroid : public Entity {
private:
......
......@@ -145,7 +145,6 @@ void Game::render() {
}
renderScoreboard();
}
void Game::drawEntity(Entity* entity) {
......@@ -167,6 +166,11 @@ void Game::drawEntity(Entity* entity) {
// drawHitbox(position, entity->getRadius(), 0xFF);
}
void Game::updateScore(AsteroidSize size) {
score += getAsteroidScore(size);
updateScoreboard();
}
void Game::update() {
handleInput();
......@@ -207,6 +211,9 @@ void Game::update() {
Asteroid* asteroid = static_cast<Asteroid*>(asteroids.get(j));
Bullet* bullet = static_cast<Bullet*>(bullets.get(i));
asteroid->handleCollision(asteroids, bullets, bullet);
updateScore(asteroid->getSize());
--i;
break;
}
......
......@@ -7,6 +7,7 @@
#include "Set.h"
#include "utils.h"
#include "physics/Physics.h"
#include "Asteroid.h"
#define GAME_WIDTH 320
#define GAME_HEIGHT 180
......@@ -37,6 +38,7 @@ public:
void render();
void handleInput();
void renderScoreboard();
void updateScore(AsteroidSize size);
void updateScoreboard();
void drawHitbox(const Vec2& position, int32_t radius, unsigned char color);
void drawEntity(Entity* entity);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment