aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/maps/stage_1_boss.bfm3
-rw-r--r--meta/maps/stage_1_start.bfm3
-rw-r--r--meta/media/sprites/sbire_hurt.pngbin0 -> 3517 bytes
-rw-r--r--meta/media/sprites/sbire_idle.pngbin0 -> 2748 bytes
-rw-r--r--src/entity.cpp8
-rw-r--r--src/entity.hpp4
-rw-r--r--src/gameplay.cpp97
-rw-r--r--src/gameplay.hpp14
-rw-r--r--src/main.cpp9
-rw-r--r--src/weapon.cpp6
-rw-r--r--src/weapon.hpp2
-rw-r--r--src/window.cpp1
12 files changed, 99 insertions, 48 deletions
diff --git a/meta/maps/stage_1_boss.bfm b/meta/maps/stage_1_boss.bfm
index 470fd66..13ca9e7 100644
--- a/meta/maps/stage_1_boss.bfm
+++ b/meta/maps/stage_1_boss.bfm
@@ -1,2 +1,3 @@
+BOSS 1 5
ENEMIES 2 100
-NEXT 0
+NEXT stage_1_boss.bfm
diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm
index e17c49c..b5ae8e0 100644
--- a/meta/maps/stage_1_start.bfm
+++ b/meta/maps/stage_1_start.bfm
@@ -1,2 +1,3 @@
-ENEMIES 15 20
+BOSS 0 0
+ENEMIES 10 20
NEXT stage_1_boss.bfm
diff --git a/meta/media/sprites/sbire_hurt.png b/meta/media/sprites/sbire_hurt.png
new file mode 100644
index 0000000..4ded272
--- /dev/null
+++ b/meta/media/sprites/sbire_hurt.png
Binary files differ
diff --git a/meta/media/sprites/sbire_idle.png b/meta/media/sprites/sbire_idle.png
new file mode 100644
index 0000000..375dc7a
--- /dev/null
+++ b/meta/media/sprites/sbire_idle.png
Binary files differ
diff --git a/src/entity.cpp b/src/entity.cpp
index 3b21557..eda350f 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -8,7 +8,10 @@
#include "entity.hpp"
-Entity::Entity(void) : hp(1)
+Entity::Entity()
+: Entity(1) {}
+
+Entity::Entity(int const & h) : hp(h)
{
auto dir = GetRandomValue(0, 3);
@@ -40,8 +43,7 @@ Entity::Entity(void) : hp(1)
}
}
- direction = (Vector2){0.02f, 0.02f};
- radius = 10; // default radius. this is changed later
+ direction = (Vector2){0.02f, 0.0f};
threshold = false;
}
diff --git a/src/entity.hpp b/src/entity.hpp
index c114ca7..a38edcf 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -27,9 +27,11 @@ class Entity {
Vector2 direction;
Weapon * wp;
Image img;
- Texture2D tex;
+ Texture2D idleTex;
+ Texture2D hurtTex;
Entity();
+ Entity(int const & h);
~Entity();
};
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index bce787b..dbfd4af 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -10,14 +10,16 @@
#include "raymath.h"
#include <fstream>
+#include <raylib.h>
#include "weapon.hpp"
-Game::Game(std::string const & path)
+Game::Game(std::string const & path) : current(path)
{
std::ifstream ifs(path);
std::string tok;
- auto radius = 10;
+ auto radius = 0;
+ auto ehp = 0;
std::cout << "Init: reading map file [" << path << "]" << std::endl;
while (ifs >> tok)
@@ -36,23 +38,45 @@ Game::Game(std::string const & path)
next = tok;
std::cout << "next level is " << next;
}
+ if (tok == "BOSS")
+ {
+ ifs >> tok;
+ ehp = (tok == "0") ? 1 : 0;
+ if (ehp == 0) {
+ ifs >> tok;
+ ehp = std::atoi(tok.c_str());
+ }
+ }
}
ifs.close();
- enemies = new std::vector<Entity>(nEnemies);
- for (auto en = enemies->begin(); en != enemies->end(); en++) {
- en->radius = radius;
+ enemies = new std::vector<Entity>;
+ for (auto i = 0; i < nEnemies; i++) {
+ if (ehp == 0) {
+ Entity en(ehp);
+ en.radius = radius;
+ en.idleTex = LoadTexture(SBIRE_TEX_IDLE);
+ en.hurtTex = LoadTexture(SBIRE_TEX_HURT);
+ enemies->push_back(en);
+ } else {
+ Entity en(ehp);
+ en.radius = radius;
+ en.idleTex = LoadTexture(SBIRE_TEX_IDLE);
+ en.hurtTex = LoadTexture(SBIRE_TEX_HURT);
+ enemies->push_back(en);
+ }
}
player = new Entity;
player->posX = 0;
player->posY = SCREENHEIGHT / 2.0f;
player->direction.x = 100;
- player->direction.y = 100;
+ player->direction.y = 0;
player->radius = 10;
player->victims = 0;
player->fury = 0;
- player->wp = new Weapon(10, 10,
- "../meta/media/mp3/shotty_shoot.mp3",
- "../meta/media/mp3/shotty_reload.mp3");
+ player->wp = new Weapon(10, 10, 10,
+ SHOTTY_BANG,
+ SHOTTY_RELOAD);
+ player->idleTex = LoadTexture(MUCHACHO_TEX);
}
Game::~Game()
@@ -63,11 +87,10 @@ Game::~Game()
void Game::start()
{
- player->tex = LoadTexture("../meta/media/sprites/cowboy_idle.png");
std::cout << "----- Gameplay: Start -----" << std::endl;
std::cout << "Gameplay: " << nEnemies << "enemies need to be spawned" << std::endl;
- frameWidth = player->tex.width;
- frameHeight = player->tex.height;
+ frameWidth = player->idleTex.width;
+ frameHeight = player->idleTex.height;
sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight };
@@ -79,17 +102,20 @@ void Game::draw() const
{
auto left = std::to_string(enemies->size());
- ClearBackground(COOLPURPLE);
-
+ auto texSize = (enemies->at(0).radius / 40.0f);
for (auto & en : *enemies)
{
- DrawCircleV((Vector2){en.posX, en.posY}, en.radius, DARKBLUE);
+ if (en.hp == 0)
+ DrawTextureEx(en.hurtTex, (Vector2){en.posX - 20, en.posY - 20}, 1.0f, 0.6f, WHITE);
+ else {
+ DrawTextureEx(en.idleTex, (Vector2){en.posX - 20, en.posY - 20}, 1.0f, 0.6f, WHITE);
+ }
}
// Destination rectangle (screen rectangle where drawing part of texture)
Rectangle destRec = { player->posX, player->posY, frameWidth * 1.8f, frameHeight * 1.8f };
// Origin of the texture (rotation/scale point), it's relative to destination rectangle size
- DrawTexturePro(player->tex, sourceRec, destRec, origin, Vector2Angle((Vector2){0.0f, 0.0f}, player->direction), WHITE);
+ DrawTexturePro(player->idleTex, sourceRec, destRec, origin, Vector2Angle((Vector2){0.0f, 0.0f}, player->direction), WHITE);
DrawText("Enemies left : ", 10, 10, 20, GREEN);
DrawText(left.c_str(), 150, 10, 20, RED);
@@ -108,7 +134,7 @@ int Game::tick() const
{
for (auto en = enemies->begin(); en != enemies->end(); en++)
{
- if (en->hp != 0)
+ if (en->hp > 0)
{
if (en->posX >= SCREENWIDTH || en->posX <= 0) {
en->direction.x = -en->direction.x;
@@ -144,7 +170,7 @@ int Game::tick() const
if (en->hp != 0 && // check for player death (one shot one kill)
CheckCollisionCircles((Vector2){player->posX, player->posY}, 10,
(Vector2){en->posX, en->posY}, 40)) {
- return (1);
+ return (1);
}
}
return (0);
@@ -249,20 +275,23 @@ Game::shoot() const
CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, r), (en->radius * 2)) ||
CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add2, (en->radius * 2)))
{ // enemy hit
- en->hp = 0;
- en->direction.x = player->direction.x;
- en->direction.y = player->direction.y;
- player->victims++;
- player->fury++;
- DrawLineEx((Vector2){player->posX, player->posY}, add1, 10,
- ORANGE);
- DrawLineEx((Vector2){player->posX, player->posY},
- Vector2Add((Vector2){player->posX, player->posY},
- r),
- 10, ORANGE);
- DrawLineEx((Vector2){player->posX, player->posY}, add2, 10,
- ORANGE);
- return (1);
+ en->hp--;
+ if (en->hp == 0)
+ {
+ en->direction.x = (player->direction.x / 2);
+ en->direction.y = (player->direction.y / 2);
+ player->victims++;
+ }
+ player->fury++;
+ DrawLineEx((Vector2){player->posX, player->posY}, add1, 10,
+ ORANGE);
+ DrawLineEx((Vector2){player->posX, player->posY},
+ Vector2Add((Vector2){player->posX, player->posY},
+ r),
+ 10, ORANGE);
+ DrawLineEx((Vector2){player->posX, player->posY}, add2, 10,
+ ORANGE);
+ return (1);
}
}
// shotty cone
@@ -278,3 +307,7 @@ Game::shoot() const
std::string const &
Game::getNext() const
{return next;}
+
+std::string const &
+Game::getCurrent() const
+{return current;}
diff --git a/src/gameplay.hpp b/src/gameplay.hpp
index 6720560..f66e0a6 100644
--- a/src/gameplay.hpp
+++ b/src/gameplay.hpp
@@ -16,6 +16,18 @@
#include <vector>
#include <iostream>
+// sound defines
+#define SHOTTY_BANG "../meta/media/mp3/shotty_shoot.mp3"
+#define SHOTTY_RELOAD "../meta/media/mp3/shotty_reload.mp3"
+
+// player textures
+#define MUCHACHO_TEX "../meta/media/sprites/cowboy_idle.png"
+
+// bad boy textures
+#define SBIRE_TEX_IDLE "../meta/media/sprites/sbire_idle.png"
+#define SBIRE_TEX_HURT "../meta/media/sprites/sbire_hurt.png"
+
+// TODO: boss textures
#define COOLPURPLE CLITERAL(Color){ 170, 153, 255, 255 } // cool Purple
//rgb(170,153,255)
@@ -29,6 +41,7 @@ class Game {
Entity * player;
std::string next; // next level
+ std::string current; // next level
Camera2D * camera;
@@ -51,6 +64,7 @@ class Game {
int hit(Entity en, Vector2 add1, Vector2 add2) const ;
std::string const &getNext() const; // returns next level's string
+ std::string const &getCurrent() const; // returns next level's string
};
#endif // GAMEPLAY_H_
diff --git a/src/main.cpp b/src/main.cpp
index d014fdb..a24657d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -13,12 +13,13 @@
gameState gs = TITLE;
-Game* game = new Game("../meta/maps/stage_1_start.bfm");
int main(void) {
initWindow();
// Main game loop
+ InitWindow(SCREENWIDTH, SCREENHEIGHT, "WIP -- coolspace");
+ Game* game = new Game("../meta/maps/stage_1_boss.bfm");
while (!WindowShouldClose()) /* Detect window close button or ESC key */
{
switch (gs) {
@@ -56,12 +57,10 @@ int main(void) {
if (IsKeyPressed(KEY_ENTER))
{
gs = TITLE;
- auto next = game->getNext();
+ auto current = game->getCurrent();
delete game;
CloseAudioDevice();
- if (next != "0") {
- game = new Game("../meta/maps/stage_1_start.bfm");
- }
+ game = new Game(current);
}
break ;
}
diff --git a/src/weapon.cpp b/src/weapon.cpp
index ad94605..62e6150 100644
--- a/src/weapon.cpp
+++ b/src/weapon.cpp
@@ -10,15 +10,15 @@
#include <iostream>
-Weapon::Weapon(float const & rg, unsigned int const & dmg, const char *s, const char *r) :
- range(rg), damage(dmg)
+Weapon::Weapon(float const & rg, unsigned int const & dmg, unsigned int const & mag, const char *s, const char *r) :
+ range(rg), damage(dmg), max(mag)
{
InitAudioDevice();
shot = LoadSound(s);
reload = LoadSound(r);
SetSoundVolume(shot, 0.3f);
SetSoundVolume(reload, 0.3f);
- max = barrel = 10;
+ barrel = max;
}
Weapon::~Weapon() {}
diff --git a/src/weapon.hpp b/src/weapon.hpp
index f117230..1f4393d 100644
--- a/src/weapon.hpp
+++ b/src/weapon.hpp
@@ -22,7 +22,7 @@ class Weapon {
unsigned int const &damage;
public:
- Weapon(float const &rg, unsigned int const &dmg, const char *s, const char *r);
+ Weapon(float const &rg, unsigned int const &dmg, unsigned int const & mag, const char *s, const char *r);
~Weapon();
int bang();
diff --git a/src/window.cpp b/src/window.cpp
index b3b8a8e..bc78427 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -11,7 +11,6 @@
int
initWindow(void) {
// Initialization
- InitWindow(SCREENWIDTH, SCREENHEIGHT, "WIP -- coolspace");
SetTargetFPS(60);
return (0);