aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/maps/map.h0
-rw-r--r--meta/maps/stage_1_start.bfm2
-rw-r--r--src/entity.hpp2
-rw-r--r--src/gameplay.cpp91
-rw-r--r--src/gameplay.hpp4
-rw-r--r--src/main.cpp1
-rw-r--r--src/map.hpp28
7 files changed, 85 insertions, 43 deletions
diff --git a/meta/maps/map.h b/meta/maps/map.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/meta/maps/map.h
diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm
index 167d83b..bfae4e5 100644
--- a/meta/maps/stage_1_start.bfm
+++ b/meta/maps/stage_1_start.bfm
@@ -1,5 +1,5 @@
BOSS 0 0
-ENEMIES 20 20
+MINIONS 20 20
WAVES 2 10
NEXT stage_1_1.bfm
BACKGROUND ../meta/media/sprites/stage_1_regbg.png
diff --git a/src/entity.hpp b/src/entity.hpp
index cd92ef9..32c1fd0 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -14,6 +14,8 @@
#include <map>
#include "weapon.hpp"
+#define MINION_SPEED 2.1f
+
class Entity {
public:
int hp;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 3dfdd5e..1ee867c 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -20,46 +20,51 @@
#include "wp_enemyslingshot.hpp"
#include "wp_shotty.hpp"
-Game::Game(std::string const& path) : current(path) {
+Level* Game::parse(std::string const& path) {
std::ifstream ifs(path);
std::string tok;
- auto radius = 0;
- auto ehp = 0;
+ Level* ret = new Level();
- std::cout << "Init: reading map file [" << path << "]" << std::endl;
+ std::cout << "Init: reading level.file [" << path << "]" << std::endl;
while (ifs >> tok) {
- if (tok == "ENEMIES") {
+ if (tok == "MINIONS") {
ifs >> tok;
- std::cout << "will spawn " << tok << " enemies";
- nEnemies = std::atoi(tok.c_str());
+ ret->nMinion = std::atoi(tok.c_str());
ifs >> tok;
- radius = std::atoi(tok.c_str());
+ ret->mRadius = std::atoi(tok.c_str());
}
- if (tok == "NEXT") {
+ if (tok == "BOSS") {
ifs >> tok;
- next = tok;
- std::cout << "next level is " << next;
+ ret->bHp = (tok == "0") ? 1 : 0;
+ ret->bRadius = ret->mRadius;
}
- if (tok == "BOSS") {
+ if (tok == "NEXT") {
ifs >> tok;
- ehp = (tok == "0") ? 1 : 0;
- if (ehp == 0) {
- ifs >> tok;
- ehp = std::atoi(tok.c_str());
- }
+ ret->next = tok;
+ std::cout << "next ret is " << next;
}
if (tok == "WAVES") {
ifs >> tok;
- nWaves = std::atoi(tok.c_str());
+ ret->nWaves = std::atoi(tok.c_str());
ifs >> tok;
- nPerWave = std::atoi(tok.c_str());
+ ret->nPerWave = std::atoi(tok.c_str());
}
if (tok == "BACKGROUND") {
ifs >> tok;
- background = tok;
+ ret->background = tok;
}
}
+ ret->nTotal = (ret->nBoss + ret->nGrunts + ret->nMinion);
ifs.close();
+ return (ret);
+}
+
+Game::Game(std::string const& path) : current(path) {
+ auto radius = 0;
+ auto ehp = 0;
+
+ level = parse(path);
+
enemies = new std::vector<Entity>;
InitAudioDevice();
@@ -67,7 +72,7 @@ Game::Game(std::string const& path) : current(path) {
AWeapon* ar = new wp_assaultrifle(AR_BANG, SHOTTY_RELOAD);
AWeapon* sling = new wp_enemysling(SHOTTY_BANG, SHOTTY_RELOAD);
- for (auto i = 0; i < nPerWave; i++) {
+ for (auto i = 0; i < level->nTotal; i++) {
if (ehp == 1) {
Entity en(ehp);
en.radius = radius;
@@ -100,17 +105,7 @@ Game::Game(std::string const& path) : current(path) {
player->wp[1] = ar;
player->currentWeapon = player->wp[0];
player->idleTex = LoadTexture(MUCHACHO_TEX);
-}
-
-Game::~Game() {
- delete enemies;
- delete player;
-}
-void Game::start() {
- std::cout << "----- Gameplay: Start -----" << std::endl;
- std::cout << "Gameplay: " << nEnemies << "enemies need to be spawned"
- << std::endl;
frameWidth = player->idleTex.width;
frameHeight = player->idleTex.height;
@@ -119,6 +114,11 @@ void Game::start() {
origin = {(float)frameWidth, (float)frameHeight};
}
+Game::~Game() {
+ delete enemies;
+ delete player;
+}
+
// draw bad boys and player
void Game::draw() {
auto left = std::to_string(enemies->size());
@@ -168,6 +168,8 @@ void Game::draw() {
// progress the game & check for player death
// NEW: go towards player NEXT: spawn at different furyTimes
int Game::tick() {
+ // player logic
+ //
auto target = GetMousePosition();
DrawTexture(crosshair, target.x, target.y, WHITE);
@@ -176,9 +178,9 @@ int Game::tick() {
player->direction = v2;
- if (player->victims == nPerWave && nWaves > 1) {
+ if (player->victims == level.nPerWave && nWaves > 1) {
nWaves--;
- for (int i = 0; i < nPerWave; i++) {
+ for (int i = 0; i < level.nPerWave; i++) {
Entity en(1);
en.radius = 20;
en.idleTex = LoadTexture(SBIRE_TEX_IDLE);
@@ -188,6 +190,12 @@ int Game::tick() {
}
}
+ //
+ // end player logic
+ // -----------------------------------
+ // baddie logic
+ //
+
for (auto en = enemies->begin(); en != enemies->end(); en++) {
if (en->hp > 0) {
if (en->posX >= SCREENWIDTH || en->posX <= 0) {
@@ -197,27 +205,30 @@ int Game::tick() {
en->direction.y = -en->direction.y;
}
if (en->posX >= player->posX) {
- en->posX -= 2.1f;
+ en->posX -= MINION_SPEED;
en->direction.x -= 0.1f;
}
if (en->posY >= player->posY) {
- en->posY -= 2.1f;
+ en->posY -= MINION_SPEED;
en->direction.y -= 0.1f;
}
if (en->posX <= player->posX) {
- en->posX += 2.1f;
+ en->posX += MINION_SPEED;
en->direction.x += 0.1f;
}
if (en->posY <= player->posY) {
- en->posY += 2.1f;
+ en->posY += MINION_SPEED;
en->direction.y += 0.1f;
}
- if ((GetRandomValue(0, 100) == 50) && // make enemy fire at random intervals
+ if ((GetRandomValue(0, 100) ==
+ 50) && // make enemy fire at random intervals
(en->currentWeapon != nullptr)) {
en->currentWeapon->bang(enemies, &(*en));
nEnemies++;
- return (0); // NOTE: this return is here to make sure that we don't run into a segfault if
- // adding an enemy to the vector reallocs and invalidates the iterator.
+ return (
+ 0); // NOTE: this return is here to make sure that we don't
+ // run into a segfault if adding an enemy to the vector
+ // in case it reallocs and invalidates the iterator.
}
} else {
if (en->posX >= SCREENWIDTH || en->posX <= 0 ||
diff --git a/src/gameplay.hpp b/src/gameplay.hpp
index f82121d..be07491 100644
--- a/src/gameplay.hpp
+++ b/src/gameplay.hpp
@@ -10,6 +10,7 @@
#define GAMEPLAY_H_
#include "entity.hpp"
+#include "map.hpp"
#include "terrain.hpp"
#include "window.hpp"
@@ -60,6 +61,7 @@ class Game {
std::string next; // next level
std::string current; // next level
std::string background; // next level
+ Level* level;
int frameWidth;
int frameHeight;
@@ -74,7 +76,7 @@ class Game {
Game(std::string const& path);
~Game();
- void start();
+ Level* parse(std::string const& path);
void draw();
int tick();
int getKeys();
diff --git a/src/main.cpp b/src/main.cpp
index ffa7e30..cb0894e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -56,7 +56,6 @@ int main(void) {
game = new Game(s);
background = LoadTexture(game->getBackground().c_str());
gs = GAMEPLAY;
- game->start();
}
if (IsKeyPressed(KEY_DOWN) && nPick < (pick.size() - 1)) {
nPick++;
diff --git a/src/map.hpp b/src/map.hpp
new file mode 100644
index 0000000..f1fc2a7
--- /dev/null
+++ b/src/map.hpp
@@ -0,0 +1,28 @@
+#ifndef MAP_H
+#define MAP_H
+
+#include <iostream>
+
+typedef struct Level {
+ int nPerWave;
+ int nWaves;
+ int nTotal;
+
+ int nGrunts;
+ int gRadius;
+ int gHp;
+
+ int nBoss;
+ int bRadius;
+ int bHp;
+
+ int nMinion;
+ int mRadius;
+ int mHp;
+
+ std::string next; // next level
+ std::string current; // next level
+ std::string background; // next level
+} Level;
+
+#endif /* MAP_H */