aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--meta/media/mp3/ar_shoot.mp3bin0 -> 126463 bytes
-rw-r--r--src/entity.hpp4
-rw-r--r--src/gameplay.cpp35
-rw-r--r--src/gameplay.hpp4
-rw-r--r--src/weapon.cpp1
-rw-r--r--src/weapon.hpp3
-rw-r--r--src/wp_assaultrifle.cpp67
-rw-r--r--src/wp_assaultrifle.hpp23
-rw-r--r--src/wp_shotty.cpp4
-rw-r--r--src/wp_shotty.hpp2
11 files changed, 130 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d213ea3..025c271 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,7 @@ add_executable(${PROJECT_NAME}
src/gameplay.cpp
src/weapon.cpp
src/wp_shotty.cpp
+ src/wp_assaultrifle.cpp
src/terrain.cpp
src/entity.cpp)
diff --git a/meta/media/mp3/ar_shoot.mp3 b/meta/media/mp3/ar_shoot.mp3
new file mode 100644
index 0000000..07efa64
--- /dev/null
+++ b/meta/media/mp3/ar_shoot.mp3
Binary files differ
diff --git a/src/entity.hpp b/src/entity.hpp
index 6c803df..40818ee 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -12,6 +12,7 @@
#include "window.hpp"
#include "weapon.hpp"
+#include <map>
class Entity {
public:
@@ -25,7 +26,8 @@ class Entity {
double furyTime;
double reloadTime;
Vector2 direction;
- AWeapon * wp;
+ std::map<int, AWeapon*> wp;
+ AWeapon * currentWeapon;
Image img;
Texture2D idleTex;
Texture2D hurtTex;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index a2d306e..0fdc67c 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -14,6 +14,7 @@
#include <raylib.h>
#include "weapon.hpp"
+#include "wp_assaultrifle.hpp"
#include "wp_shotty.hpp"
Game::Game(std::string const & path) : current(path)
@@ -75,9 +76,19 @@ Game::Game(std::string const & path) : current(path)
player->radius = 10;
player->victims = 0;
player->fury = 0;
- player->wp = new wp_shotty(10, 10, 10,
+ InitAudioDevice();
+ AWeapon * shotty = new wp_shotty(
SHOTTY_BANG,
- SHOTTY_RELOAD);
+ SHOTTY_RELOAD
+ );
+ AWeapon * ar = new wp_assaultrifle(
+ AR_BANG,
+ SHOTTY_RELOAD // TODO: get sound
+ );
+
+ player->wp[0] = shotty;
+ player->wp[1] = ar;
+ player->currentWeapon = player->wp[0];
player->idleTex = LoadTexture(MUCHACHO_TEX);
}
@@ -125,7 +136,7 @@ void Game::draw() const
if (player->fury >= 5) {
DrawText("[E] FURY", SCREENWIDTH - 300, 10, 50, RED);
}
- for (auto i = 0; i < player->wp->barrel; i++) {
+ for (auto i = 0; i < player->currentWeapon->barrel; i++) {
DrawRectangle(40 + (i * 20), SCREENHEIGHT - 60, 10, 30, RED);
}
}
@@ -208,6 +219,12 @@ int Game::getKeys() const
player->threshold = true;
player->fury = 0;
}
+ if (IsKeyDown(KEY_ONE)) {
+ player->currentWeapon = player->wp[0];
+ }
+ if (IsKeyDown(KEY_TWO)) {
+ player->currentWeapon = player->wp[1];
+ }
if (IsKeyDown(KEY_LEFT)) {
player->direction = Vector2Rotate(player->direction, -0.1f); // left
}
@@ -242,11 +259,11 @@ int Game::getKeys() const
return (1);
}
}
- if (player->wp->empty) {
+ if (player->currentWeapon->empty) {
if (GetTime() >= (player->reloadTime + 2))
{
- player->wp->refill();
- player->wp->empty = false;
+ player->currentWeapon->refill();
+ player->currentWeapon->empty = false;
}
}
return (0);
@@ -257,11 +274,11 @@ int
Game::shoot() const
{
- if (player->wp->empty == true) {
+ if (player->currentWeapon->empty == true) {
return (0);
}
- player->wp->bang(enemies, player->direction, (Vector2){player->posX, player->posY}, &player->victims);
- if (player->wp->empty == true) {
+ player->currentWeapon->bang(enemies, player->direction, (Vector2){player->posX, player->posY}, &player->victims);
+ if (player->currentWeapon->empty == true) {
player->reloadTime = GetTime();
}
return (0);
diff --git a/src/gameplay.hpp b/src/gameplay.hpp
index f66e0a6..7098e1a 100644
--- a/src/gameplay.hpp
+++ b/src/gameplay.hpp
@@ -20,6 +20,10 @@
#define SHOTTY_BANG "../meta/media/mp3/shotty_shoot.mp3"
#define SHOTTY_RELOAD "../meta/media/mp3/shotty_reload.mp3"
+#define AR_BANG "../meta/media/mp3/ar_shoot.mp3"
+#define AR_RELOAD "../meta/media/mp3/shotty_reload.mp3"
+
+
// player textures
#define MUCHACHO_TEX "../meta/media/sprites/cowboy_idle.png"
diff --git a/src/weapon.cpp b/src/weapon.cpp
index f357b40..f7426d6 100644
--- a/src/weapon.cpp
+++ b/src/weapon.cpp
@@ -13,7 +13,6 @@
AWeapon::AWeapon(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);
diff --git a/src/weapon.hpp b/src/weapon.hpp
index ca03de3..cce6c50 100644
--- a/src/weapon.hpp
+++ b/src/weapon.hpp
@@ -22,6 +22,9 @@ protected:
unsigned int max;
+ double cooldown;
+ double t;
+
float const &range;
unsigned int const &damage;
diff --git a/src/wp_assaultrifle.cpp b/src/wp_assaultrifle.cpp
new file mode 100644
index 0000000..e91073b
--- /dev/null
+++ b/src/wp_assaultrifle.cpp
@@ -0,0 +1,67 @@
+#include "wp_assaultrifle.hpp"
+
+#include <iostream>
+#include <raymath.h>
+#include <raylib.h>
+
+#include "entity.hpp"
+
+wp_assaultrifle::wp_assaultrifle(const char *s, const char *r)
+ : AWeapon(100, 10, 30, s, r)
+{}
+
+
+
+int wp_assaultrifle::bang(std::vector<Entity> * enemies, Vector2 playerDirection, Vector2 playerPosition, int * victims)
+{
+ if (barrel == 0)
+ {
+ return (1);
+ } else {
+ barrel--;
+ PlaySound(shot);
+ // here
+ //
+ auto rot1 = Vector2Rotate(playerDirection, -0.2f);
+ auto rot2 = Vector2Rotate(playerDirection, 0.2f);
+
+ auto add1 = Vector2Add(playerPosition, rot1);
+ auto add2 = Vector2Add(playerPosition, rot2);
+
+ auto r = playerDirection;
+ r.x *= 2;
+ r.y *= 2;
+
+ for (auto en = enemies->begin(); en != enemies->end(); en++)
+ {
+ if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, add1, (en->radius * 2)) ||
+ CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, Vector2Add(playerPosition, r), (en->radius * 2)) ||
+ CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, add2, (en->radius * 2)))
+ { // enemy hit
+ std::cout << "hit" << std::endl;
+ en->hp--;
+ if (en->hp == 0)
+ {
+ en->direction.x = (playerDirection.x / 2);
+ en->direction.y = (playerDirection.y / 2);
+ }
+ *victims += 1;
+ }
+ }
+ // assaultrifle cone
+ DrawLineEx(playerPosition, add1, 10, ORANGE);
+ DrawLineEx(playerPosition,
+ Vector2Add(playerPosition,
+ r),
+ 10, ORANGE);
+ DrawLineEx(playerPosition, add2, 10, ORANGE);
+
+ //
+ // there
+ if (barrel == 0)
+ {
+ empty = true;
+ }
+ return (0);
+ }
+}
diff --git a/src/wp_assaultrifle.hpp b/src/wp_assaultrifle.hpp
new file mode 100644
index 0000000..2780a29
--- /dev/null
+++ b/src/wp_assaultrifle.hpp
@@ -0,0 +1,23 @@
+/*********************************/
+/* THRESHOLD ( // */
+/* rifle ( )/ */
+/* by salade )(/ */
+/* ________________ ( /) */
+/* ()__)____________))))) :^} */
+/*********************************/
+
+#ifndef WP_ASSAULTRIFLE_H_
+#define WP_ASSAULTRIFLE_H_
+
+#include "weapon.hpp"
+
+class wp_assaultrifle : public AWeapon {
+ public:
+ wp_assaultrifle(const char *s, const char *r);
+ ~wp_assaultrifle();
+
+ int bang(std::vector<Entity> * enemies, Vector2 playerDirection, Vector2 playerPosition, int * victims) ;
+};
+
+
+#endif
diff --git a/src/wp_shotty.cpp b/src/wp_shotty.cpp
index 23c1074..cdb6898 100644
--- a/src/wp_shotty.cpp
+++ b/src/wp_shotty.cpp
@@ -6,8 +6,8 @@
#include "entity.hpp"
-wp_shotty::wp_shotty(float const &rg, unsigned int const &dmg, unsigned int const & mag, const char *s, const char *r)
- : AWeapon(rg, dmg, mag, s, r)
+wp_shotty::wp_shotty(const char *s, const char *r)
+ : AWeapon(10, 10, 10, s, r)
{}
diff --git a/src/wp_shotty.hpp b/src/wp_shotty.hpp
index 8e91be5..2f9b917 100644
--- a/src/wp_shotty.hpp
+++ b/src/wp_shotty.hpp
@@ -13,7 +13,7 @@
class wp_shotty : public AWeapon {
public:
- wp_shotty(float const &rg, unsigned int const &dmg, unsigned int const & mag, const char *s, const char *r);
+ wp_shotty(const char *s, const char *r);
~wp_shotty();
int bang(std::vector<Entity> * enemies, Vector2 playerDirection, Vector2 playerPosition, int * victims) ;