From a4a467cf6ee8f30d7cba5f867981846275b0e22d Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 4 Jan 2022 14:19:47 +0100 Subject: shooting is fun hahahahahaha --- src/entity.cpp | 2 +- src/entity.hpp | 1 + src/gameplay.cpp | 25 +++++++++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/entity.cpp b/src/entity.cpp index 124ac02..9f3b35f 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -1,6 +1,6 @@ #include "entity.hpp" -Entity::Entity(void) +Entity::Entity(void) : hp(1) { posX = GetRandomValue(0, SCREENWIDTH); posY = GetRandomValue(0, SCREENHEIGHT); diff --git a/src/entity.hpp b/src/entity.hpp index 49d98b6..995c0b4 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -5,6 +5,7 @@ class Entity { public: + int hp; float posX; float posY; Vector2 direction; diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 038fb2f..2a208ee 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -32,11 +32,14 @@ void Game::start() const void Game::draw() const { + auto left = std::to_string(nEnemies); for (auto & en : *enemies) { DrawCircleV((Vector2){en.posX, en.posY}, 10, RED); } DrawCircleV((Vector2){player->posX, player->posY}, 10, GREEN); + DrawText("Enemies left : ", 10, 10, 20, GREEN); + DrawText(left.c_str(), 150, 10, 20,RED); } @@ -44,16 +47,20 @@ void Game::tick() const { for (auto & en : *enemies) { - if (en.posX >= SCREENWIDTH || en.posX <= 0) - { - en.direction.x = -en.direction.x; + if (!en.hp) + { continue ; } + if (en.posX >= SCREENWIDTH || en.posX <= 0) { + en.direction.x = -en.direction.x; } - if (en.posY >= SCREENHEIGHT || en.posY <= 0) - { - en.direction.y = -en.direction.y; + if (en.posY >= SCREENHEIGHT || en.posY <= 0) { + en.direction.y = -en.direction.y; } en.posX += en.direction.x; en.posY += en.direction.y; + if (CheckCollisionCircles((Vector2){player->posX, player->posY}, 10, + (Vector2){en.posX, en.posY}, 10)) { + std::cout << "you died" << std::endl; + } } } @@ -87,7 +94,13 @@ void Game::getKeys() const player->direction = Vector2Rotate(player->direction, 0.1f); } if (IsKeyPressed(KEY_SPACE)) { + for (auto & en : *enemies) + { + if (CheckCollisionPointLine((Vector2){en.posX, en.posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20)) + std::cout << "hit enemy at " << en.posX << "|" << en.posY << std::endl; + } DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20, RED); + } if (oldX != player->posX || oldY != player->posY) { -- cgit v1.2.3