aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-04 13:35:10 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-04 13:35:10 +0100
commit08378b50cdc850ae69a96d771d53ab137be5840b (patch)
tree9fe69a10f1225fd44a7426b56c4fa6ad4d3aef8f
parentwell done soldier (diff)
downloadthreshold-08378b50cdc850ae69a96d771d53ab137be5840b.tar.gz
threshold-08378b50cdc850ae69a96d771d53ab137be5840b.tar.bz2
threshold-08378b50cdc850ae69a96d771d53ab137be5840b.tar.xz
threshold-08378b50cdc850ae69a96d771d53ab137be5840b.tar.zst
threshold-08378b50cdc850ae69a96d771d53ab137be5840b.zip
two way control. Added reticle and smaller shots
Diffstat (limited to '')
-rw-r--r--src/gameplay.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 25f63d7..038fb2f 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -4,12 +4,6 @@
#include "raymath.h"
-Game::~Game()
-{
- delete enemies;
- delete player;
-}
-
Game::Game(void)
{
// nEnemies = GetRandomValue(5, 15);
@@ -24,6 +18,12 @@ Game::Game(void)
player->direction.y = 100;
}
+Game::~Game()
+{
+ delete enemies;
+ delete player;
+}
+
void Game::start() const
{
std::cout << "----- Gameplay: Start -----" << std::endl;
@@ -55,41 +55,45 @@ void Game::tick() const
en.posX += en.direction.x;
en.posY += en.direction.y;
}
- // player->posX += player->direction.x;
- // player->posY += player->direction.y;
}
void Game::getKeys() const
{
auto oldX = 0, oldY = 0;
+ auto aimer = player->direction;
oldX = player->posX;
oldY = player->posY;
- if (IsKeyDown(KEY_UP)) {
+ if (IsKeyDown(KEY_W)) {
player->posX += 0;
player->posY += -4;
- player->direction = Vector2Rotate(player->direction, -0.1f);
}
- if (IsKeyDown(KEY_DOWN)) {
+ if (IsKeyDown(KEY_S)) {
player->posX += 0;
player->posY += 4;
- player->direction = Vector2Rotate(player->direction, 0.1f);
}
- if (IsKeyDown(KEY_LEFT)) {
+ if (IsKeyDown(KEY_A)) {
player->posX += -4;
player->posY += 0;
- player->direction = Vector2Rotate(player->direction, -0.1f);
}
- if (IsKeyDown(KEY_RIGHT)) {
+ if (IsKeyDown(KEY_D)) {
player->posX += 4;
player->posY += 0;
+ }
+ if (IsKeyDown(KEY_LEFT)) {
+ player->direction = Vector2Rotate(player->direction, -0.1f); // left
+ }
+ if (IsKeyDown(KEY_RIGHT)) {
player->direction = Vector2Rotate(player->direction, 0.1f);
}
- if (IsKeyDown(KEY_SPACE)) {
- DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 30, RED);
+ if (IsKeyPressed(KEY_SPACE)) {
+ DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20, RED);
}
if (oldX != player->posX || oldY != player->posY)
{
this->tick();
}
+ 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);
}