aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-03 22:32:32 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-03 22:32:32 +0100
commit3d3f0107b7b328a9a68159edc7890cc43aa34926 (patch)
treee2d80aeb851803b159a34b7ae85a161b65527b3f
parentballs move yknow (diff)
downloadthreshold-3d3f0107b7b328a9a68159edc7890cc43aa34926.tar.gz
threshold-3d3f0107b7b328a9a68159edc7890cc43aa34926.tar.bz2
threshold-3d3f0107b7b328a9a68159edc7890cc43aa34926.tar.xz
threshold-3d3f0107b7b328a9a68159edc7890cc43aa34926.tar.zst
threshold-3d3f0107b7b328a9a68159edc7890cc43aa34926.zip
move to entity and add player
-rw-r--r--src/entity.cpp16
-rw-r--r--src/entity.hpp15
-rw-r--r--src/gameplay.cpp19
-rw-r--r--src/gameplay.hpp23
4 files changed, 40 insertions, 33 deletions
diff --git a/src/entity.cpp b/src/entity.cpp
new file mode 100644
index 0000000..af93f36
--- /dev/null
+++ b/src/entity.cpp
@@ -0,0 +1,16 @@
+#include "enemy.hpp"
+
+Entity::Entity(void)
+{
+ posX = GetRandomValue(0, SCREENWIDTH);
+ posY = GetRandomValue(0, SCREENHEIGHT);
+ 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/entity.hpp b/src/entity.hpp
new file mode 100644
index 0000000..49d98b6
--- /dev/null
+++ b/src/entity.hpp
@@ -0,0 +1,15 @@
+#ifndef ENEMY_H_
+#define ENEMY_H_
+
+#include "window.hpp"
+
+class Entity {
+ public:
+ float posX;
+ float posY;
+ Vector2 direction;
+ Entity();
+ ~Entity();
+};
+
+#endif // ENEMY_H_
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 56429d9..260ddde 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -3,27 +3,18 @@
#include <iostream>
-Enemy::Enemy(void)
+Game::~Game()
{
- posX = GetRandomValue(0, SCREENWIDTH);
- posY = GetRandomValue(0, SCREENHEIGHT);
- if (static_cast<int>(posX) & 1)
- {
- direction = (Vector2){posX / 100, -posY / 100};
- } else {
- direction = (Vector2){-posX / 100, posY / 100};
- }
-
+ delete enemies;
+ delete player;
}
-Enemy::~Enemy() {}
-Game::~Game() {}
-
Game::Game(void)
{
nEnemies = GetRandomValue(5, 15);
- enemies = new std::vector<Enemy>(nEnemies);
+ enemies = new std::vector<Entity>(nEnemies);
+ player = new Entity;
}
void Game::start() const
diff --git a/src/gameplay.hpp b/src/gameplay.hpp
index 3dc6b27..151b591 100644
--- a/src/gameplay.hpp
+++ b/src/gameplay.hpp
@@ -2,31 +2,16 @@
#define GAMEPLAY_H_
#include "window.hpp"
+#include "entity.hpp"
#include <vector>
-class Enemy {
- public:
- float posX;
- float posY;
- Vector2 direction;
- Enemy();
- ~Enemy();
-};
-
-class Player {
- public:
- float posX;
- float posY;
- Vector2 direction;
- Player();
- ~Player();
-};
-
class Game {
int nEnemies;
- std::vector<Enemy> * enemies;
+ std::vector<Entity> * enemies;
+
+ Entity * player;
public:
Game();