aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-05 21:42:26 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-05 21:42:26 +0100
commit4e266c0e8f0b49cb39f3f2c3bc43d0bc09cc3aca (patch)
treed35d35c340e63589350c351738d4af3dab68e3d8
parentterrain is fukkkkd (diff)
downloadthreshold-4e266c0e8f0b49cb39f3f2c3bc43d0bc09cc3aca.tar.gz
threshold-4e266c0e8f0b49cb39f3f2c3bc43d0bc09cc3aca.tar.bz2
threshold-4e266c0e8f0b49cb39f3f2c3bc43d0bc09cc3aca.tar.xz
threshold-4e266c0e8f0b49cb39f3f2c3bc43d0bc09cc3aca.tar.zst
threshold-4e266c0e8f0b49cb39f3f2c3bc43d0bc09cc3aca.zip
reload works
-rw-r--r--README.md11
-rw-r--r--meta/maps/stage_1_start.bfm2
-rw-r--r--src/entity.hpp3
-rw-r--r--src/gameplay.cpp23
-rw-r--r--src/terrain.cpp4
-rw-r--r--src/terrain.hpp5
-rw-r--r--src/weapon.cpp10
-rw-r--r--src/weapon.hpp3
8 files changed, 40 insertions, 21 deletions
diff --git a/README.md b/README.md
index d254c5c..448a0c8 100644
--- a/README.md
+++ b/README.md
@@ -32,3 +32,14 @@ cmake ..
- Optimizations on vectors (too many function calls)
+
+## TODO
+
+### Weapons
+- reload
+- visual representation of mag
+- more weapons (gravity gun ?)
+
+### Maps
+- more
+- terrain
diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm
index e735c3f..310eba0 100644
--- a/meta/maps/stage_1_start.bfm
+++ b/meta/maps/stage_1_start.bfm
@@ -1,2 +1,2 @@
-ENEMIES 10 20
+ENEMIES 2 20
NEXT stage_1_boss.bfm
diff --git a/src/entity.hpp b/src/entity.hpp
index dd8a810..c114ca7 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -22,7 +22,8 @@ class Entity {
bool threshold;
float posX;
float posY;
- double time;
+ double furyTime;
+ double reloadTime;
Vector2 direction;
Weapon * wp;
Image img;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index d732a48..9e37221 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -59,7 +59,6 @@ Game::~Game()
{
delete enemies;
delete player;
- delete terrain;
}
void Game::start()
@@ -87,7 +86,7 @@ void Game::draw() const
DrawCircleV((Vector2){en.posX, en.posY}, en.radius, DARKBLUE);
}
// Destination rectangle (screen rectangle where drawing part of texture)
- Rectangle destRec = { player->posX, player->posY, frameWidth * 1.4f, frameHeight * 1.4f };
+ 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);
@@ -101,7 +100,7 @@ void Game::draw() const
// progress the game & check for player death
-// NEW: go towards player NEXT: spawn at different times
+// NEW: go towards player NEXT: spawn at different furyTimes
int Game::tick() const
{
for (auto en = enemies->begin(); en != enemies->end(); en++)
@@ -170,7 +169,7 @@ int Game::getKeys() const
}
if (player->fury >= 5 &&
IsKeyDown(KEY_E)) {
- player->time = GetTime();
+ player->furyTime = GetTime();
player->threshold = true;
player->fury = 0;
@@ -192,7 +191,7 @@ int Game::getKeys() const
}
if (player->threshold)
{
- if (GetTime() >= (player->time + 5))
+ if (GetTime() >= (player->furyTime + 5))
{
player->fury = 0;
player->threshold = false;
@@ -209,6 +208,13 @@ int Game::getKeys() const
return (1);
}
}
+ if (player->wp->empty) {
+ if (GetTime() >= (player->reloadTime + 2))
+ {
+ player->wp->refill();
+ player->wp->empty = false;
+ }
+ }
aimer.x = (player->direction.x / 3);
aimer.y = (player->direction.y / 3);
DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, aimer), 5, GREEN);
@@ -225,10 +231,13 @@ Game::shoot() const
auto add1 = Vector2Add((Vector2){player->posX, player->posY}, rot1);
auto add2 = Vector2Add((Vector2){player->posX, player->posY}, rot2);
+ if (player->wp->empty == true) {
+ return (0);
+ }
if (player->wp->bang() == 1) {
+ player->wp->empty = true;
+ player->reloadTime = GetTime();
return (0);
- } else {
- player->wp->bang();
}
for (auto en = enemies->begin(); en != enemies->end(); en++)
{
diff --git a/src/terrain.cpp b/src/terrain.cpp
index 692bb97..42ee676 100644
--- a/src/terrain.cpp
+++ b/src/terrain.cpp
@@ -2,14 +2,10 @@
#include <iostream>
-#include "raylib.h"
Terrain::Terrain(int const & x, int const & y, int const & thick)
- : x(x), y(y), thick(thick)
{
- std::cout << "\ncreate new terrain with parameters :\n" << this->x << " " << this->y << " " << this->thick << std::endl;
}
Terrain::~Terrain(void) {
- std::cout << "destroy terrain\n";
}
diff --git a/src/terrain.hpp b/src/terrain.hpp
index 6d7cf7e..7c21460 100644
--- a/src/terrain.hpp
+++ b/src/terrain.hpp
@@ -3,14 +3,9 @@
class Terrain {
public:
- Terrain();
Terrain(int const & x, int const & y, int const & thick);
~Terrain();
- void draw() const ;
- int x;
- int y;
- int thick;
};
#endif // TERRAIN_H_
diff --git a/src/weapon.cpp b/src/weapon.cpp
index 3f5dcec..507c5b3 100644
--- a/src/weapon.cpp
+++ b/src/weapon.cpp
@@ -8,6 +8,8 @@
#include "weapon.hpp"
+#include <iostream>
+
Weapon::Weapon(float const & rg, unsigned int const & dmg, const char *s, const char *r) :
range(rg), damage(dmg)
{
@@ -16,24 +18,26 @@ Weapon::Weapon(float const & rg, unsigned int const & dmg, const char *s, const
reload = LoadSound(r);
SetSoundVolume(shot, 0.3f);
SetSoundVolume(reload, 0.3f);
- max = barrel = 200;
+ max = barrel = 5;
}
Weapon::~Weapon() {}
void Weapon::refill()
{
- auto time = GetTime();
+ std::cout << "reload" << std::endl;
+ PlaySound(reload);
+ barrel = max;
}
int Weapon::bang()
{
if (barrel == 0)
{
- refill();
return (1);
} else {
barrel--;
+ std::cout << "BANG : " << barrel << "shots left" << std::endl;
PlaySound(shot);
return (0);
}
diff --git a/src/weapon.hpp b/src/weapon.hpp
index 61d3ace..902b55f 100644
--- a/src/weapon.hpp
+++ b/src/weapon.hpp
@@ -18,6 +18,7 @@ class Weapon {
unsigned int barrel;
unsigned int max;
+
float const &range;
unsigned int const &damage;
@@ -27,6 +28,8 @@ public:
int bang();
void refill();
+
+ bool empty;
};
#endif // WEAPON_H_