diff --git a/config.yml b/config.yml index c3ff9ba..445c53f 100644 --- a/config.yml +++ b/config.yml @@ -16,7 +16,6 @@ players: right: d shoot: s - # Enemies config invaders: size: 4 @@ -31,3 +30,8 @@ projectiles: torpedos: speed: 2 width: 10 + +points: + invader3: 100 + invader2: 250 + invader1: 600 \ No newline at end of file diff --git a/headers/player.h b/headers/player.h index a9fbeac..b4e905b 100644 --- a/headers/player.h +++ b/headers/player.h @@ -4,6 +4,8 @@ struct Player{ unsigned lives; unsigned x; + unsigned id; + unsigned score; }; #endif \ No newline at end of file diff --git a/headers/utils.h b/headers/utils.h index 5634574..3879830 100644 --- a/headers/utils.h +++ b/headers/utils.h @@ -3,14 +3,14 @@ #include #include -#include "position.h" +#include"position.h" // hardcoded values #define PLAYER_HEIGHT 100 #define PROJ_LENGTH_FACTOR 2 enum WinValue{ - NOBODY, // should never be used, but hey + NOBODY, // should never be used PLAYERS, INVADERS, }; @@ -22,7 +22,12 @@ typedef vector aliensLine; typedef vector aliensGrid; typedef position missile; -typedef position torpedo; + +class torpedo : public nsGraphics::Vec2D { +public: + topedo(int x, int y); + unsigned playerID; +}; // didn't want to use position because of the semantic with x and y bool lineCollideCheck(unsigned start1, unsigned end1, unsigned start2, unsigned end2); diff --git a/src/game_managers.cpp b/src/game_managers.cpp index f3e1d54..819e4b8 100644 --- a/src/game_managers.cpp +++ b/src/game_managers.cpp @@ -6,7 +6,7 @@ #define ISPRESSED(X) window.isPressed({X, false}) -void Game::managePlayerMoves(PlayerDef& pdef, unsigned& playerX){ +void Game::managePlayerMoves(PlayerDef& pdef, unsigned& playerX, unsigned playerId){ if (ISPRESSED(pdef.keys.left)){ if(playerX < confData.playersSpeed) playerX = 0; else playerX = playerX - confData.playersSpeed; @@ -16,15 +16,15 @@ void Game::managePlayerMoves(PlayerDef& pdef, unsigned& playerX){ else playerX = playerX + confData.playersSpeed; } if(ISPRESSED(pdef.keys.shoot)){ - torpedos.emplace_back(playerX + confData.playersWidth / 2, pm.getScreenHeight() - PLAYER_HEIGHT); + torpedos.emplace_back(playerX + confData.playersWidth / 2, pm.getScreenHeight() - PLAYER_HEIGHT, playerId ); } } /** Makes the players play once */ void Game::managePlayers(){ - managePlayerMoves(confData.p1Def, p1.x); - if(playMode==PlayMode::TWO_LOCAL)managePlayerMoves(confData.p2Def, p2.x); + managePlayerMoves(confData.p1Def, p1.x,p1.id); + if(playMode==PlayMode::TWO_LOCAL)managePlayerMoves(confData.p2Def, p2.x, p2.id); } /** Makes the invaders play once, and check lower bounds diff --git a/src/utils.cpp b/src/utils.cpp index b39d7ae..42910ad 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,5 +1,7 @@ #include "utils.h" +torpedo::torpedo(int x, int y) : position(x, y) {} + bool lineCollideCheck(unsigned start1, unsigned end1, unsigned start2, unsigned end2){ return start1 < end2 != start2 < end1; // if true, are colliding. I like truth tables