Compare commits

..

2 commits

Author SHA1 Message Date
a5882211a9 I'm tired 2026-03-15 01:05:05 +05:00
d32fb76f86 Win conditions 2026-03-15 00:47:21 +05:00
8 changed files with 45 additions and 32 deletions

View file

@ -1,22 +1,22 @@
############################ ############################
# ## # # ## #
# #### ##### ## ##### #### # # #### ##### ## ##### #### #
#C#### ##### ## ##### ####C# #C#__# #___# ## #___# #__#C#
# #### ##### ## ##### #### # # #### ##### ## ##### #### #
# # # #
# #### ## ######## ## #### # # #### ## ######## ## #### #
# #### ## ######## ## #### # # #### ## ######## ## #### #
# ## ## ## # # ## ## ## #
###### ##### ## ##### ###### ###### ##### ## ##### ######
###### ##### ## ##### ###### _____# ##### ## ##### #_____
###### ## ## ###### _____# ## ## #_____
###### ## #++# ## ###### _____# ## #++# ## #_____
###### ## #__# ## ###### ###### ## #__# ## ######
- #GG# - - #GG# -
###### ## #GG# ## ###### ###### ## #GG# ## ######
###### ## #### ## ###### _____# ## #### ## #_____
###### ## ## ###### _____# ## ## #_____
###### ## ######## ## ###### _____# ## ######## ## #_____
###### ## ######## ## ###### ###### ## ######## ## ######
# ## # # ## #
# #### ##### ## ##### #### # # #### ##### ## ##### #### #

View file

@ -66,6 +66,7 @@ class Scorepoint : public Entity {
public: public:
Scorepoint(); Scorepoint();
void draw() const override; void draw() const override;
void ready() override;
}; };
class Ghost : public Entity { class Ghost : public Entity {
@ -78,7 +79,7 @@ class Ghost : public Entity {
Vector2 start_position; Vector2 start_position;
int respawn_timer = 0; int respawn_timer = 0;
void recalculate_direction(); void recalculate_direction();
void try_to_chase(); void try_switch_direction();
public: public:
Ghost(); Ghost();
void ready() override; void ready() override;
@ -93,6 +94,7 @@ class Cherry : public Entity {
public: public:
Cherry(); Cherry();
void draw() const override; void draw() const override;
void ready() override;
}; };
#endif #endif

View file

@ -30,7 +30,6 @@ void Ghost::ready() {
} }
void Ghost::tick() { void Ghost::tick() {
try_to_chase();
Vector2 check_position = project_position(direction, 1); Vector2 check_position = project_position(direction, 1);
World& world = get_world(); World& world = get_world();
@ -46,10 +45,21 @@ void Ghost::tick() {
} }
position = check_position; position = check_position;
try_switch_direction();
} }
void Ghost::try_to_chase(){ void Ghost::try_switch_direction(){
// Todo /*if(rand()%10!=0)
return;
World world = get_world();
if(dynamic_cast<GhostWall*>(world.grid[world.indexify_position(project_position((direction+1)%4, 1))]) == nullptr){
direction = (direction+1)%4;
}
else if(dynamic_cast<GhostWall*>(world.grid[world.indexify_position(project_position((direction-1)%4,1))]) == nullptr){
direction = (direction-1)%4;
}*/
} }
void Ghost::recalculate_direction(){ void Ghost::recalculate_direction(){

View file

@ -21,15 +21,15 @@ int main() {
while (WindowShouldClose() == false) { while (WindowShouldClose() == false) {
if(IsKeyPressed(KEY_F1)) if(IsKeyPressed(KEY_F1))
world.debug = !world.debug; get_world().debug = !get_world().debug;
world.process(); get_world().process();
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
world.draw(); get_world().draw();
EndDrawing(); EndDrawing();
} }

View file

@ -93,12 +93,18 @@ void Pacman::collision(Entity* with){
if (score != nullptr) { if (score != nullptr) {
score->queue_free(); score->queue_free();
get_world().points+=10; get_world().points+=10;
get_world().total_scorepoints--;
if(get_world().total_scorepoints == 0)
get_world().win();
} }
Cherry* cherry = dynamic_cast<Cherry*>(with); Cherry* cherry = dynamic_cast<Cherry*>(with);
if (cherry != nullptr) { if (cherry != nullptr) {
cherry->queue_free(); cherry->queue_free();
get_world().points+=30; get_world().points+=30;
get_world().start_killmode(); get_world().start_killmode();
get_world().total_scorepoints--;
if(get_world().total_scorepoints == 0)
get_world().win();
} }
} }

View file

@ -10,6 +10,10 @@ void Scorepoint::draw() const {
DrawTextureRec(this->texture.get_texture(), this->texture.full_view(), this->position, WHITE); DrawTextureRec(this->texture.get_texture(), this->texture.full_view(), this->position, WHITE);
} }
void Scorepoint::ready() {
get_world().total_scorepoints++;
}
Cherry::Cherry(){ Cherry::Cherry(){
texture = {get_world().get_atlas(),112,16,16,16}; texture = {get_world().get_atlas(),112,16,16,16};
} }
@ -17,3 +21,7 @@ Cherry::Cherry(){
void Cherry::draw() const { void Cherry::draw() const {
DrawTextureRec(texture.get_texture(),texture.full_view(),position,WHITE); DrawTextureRec(texture.get_texture(),texture.full_view(),position,WHITE);
} }
void Cherry::ready() {
get_world().total_scorepoints++;
}

View file

@ -4,18 +4,6 @@
#include <raylib.h> #include <raylib.h>
#include <string> #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(){ World::World(){
this->entities = {}; this->entities = {};
this->grid = new Entity*[get_capacity()]; this->grid = new Entity*[get_capacity()];
@ -57,12 +45,10 @@ void World::process(){
this->seconds_per_tick-=0.025; this->seconds_per_tick-=0.025;
if(IsKeyPressed(KEY_F3)) if(IsKeyPressed(KEY_F3))
this->seconds_per_tick+=0.025; this->seconds_per_tick+=0.025;
if(IsKeyPressed(KEY_Q))
CloseWindow();
if(state != LevelState::NotFinished){ if(state != LevelState::NotFinished){
if(IsKeyPressed(KEY_Q))
CloseWindow();
if(IsKeyPressed(KEY_R))
init_world();
return; return;
} }
@ -115,7 +101,7 @@ void World::draw() const {
else { else {
DrawText("You lost!",16,16,24,WHITE); 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); DrawText(TextFormat("Score: %i",this->points),16,56,16,WHITE);
} }

View file

@ -33,6 +33,7 @@ class World {
int width = 0; int width = 0;
int height = 0; int height = 0;
int bound_offset = 1; int bound_offset = 1;
int total_scorepoints = 0;
void setup(); /// Sets up game world. void setup(); /// Sets up game world.
/// Should be called once when entites are set. /// Should be called once when entites are set.