From bad10aea4d3b5988ccaee04ccc65a53a3a6455e2 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 26 Dec 2021 20:17:36 +0100 Subject: [PATCH] piew piew (from player only, fuck you invaders, also torpedos are invisibles) --- headers/config.h | 1 + headers/game.h | 3 ++- headers/{pixelManager.h => pixel_manager.h} | 4 ++-- src/config.cpp | 3 ++- src/game_basics.cpp | 5 ++++- src/game_managers.cpp | 12 +++++++++++- src/main.cpp | 12 +++++++++++- src/{pixelManager.cpp => pixel_manager.cpp} | 6 ++---- 8 files changed, 35 insertions(+), 11 deletions(-) rename headers/{pixelManager.h => pixel_manager.h} (93%) rename src/{pixelManager.cpp => pixel_manager.cpp} (95%) diff --git a/headers/config.h b/headers/config.h index 884a3c7..40af069 100644 --- a/headers/config.h +++ b/headers/config.h @@ -20,6 +20,7 @@ public: unsigned player_width; unsigned alien_speed; + unsigned player_speed; bool loadConfig(); }; diff --git a/headers/game.h b/headers/game.h index f6bf4aa..5492985 100644 --- a/headers/game.h +++ b/headers/game.h @@ -2,7 +2,7 @@ #define GUARD_GAME_H #include #include "mingl/mingl.h" -#include "pixelManager.h" +#include "pixel_manager.h" #include "config.h" #include "utils.h" #include "position.h" @@ -11,6 +11,7 @@ using namespace std; class Game { private: + MinGL window; PixelManager pm; Config conf; diff --git a/headers/pixelManager.h b/headers/pixel_manager.h similarity index 93% rename from headers/pixelManager.h rename to headers/pixel_manager.h index c468611..8b86229 100644 --- a/headers/pixelManager.h +++ b/headers/pixel_manager.h @@ -9,8 +9,8 @@ class PixelManager{ public: - MinGL window; - PixelManager(); + MinGL& window; + explicit PixelManager(MinGL&); void dessinerInvader1(const nsGraphics::Vec2D& baseVector, unsigned size); void dessinerInvader2(const nsGraphics::Vec2D& baseVector, unsigned size); void dessinerInvader3(const nsGraphics::Vec2D& baseVector, unsigned size); diff --git a/src/config.cpp b/src/config.cpp index d465a20..23755fb 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -10,13 +10,14 @@ bool Config::loadConfig() { alien_size = 20; distance = 5; alien_speed = 1; + player_speed = 2; missile_width = 10; missile_length = 15; torpedo_width = 10; torpedo_length = 15; - player_width = 50; + player_width = 1000; return true; } diff --git a/src/game_basics.cpp b/src/game_basics.cpp index cfc650c..b11916a 100644 --- a/src/game_basics.cpp +++ b/src/game_basics.cpp @@ -2,7 +2,10 @@ #include #include "game.h" -Game::Game() { +#define WININIT window("space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack) + + +Game::Game() : WININIT, pm(window) { conf.loadConfig(); } diff --git a/src/game_managers.cpp b/src/game_managers.cpp index 87ace81..605d2bc 100644 --- a/src/game_managers.cpp +++ b/src/game_managers.cpp @@ -7,7 +7,17 @@ /** Makes the player play once */ void Game::managePlayer(){ - + if (window.isPressed({'q', false})){ + if(playerX < conf.player_speed) playerX = 0; + else playerX = playerX-conf.player_speed; + } + if (window.isPressed({'d', false})){ + if(playerX+conf.player_speed>=pm.getScreenWidth()) playerX = pm.getScreenWidth()-1; + else playerX = playerX+conf.player_speed; + } + if(window.isPressed({' ', false})){ + torpedos.emplace_back(playerX+conf.player_width/2, pm.getScreenHeight()-PLAYER_HEIGHT); + } } /** Makes the invaders play once, and check lower bounds diff --git a/src/main.cpp b/src/main.cpp index 33ebaf7..80d72a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,8 +2,18 @@ #include "game.h" using namespace std; +#define C "space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack + +class Test{ +public: + MinGL a; + PixelManager pm; + Test() : a(C), pm(a) { + } +}; + int main(){ - Game g; + Game g; g.managedGames(); return 0; diff --git a/src/pixelManager.cpp b/src/pixel_manager.cpp similarity index 95% rename from src/pixelManager.cpp rename to src/pixel_manager.cpp index 0f2d230..c28d4dc 100644 --- a/src/pixelManager.cpp +++ b/src/pixel_manager.cpp @@ -1,9 +1,7 @@ -#include "pixelManager.h" +#include "pixel_manager.h" #include "utils.h" -#define WININIT window("space invader du turfu ma gueule", nsGraphics::Vec2D(1280, 720), nsGraphics::Vec2D(128, 128), nsGraphics::KBlack) - -PixelManager::PixelManager() : WININIT { +PixelManager::PixelManager(MinGL& a) : window(a) { window.initGlut(); window.initGraphic(); }