diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2022-01-11 16:19:57 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2022-01-11 16:19:57 +0100 |
commit | 00aaef95323c01f6575e497921595b68da52fd2f (patch) | |
tree | c568a4a6c2f140ce1e93ba6c433d0a6eb6467b67 | |
parent | cool man. death is fucked yo (diff) | |
download | threshold-00aaef95323c01f6575e497921595b68da52fd2f.tar.gz threshold-00aaef95323c01f6575e497921595b68da52fd2f.tar.bz2 threshold-00aaef95323c01f6575e497921595b68da52fd2f.tar.xz threshold-00aaef95323c01f6575e497921595b68da52fd2f.tar.zst threshold-00aaef95323c01f6575e497921595b68da52fd2f.zip |
mouselook just needed some sleep ! cool
-rw-r--r-- | meta/maps/stage_1_start.bfm | 3 | ||||
-rw-r--r-- | src/gameplay.cpp | 42 | ||||
-rw-r--r-- | src/gameplay.hpp | 16 | ||||
-rw-r--r-- | src/main.cpp | 20 |
4 files changed, 64 insertions, 17 deletions
diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm index ca380e2..601bc8f 100644 --- a/meta/maps/stage_1_start.bfm +++ b/meta/maps/stage_1_start.bfm @@ -1,3 +1,4 @@ BOSS 0 0 -ENEMIES 10 20 +ENEMIES 20 20 +WAVES 2 10 NEXT stage_1_1.bfm diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 6180ae4..d846373 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -12,8 +12,10 @@ #include <fstream> #include <iostream> #include <raylib.h> +#include <string> #include "weapon.hpp" +#include "window.hpp" #include "wp_assaultrifle.hpp" #include "wp_shotty.hpp" @@ -50,6 +52,13 @@ Game::Game(std::string const & path) : current(path) ehp = std::atoi(tok.c_str()); } } + if (tok == "WAVES") + { + ifs >> tok; + nWaves = std::atoi(tok.c_str()); + ifs >> tok; + nPerWave = std::atoi(tok.c_str()); + } } ifs.close(); enemies = new std::vector<Entity>; @@ -65,7 +74,7 @@ Game::Game(std::string const & path) : current(path) en.radius = radius; en.idleTex = LoadTexture(SBIRE_TEX_IDLE); en.hurtTex = LoadTexture(SBIRE_TEX_HURT); - enemies->push_back(en); + enemies->push_back(en); // legacy code. TODO: remove } } player = new Entity; @@ -77,6 +86,11 @@ Game::Game(std::string const & path) : current(path) player->victims = 0; player->fury = 0; InitAudioDevice(); + + cam.target = (Vector2){player->posX, player->posY}; + cam.offset = (Vector2){SCREENWIDTH / 2.0f, SCREENHEIGHT / 2.0f}; + cam.rotation = 0.0f; + cam.zoom = 1.0f; AWeapon * shotty = new wp_shotty( SHOTTY_BANG, SHOTTY_RELOAD @@ -111,10 +125,12 @@ void Game::start() } // draw bad boys and player -void Game::draw() const +void Game::draw() { auto left = std::to_string(enemies->size()); + cam.target.x = player->posX; + EndMode2D(); auto texSize = (enemies->at(0).radius / 40.0f); for (auto & en : *enemies) { @@ -139,13 +155,35 @@ void Game::draw() const for (auto i = 0; i < player->currentWeapon->barrel; i++) { DrawRectangle(40 + (i * 20), SCREENHEIGHT - 60, 10, 30, RED); } + } +int Game::getDiff(Vector2 pos, Vector2 tip, Vector2 target) const +{ + if(((tip.x-pos.x)*(target.y-pos.y)-(tip.y-pos.y)*(target.x-pos.x))<0) + return -1; + if(((tip.x-pos.x)*(target.y-pos.y)-(tip.y-pos.y)*(target.x-pos.x))>0) + return 1; + + return 0; +} // progress the game & check for player death // NEW: go towards player NEXT: spawn at different furyTimes int Game::tick() const { + auto target = GetMousePosition(); + + DrawLine(player->posX, player->posY, target.x, target.y, RAYWHITE); + + + auto v2 = (Vector2){target.x - player->posX, target.y - player->posY}; + + DrawText(std::to_string(v2.x).c_str(), 1400, 10, 20, RED); + DrawText(std::to_string(v2.y).c_str(), 1400, 30, 20, RED); + + player->direction = v2; + for (auto en = enemies->begin(); en != enemies->end(); en++) { if (en->hp > 0) diff --git a/src/gameplay.hpp b/src/gameplay.hpp index 7098e1a..17a17f4 100644 --- a/src/gameplay.hpp +++ b/src/gameplay.hpp @@ -13,6 +13,7 @@ #include "window.hpp" #include "entity.hpp" +#include <raylib.h> #include <vector> #include <iostream> @@ -34,9 +35,15 @@ // TODO: boss textures #define COOLPURPLE CLITERAL(Color){ 170, 153, 255, 255 } // cool Purple -//rgb(170,153,255) + class Game { int nEnemies; // number of enemies on given level + int nWaves; // number of waves in level + int nPerWave; // number of enemies per wave. + + // NOTE : maps are assumed to be correct. tyhus, no + // checks are made to verify their integrity. + // having wrong maps can (and probably will) result in a crash std::vector<Entity> * enemies; @@ -47,7 +54,6 @@ class Game { std::string next; // next level std::string current; // next level - Camera2D * camera; int frameWidth; int frameHeight; @@ -60,13 +66,17 @@ class Game { Game(std::string const &path); ~Game(); + Camera2D cam; + void start() ; - void draw() const; + void draw() ; int tick() const; int getKeys() const; int shoot() const; int hit(Entity en, Vector2 add1, Vector2 add2) const ; + int getDiff(Vector2 pos, Vector2 tip, Vector2 target) const ; + std::string const &getNext() const; // returns next level's string std::string const &getCurrent() const; // returns next level's string }; diff --git a/src/main.cpp b/src/main.cpp index 24916f1..a2f616d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,18 +69,14 @@ int main(void) { } case (DEATH): { - std::string current; - if (game != nullptr) - { - current = game->getCurrent(); + if (IsKeyPressed(KEY_ENTER)) { + auto current = game->getCurrent(); + delete game; + CloseAudioDevice(); + game = new Game(current); + gs = GAMEPLAY; } - - if (IsKeyPressed(KEY_ENTER)) { - CloseAudioDevice(); - game = new Game(current); - gs = GAMEPLAY; - } break ; } case (GAMEPLAY): @@ -121,6 +117,7 @@ int main(void) { ClearBackground(COOLPURPLE); + switch (gs) { case (TITLE): { @@ -153,6 +150,7 @@ int main(void) { DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); DrawText("YOU DIED", (SCREENWIDTH / 2) - 200, (SCREENHEIGHT / 2) - 50, 40, WHITE); DrawText(game->getCurrent().c_str(), (SCREENWIDTH / 2) - 100, (SCREENHEIGHT / 2) + 50, 40, WHITE); + break ; } case (GAMEPLAY): { @@ -162,6 +160,7 @@ int main(void) { else if (code == 2) // level end {gs = NEXT;} } + BeginMode2D(game->cam); game->draw(); break ; } @@ -182,7 +181,6 @@ int main(void) { } EndDrawing(); } - EndMode2D(); CloseWindow(); return 0; } |