Win conditions
This commit is contained in:
parent
c67ddcc6d2
commit
d32fb76f86
7 changed files with 31 additions and 28 deletions
|
|
@ -66,6 +66,7 @@ class Scorepoint : public Entity {
|
|||
public:
|
||||
Scorepoint();
|
||||
void draw() const override;
|
||||
void ready() override;
|
||||
};
|
||||
|
||||
class Ghost : public Entity {
|
||||
|
|
@ -93,6 +94,7 @@ class Cherry : public Entity {
|
|||
public:
|
||||
Cherry();
|
||||
void draw() const override;
|
||||
void ready() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@ int main() {
|
|||
while (WindowShouldClose() == false) {
|
||||
|
||||
if(IsKeyPressed(KEY_F1))
|
||||
world.debug = !world.debug;
|
||||
get_world().debug = !get_world().debug;
|
||||
|
||||
world.process();
|
||||
get_world().process();
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BLACK);
|
||||
|
||||
world.draw();
|
||||
get_world().draw();
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,12 +93,18 @@ void Pacman::collision(Entity* with){
|
|||
if (score != nullptr) {
|
||||
score->queue_free();
|
||||
get_world().points+=10;
|
||||
get_world().total_scorepoints--;
|
||||
if(get_world().total_scorepoints == 0)
|
||||
get_world().win();
|
||||
}
|
||||
Cherry* cherry = dynamic_cast<Cherry*>(with);
|
||||
if (cherry != nullptr) {
|
||||
cherry->queue_free();
|
||||
get_world().points+=30;
|
||||
get_world().start_killmode();
|
||||
get_world().total_scorepoints--;
|
||||
if(get_world().total_scorepoints == 0)
|
||||
get_world().win();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ void Scorepoint::draw() const {
|
|||
DrawTextureRec(this->texture.get_texture(), this->texture.full_view(), this->position, WHITE);
|
||||
}
|
||||
|
||||
void Scorepoint::ready() {
|
||||
get_world().total_scorepoints++;
|
||||
}
|
||||
|
||||
Cherry::Cherry(){
|
||||
texture = {get_world().get_atlas(),112,16,16,16};
|
||||
}
|
||||
|
|
@ -17,3 +21,7 @@ Cherry::Cherry(){
|
|||
void Cherry::draw() const {
|
||||
DrawTextureRec(texture.get_texture(),texture.full_view(),position,WHITE);
|
||||
}
|
||||
|
||||
void Cherry::ready() {
|
||||
get_world().total_scorepoints++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,6 @@
|
|||
#include <raylib.h>
|
||||
#include <string>
|
||||
|
||||
void init_world() {
|
||||
create_world_with(1./5.);
|
||||
|
||||
World& world = get_world();
|
||||
Vector2i window_size = get_map_size("assets/map");
|
||||
|
||||
world.set_size(window_size);
|
||||
load_world(world,"assets/map");
|
||||
|
||||
world.setup();
|
||||
}
|
||||
|
||||
World::World(){
|
||||
this->entities = {};
|
||||
this->grid = new Entity*[get_capacity()];
|
||||
|
|
@ -57,12 +45,10 @@ void World::process(){
|
|||
this->seconds_per_tick-=0.025;
|
||||
if(IsKeyPressed(KEY_F3))
|
||||
this->seconds_per_tick+=0.025;
|
||||
|
||||
if(IsKeyPressed(KEY_Q))
|
||||
CloseWindow();
|
||||
|
||||
if(state != LevelState::NotFinished){
|
||||
if(IsKeyPressed(KEY_Q))
|
||||
CloseWindow();
|
||||
if(IsKeyPressed(KEY_R))
|
||||
init_world();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +101,7 @@ void World::draw() const {
|
|||
else {
|
||||
DrawText("You lost!",16,16,24,WHITE);
|
||||
}
|
||||
DrawText("q to quit, r to restart",0,40,16,WHITE);
|
||||
DrawText("q to quit",0,40,16,WHITE);
|
||||
DrawText(TextFormat("Score: %i",this->points),16,56,16,WHITE);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class World {
|
|||
int width = 0;
|
||||
int height = 0;
|
||||
int bound_offset = 1;
|
||||
int total_scorepoints = 0;
|
||||
|
||||
void setup(); /// Sets up game world.
|
||||
/// Should be called once when entites are set.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue