diff options
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/entity.cpp | 6 | ||||
-rw-r--r-- | src/gameplay.cpp | 27 |
3 files changed, 33 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d25a131..9a600f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,11 @@ find_package(raylib 3.0 REQUIRED) # Requires at least version 3.0 set(CMAKE_C_STANDARD 11) # Requires C11 standard -add_executable(${PROJECT_NAME} src/main.cpp src/window.cpp src/gameplay.cpp) +add_executable(${PROJECT_NAME} + src/main.cpp + src/window.cpp + src/gameplay.cpp + src/entity.cpp) target_link_libraries(${PROJECT_NAME} raylib m pthread dl) diff --git a/src/entity.cpp b/src/entity.cpp index af93f36..124ac02 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -1,16 +1,14 @@ -#include "enemy.hpp" +#include "entity.hpp" Entity::Entity(void) { posX = GetRandomValue(0, SCREENWIDTH); posY = GetRandomValue(0, SCREENHEIGHT); - if (static_cast<int>(posX) & 1) - { + if (static_cast<int>(posX) & 1) { direction = (Vector2){posX / 100, -posY / 100}; } else { direction = (Vector2){-posX / 100, posY / 100}; } - } Entity::~Entity() {} diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 260ddde..3cbc17f 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -11,10 +11,16 @@ Game::~Game() Game::Game(void) { - nEnemies = GetRandomValue(5, 15); + // nEnemies = GetRandomValue(5, 15); + + enemies = 3; enemies = new std::vector<Entity>(nEnemies); player = new Entity; + player->posX = SCREENWIDTH / 2; + player->posY = SCREENHEIGHT / 2; + player->direction.x = 1; + player->direction.y = 0; } void Game::start() const @@ -29,6 +35,7 @@ void Game::draw() const { DrawCircleV((Vector2){en.posX, en.posY}, 10, RED); } + DrawCircleV((Vector2){player->posX, player->posY}, 10, GREEN); } @@ -47,8 +54,26 @@ void Game::tick() const en.posX += en.direction.x; en.posY += en.direction.y; } + player->posX += player->direction.x; + player->posY += player->direction.y; } void Game::getKeys() const { + if (IsKeyPressed(KEY_UP)) { + player->direction.x = 0; + player->direction.y = -2; + } + if (IsKeyPressed(KEY_DOWN)) { + player->direction.x = 0; + player->direction.y = 2; + } + if (IsKeyPressed(KEY_LEFT)) { + player->direction.x = -2; + player->direction.y = 0; + } + if (IsKeyPressed(KEY_RIGHT)) { + player->direction.x = 2; + player->direction.y = 0; + } } |