diff --git a/makefile b/makefile index cffd6c4..5f9c31b 100644 --- a/makefile +++ b/makefile @@ -2,9 +2,11 @@ CP=clang CFLAGS=$(shell cat compiler_flags.txt | tr '\n' ' ') FILES=$(wildcard src/*.cpp) -build/raylib-test-linux.x86_64 : $(FILES) - mkdir -p build - $(CP) $(FILES) $(CFLAGS) -o build/raylib-test-linux.x86_64 +.PHONY : clean cross-windows + +build/linux/raylib-test-linux.x86_64 : $(FILES) + mkdir -p build/linux + $(CP) $(FILES) $(CFLAGS) -o build/linux/raylib-test-linux.x86_64 clean : diff --git a/src/main.cpp b/src/main.cpp index d4ab187..7560f7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,5 @@ #include #include -#include "components.h" #include "world.h" #include "maploader.h" @@ -8,20 +7,20 @@ const int SCREEN_HEIGHT = 320; const int SCREEN_WIDTH = 320; int main() { - loadmap(); - return 0; - InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test game"); SetTargetFPS(60); world = create_world_with(1./10.); - world.entities.push_back(new Pacman({SCREEN_WIDTH/2,SCREEN_HEIGHT/2})); + loadmap(world); world.setup(); while (WindowShouldClose() == false) { + + if(IsKeyPressed(KEY_F1)) + world.debug = !world.debug; world.process(); diff --git a/src/maploader.cpp b/src/maploader.cpp index 5c9f491..15e7249 100644 --- a/src/maploader.cpp +++ b/src/maploader.cpp @@ -1,17 +1,47 @@ #include "maploader.h" #include #include +#include "components.h" #include "world.h" -void loadmap() { - std::ifstream input_stream; - input_stream.open("assets/map"); +void loadmap(World& world) { + std::ifstream in; + in.open("assets/map"); + + int x = 0; + int y = 0; - if(input_stream.is_open() == false) - return; - - std::cout << input_stream.getline() - - input_stream.close(); + while(in.eof() == false) + { + char c; + in.get(c); + + switch (c) { + case '#': + { + Wall* wall = new Wall; + wall->position = {(float)x*16,(float)y*16}; + world.entities.push_back(wall); + x++; + } + break; + case 'P': + { + Pacman* pacman = new Pacman; + pacman->position = {(float)x*16,(float)y*16}; + world.entities.push_back(pacman); + x++; + } + + break; + case '\n': + x = 0; + y++; + break; + default: + x++; + break; + } + } } diff --git a/src/maploader.h b/src/maploader.h index f27ac8b..61abcd0 100644 --- a/src/maploader.h +++ b/src/maploader.h @@ -1,6 +1,8 @@ #ifndef MAPLOADER_H #define MAPLOADER_H -void loadmap(); +#include "world.h" + +void loadmap(World& world); #endif diff --git a/src/components.cpp b/src/pacman.cpp similarity index 86% rename from src/components.cpp rename to src/pacman.cpp index c9d40d7..f3e2acc 100644 --- a/src/components.cpp +++ b/src/pacman.cpp @@ -71,22 +71,5 @@ void Pacman::draw() const { DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE); } -// Wall definitions - -Wall::Wall() { - this->texture = LoadTexture("assets/sprites/walls.png"); -} - -Wall::~Wall() { - UnloadTexture(this->texture); -} - -void Wall::ready() { - // Set neigbors depending on state -} - -void Wall::draw() const { - // Draw based on neighbors -} diff --git a/src/wall.cpp b/src/wall.cpp new file mode 100644 index 0000000..a71d15c --- /dev/null +++ b/src/wall.cpp @@ -0,0 +1,19 @@ +#include "components.h" +#include + +Wall::Wall() { + this->texture = LoadTexture("assets/sprites/wall.png"); +} + +Wall::~Wall() { + UnloadTexture(this->texture); +} + +void Wall::ready() { + // Set neigbors depending on state +} + +void Wall::draw() const { + // Draw based on neighbors + DrawTexture(this->texture, this->position.x, this->position.y, WHITE); +} diff --git a/src/world.cpp b/src/world.cpp index 73fc1a9..c160a71 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -5,6 +5,7 @@ World::World(){ this->entities = {}; this->seconds_per_tick = 0; this->clock = 0; + this->debug = false; } World::~World(){ @@ -21,6 +22,11 @@ void World::setup(){ void World::process(){ this->clock += GetFrameTime(); + if(IsKeyPressed(KEY_F2)) + this->seconds_per_tick-=0.025; + if(IsKeyPressed(KEY_F3)) + this->seconds_per_tick+=0.025; + this->update_grid(); for(int i = 0; i < this->entities.size(); i++) { @@ -39,6 +45,11 @@ void World::draw() const { for(int i = 0; i < this->entities.size(); i++) { this->entities[i]->draw(); } + if (this->debug == false) + return; + + DrawText(TextFormat("entities: %i",this->entities.size()), 0, 0, 14, WHITE); + DrawText(TextFormat("seconds_per_tick: %f",this->seconds_per_tick), 0, 16, 14, WHITE); } int indexify_position(Vector2 vector){ diff --git a/src/world.h b/src/world.h index 1a7ed51..bf6e754 100644 --- a/src/world.h +++ b/src/world.h @@ -13,7 +13,7 @@ class World { public: World(); ~World(); - + bool debug; std::vector entities; /// Main subjects of game world. Entity* grid[GRID_CAPACITY]; /// Grid representation float seconds_per_tick; /// Internal clock speed