piew piew (from player only, fuck you invaders, also torpedos are invisibles)

This commit is contained in:
Thomas 2021-12-26 20:17:36 +01:00
parent 9e74ca9ecd
commit bad10aea4d
No known key found for this signature in database
GPG Key ID: E538821A6CDFDAD7
8 changed files with 35 additions and 11 deletions

View File

@ -20,6 +20,7 @@ public:
unsigned player_width; unsigned player_width;
unsigned alien_speed; unsigned alien_speed;
unsigned player_speed;
bool loadConfig(); bool loadConfig();
}; };

View File

@ -2,7 +2,7 @@
#define GUARD_GAME_H #define GUARD_GAME_H
#include <vector> #include <vector>
#include "mingl/mingl.h" #include "mingl/mingl.h"
#include "pixelManager.h" #include "pixel_manager.h"
#include "config.h" #include "config.h"
#include "utils.h" #include "utils.h"
#include "position.h" #include "position.h"
@ -11,6 +11,7 @@ using namespace std;
class Game { class Game {
private: private:
MinGL window;
PixelManager pm; PixelManager pm;
Config conf; Config conf;

View File

@ -9,8 +9,8 @@
class PixelManager{ class PixelManager{
public: public:
MinGL window; MinGL& window;
PixelManager(); explicit PixelManager(MinGL&);
void dessinerInvader1(const nsGraphics::Vec2D& baseVector, unsigned size); void dessinerInvader1(const nsGraphics::Vec2D& baseVector, unsigned size);
void dessinerInvader2(const nsGraphics::Vec2D& baseVector, unsigned size); void dessinerInvader2(const nsGraphics::Vec2D& baseVector, unsigned size);
void dessinerInvader3(const nsGraphics::Vec2D& baseVector, unsigned size); void dessinerInvader3(const nsGraphics::Vec2D& baseVector, unsigned size);

View File

@ -10,13 +10,14 @@ bool Config::loadConfig() {
alien_size = 20; alien_size = 20;
distance = 5; distance = 5;
alien_speed = 1; alien_speed = 1;
player_speed = 2;
missile_width = 10; missile_width = 10;
missile_length = 15; missile_length = 15;
torpedo_width = 10; torpedo_width = 10;
torpedo_length = 15; torpedo_length = 15;
player_width = 50; player_width = 1000;
return true; return true;
} }

View File

@ -2,7 +2,10 @@
#include <thread> #include <thread>
#include "game.h" #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(); conf.loadConfig();
} }

View File

@ -7,7 +7,17 @@
/** Makes the player play once /** Makes the player play once
*/ */
void Game::managePlayer(){ 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 /** Makes the invaders play once, and check lower bounds

View File

@ -2,6 +2,16 @@
#include "game.h" #include "game.h"
using namespace std; 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(){ int main(){
Game g; Game g;
g.managedGames(); g.managedGames();

View File

@ -1,9 +1,7 @@
#include "pixelManager.h" #include "pixel_manager.h"
#include "utils.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(MinGL& a) : window(a) {
PixelManager::PixelManager() : WININIT {
window.initGlut(); window.initGlut();
window.initGraphic(); window.initGraphic();
} }