debut de systeme de score, reste plus qu'a 1. lire le score depuis la config, et 2 ajouter le score au joueur associer lorsque sa torpille collide avec un invader

This commit is contained in:
Djalim Simaila 2021-12-31 18:50:08 +01:00
parent 3d9c50bf6e
commit 07da695d88
5 changed files with 21 additions and 8 deletions

View File

@ -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

View File

@ -4,6 +4,8 @@
struct Player{
unsigned lives;
unsigned x;
unsigned id;
unsigned score;
};
#endif

View File

@ -3,14 +3,14 @@
#include<vector>
#include<mingl/mingl.h>
#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<Alien> aliensLine;
typedef vector<aliensLine> 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);

View File

@ -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

View File

@ -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