God beta (quite cool)
This commit is contained in:
parent
bc03a21b2e
commit
1af32bafd8
@ -1,4 +1,4 @@
|
|||||||
nom du joueur ecran 100*100 sans efacé le reste
|
nom du joueur ecran 100*100 sans effacer le reste
|
||||||
le joueur est gros
|
le joueur est gros
|
||||||
basevector a change en variable x
|
basevector a change en variable x
|
||||||
projectile style fusée
|
projectile style fusée
|
||||||
|
16
config.yml
16
config.yml
@ -19,9 +19,9 @@ players:
|
|||||||
|
|
||||||
# Enemies config
|
# Enemies config
|
||||||
invaders:
|
invaders:
|
||||||
fireCooldown: 0
|
fireCooldown: 20
|
||||||
size: 40
|
size: 25
|
||||||
speed: 10
|
speed: 2
|
||||||
distance: 10 # distance in pixels between invaders
|
distance: 10 # distance in pixels between invaders
|
||||||
|
|
||||||
typeA:
|
typeA:
|
||||||
@ -39,14 +39,16 @@ invaders:
|
|||||||
projectiles:
|
projectiles:
|
||||||
missiles:
|
missiles:
|
||||||
color: yellow
|
color: yellow
|
||||||
speed: 100
|
speed: 10
|
||||||
width: 10
|
width: 10
|
||||||
torpedos:
|
torpedos:
|
||||||
color: green
|
color: green
|
||||||
speed: 10
|
speed: 10
|
||||||
width: 10
|
width: 10
|
||||||
|
|
||||||
|
# Grid definition
|
||||||
|
# You can add more rows, make rows longer and add spaces
|
||||||
grid:
|
grid:
|
||||||
- "AAAAAAAA"
|
- "AAAAAAAAAAAA"
|
||||||
# - "B BBBBBBBB"
|
- "BBBBBBBBBBBB"
|
||||||
# - " CCCCCCCC"
|
- "CCCCCCCCCCCC"
|
||||||
|
@ -29,12 +29,14 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// we do not use a Position because it is used for pixel X and Y
|
// we do not use a Position because it is used for pixel X and Y
|
||||||
unsigned throwedInvPosX;
|
unsigned thrownInvPosX;
|
||||||
unsigned throwedInvPosY;
|
unsigned thrownInvPosY;
|
||||||
InvaderType thrownInvType;
|
InvaderType thrownInvType;
|
||||||
Position thrownVector;
|
Position thrownVector;
|
||||||
Position thrownTransition;
|
Position thrownTransition;
|
||||||
|
|
||||||
|
Position getLeftHandPos(unsigned screenWidth) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,10 +59,10 @@ public:
|
|||||||
void askPlayerNameMenu(playerID pID, string& name) const;
|
void askPlayerNameMenu(playerID pID, string& name) const;
|
||||||
|
|
||||||
// y will be negative sometimes, so not unsigned
|
// y will be negative sometimes, so not unsigned
|
||||||
void displayGodBench(int y) const;
|
void drawGodBench(int y) const;
|
||||||
|
|
||||||
void displayGodRightHand(const Position& pos, bool closed=false) const;
|
void drawGodRightHand(const Position& pos, bool closed= false) const;
|
||||||
void displayGodLeftHand(const Position& pos, bool closed=false) const;
|
void drawGodLeftHand(const Position& pos, bool closed= false) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Explanation for choices :
|
// Explanation for choices :
|
||||||
|
@ -34,10 +34,13 @@ public:
|
|||||||
size_t getOutterInvader() const;
|
size_t getOutterInvader() const;
|
||||||
};
|
};
|
||||||
typedef vector<InvadersColumn> InvadersGrid;
|
typedef vector<InvadersColumn> InvadersGrid;
|
||||||
typedef nsGraphics::Vec2D Position; // in case we need to ad dmore methods, we defined our own type
|
typedef nsGraphics::Vec2D Position; // TODO replace with Vec2D ?
|
||||||
typedef unsigned playerID; // 0 for player 1, 1 for player 2
|
typedef unsigned playerID; // 0 for player 1, 1 for player 2
|
||||||
|
|
||||||
// didn't want to use Position because of the semantic with x and y
|
// didn't want to use Position because of the semantic with x and y
|
||||||
bool areLinesColliding(unsigned start1, unsigned end1, unsigned start2, unsigned end2);
|
bool areLinesColliding(unsigned start1, unsigned end1, unsigned start2, unsigned end2);
|
||||||
|
|
||||||
|
// change draw position for a specified size (keeps the same center)
|
||||||
|
void applyTransformation(Position& pos, unsigned sizeFrom, unsigned sizeTo);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -64,45 +64,67 @@ void Game::displayGod() const {
|
|||||||
return;
|
return;
|
||||||
case GodState::AWAKE: {
|
case GodState::AWAKE: {
|
||||||
unsigned dividedCounter = god.counter/1;
|
unsigned dividedCounter = god.counter/1;
|
||||||
pm.displayGodBench(dividedCounter - GOD_BENCH_SIZE);
|
pm.drawGodBench(dividedCounter - GOD_BENCH_SIZE);
|
||||||
|
|
||||||
Position leftHand(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, dividedCounter-GOD_BENCH_SIZE);
|
Position leftHand(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, dividedCounter-GOD_BENCH_SIZE);
|
||||||
Position rightHand(GOD_HAND_DISTANCE, dividedCounter-GOD_BENCH_SIZE);
|
Position rightHand(GOD_HAND_DISTANCE, dividedCounter-GOD_BENCH_SIZE);
|
||||||
pm.displayGodLeftHand(leftHand);
|
pm.drawGodLeftHand(leftHand);
|
||||||
pm.displayGodRightHand(rightHand);
|
pm.drawGodRightHand(rightHand);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::WAIT:{
|
case GodState::WAIT:{
|
||||||
pm.displayGodBench(0);
|
pm.drawGodBench(0);
|
||||||
|
|
||||||
Position leftHand(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
|
Position leftHand(GOD_HAND_DISTANCE, 0);
|
||||||
Position rightHand(GOD_HAND_DISTANCE, 0);
|
Position rightHand(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
|
||||||
pm.displayGodLeftHand(leftHand);
|
pm.drawGodLeftHand(leftHand);
|
||||||
pm.displayGodRightHand(rightHand);
|
pm.drawGodRightHand(rightHand);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::RETRIEVE1:
|
case GodState::RETRIEVE1:
|
||||||
case GodState::RETRIEVE2:{
|
case GodState::RETRIEVE2:{
|
||||||
// Bezier curve
|
// Bezier curve
|
||||||
// counter goes [0-100]
|
// counter goes [0-100]
|
||||||
pm.displayGodBench(0);
|
pm.drawGodBench(0);
|
||||||
|
pm.drawGodLeftHand(Position(GOD_HAND_DISTANCE, 0));
|
||||||
|
|
||||||
Position pos(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
|
Position pos(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
|
||||||
Position endPos = invIndexToPos(god.throwedInvPosX, god.throwedInvPosY);
|
Position endPos = invIndexToPos(god.thrownInvPosX, god.thrownInvPosY);
|
||||||
|
|
||||||
applyBezier(pos, god.thrownTransition, god.counter / 100.0);
|
applyBezier(pos, god.thrownTransition, god.counter / 100.0);
|
||||||
applyBezier(pos, endPos, god.counter / 100.0);
|
applyBezier(pos, endPos, god.counter / 100.0);
|
||||||
cout << pos << endl;
|
|
||||||
|
|
||||||
// pos is now the position we need to draw our hand to
|
// pos is now the position we need to draw our hand to
|
||||||
pm.displayGodLeftHand(Position(GOD_HAND_DISTANCE, 0));
|
pm.drawGodRightHand(pos);
|
||||||
pm.displayGodRightHand(pos);
|
// TODO remove "closed" arg
|
||||||
if(god.state==GodState::RETRIEVE2){
|
if(god.state==GodState::RETRIEVE2){
|
||||||
// TODO maybe a little transition to pos to better reflect the invader's position ?
|
pos+=Position(GOD_HAND_SIZE/2, GOD_HAND_SIZE/2);
|
||||||
|
pos-=Position(confData.invadersSize/2, confData.invadersSize/2);
|
||||||
displayInvader(pos, god.thrownInvType);
|
displayInvader(pos, god.thrownInvType);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case GodState::THROW:{
|
case GodState::THROW:{
|
||||||
|
pm.drawGodBench(0);
|
||||||
|
pm.drawGodLeftHand(Position(GOD_HAND_DISTANCE, 0));
|
||||||
|
|
||||||
|
// compute start position (not sure if we should store it or compute it each time ?)
|
||||||
|
Position handPos = god.getLeftHandPos(pm.getScreenWidth());
|
||||||
|
|
||||||
|
Position invaderPos = handPos;
|
||||||
|
applyTransformation(invaderPos, GOD_HAND_SIZE, confData.invadersSize);
|
||||||
|
Position a = god.thrownVector * (god.counter / 100.0);
|
||||||
|
invaderPos = invaderPos + a;
|
||||||
|
|
||||||
|
displayInvader(invaderPos, god.thrownInvType);
|
||||||
|
if(god.counter>60){
|
||||||
|
// handling hand retraction
|
||||||
|
unsigned handCounter;
|
||||||
|
if(god.counter>30)handCounter = 30-god.counter;
|
||||||
|
else handCounter = god.counter;
|
||||||
|
handPos = handPos + god.thrownVector * (handCounter / 100.0);
|
||||||
|
pm.drawGodRightHand(handPos);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,12 +84,13 @@ WinValue Game::playGame(){ // returns when game is finished
|
|||||||
basePos = Position(200, 0);
|
basePos = Position(200, 0);
|
||||||
// GAMELOOP
|
// GAMELOOP
|
||||||
|
|
||||||
#define MAX_FPS 60
|
const int MAX_FPS = 60;
|
||||||
|
|
||||||
chrono::milliseconds fpsTime;
|
chrono::milliseconds fpsTime;
|
||||||
unsigned tmpFps = 0;
|
unsigned tmpFps = 0;
|
||||||
unsigned fps = 0;
|
unsigned fps = 0;
|
||||||
while(window.isOpen()){
|
while(window.isOpen()){
|
||||||
|
|
||||||
chrono::time_point startTime = chrono::high_resolution_clock::now();
|
chrono::time_point startTime = chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
pm.startFrame();
|
pm.startFrame();
|
||||||
|
@ -5,51 +5,105 @@ void Game::awakeGod() {
|
|||||||
god.state = GodState::AWAKE;
|
god.state = GodState::AWAKE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::manageGod(){
|
void Game::manageGod() {
|
||||||
switch(god.state){
|
switch (god.state) {
|
||||||
case GodState::NONE:{
|
case GodState::NONE: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::AWAKE:{
|
case GodState::AWAKE: {
|
||||||
if(god.counter==GOD_BENCH_SIZE*1){
|
if (god.counter == GOD_BENCH_SIZE) {
|
||||||
god.counter = 0;
|
god.counter = 0;
|
||||||
god.state = GodState::WAIT;
|
god.state = GodState::WAIT;
|
||||||
}else ++god.counter;
|
} else ++god.counter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::WAIT: {
|
case GodState::WAIT: {
|
||||||
if (god.counter == 50) {
|
if (god.counter == 50) {
|
||||||
cout << "init throw" << endl;
|
|
||||||
// init throw
|
// init throw
|
||||||
god.counter = 0;
|
god.counter = 0;
|
||||||
god.state = GodState::RETRIEVE1;
|
god.state = GodState::RETRIEVE1;
|
||||||
god.throwedInvPosX = rand() % grid.size();
|
god.thrownInvPosX = rand() % grid.size();
|
||||||
god.throwedInvPosY = rand() % grid[0].size();
|
god.thrownInvPosY = rand() % grid[0].size();
|
||||||
|
|
||||||
god.thrownInvType = grid[god.throwedInvPosX][god.throwedInvPosY];
|
god.thrownInvType = grid[god.thrownInvPosX][god.thrownInvPosY];
|
||||||
|
|
||||||
god.thrownTransition.setX(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE);
|
god.thrownTransition.setX(pm.getScreenWidth() - GOD_HAND_DISTANCE - GOD_HAND_SIZE);
|
||||||
god.thrownTransition.setY(basePos.getY()+INV_GET_POS(god.throwedInvPosY));
|
god.thrownTransition.setY(basePos.getY() + INV_GET_POS(god.thrownInvPosY));
|
||||||
} else ++god.counter;
|
} else ++god.counter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::RETRIEVE1:{
|
case GodState::RETRIEVE1: {
|
||||||
if(god.counter==100){
|
if (god.counter == 100) {
|
||||||
grid[god.throwedInvPosX][god.throwedInvPosY] = InvaderType::NONE;
|
grid[god.thrownInvPosX][god.thrownInvPosY] = InvaderType::NONE;
|
||||||
updateColumns();
|
updateColumns();
|
||||||
god.state = GodState::RETRIEVE2;
|
god.state = GodState::RETRIEVE2;
|
||||||
}else ++god.counter;
|
} else god.counter += 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::RETRIEVE2:{
|
case GodState::RETRIEVE2: {
|
||||||
if(god.counter==0){
|
if (god.counter == 0) {
|
||||||
god.state = GodState::THROW;
|
god.state = GodState::THROW;
|
||||||
}else --god.counter;
|
god.counter = 0;
|
||||||
|
|
||||||
|
// compute the launch vector
|
||||||
|
|
||||||
|
Position invaderMiddlePos(pm.getScreenWidth() - GOD_HAND_DISTANCE - GOD_HAND_SIZE / 2,
|
||||||
|
GOD_HAND_SIZE / 2);
|
||||||
|
|
||||||
|
playerID target;
|
||||||
|
if (players.size() == 1)target = 0; // don't want to use random if not needed
|
||||||
|
else target = rand() % players.size();
|
||||||
|
Position playerMiddlePos(players[target].x + confData.playersWidth / 2,
|
||||||
|
pm.getScreenWidth() - PLAYER_HEIGHT / 2);
|
||||||
|
|
||||||
|
god.thrownVector = playerMiddlePos - invaderMiddlePos;
|
||||||
|
god.thrownVector = god.thrownVector / (god.thrownVector.computeMagnitude() / 1000.0);
|
||||||
|
// let's normalize it, but keep it's length big so x and y and non-zero
|
||||||
|
// We will divide it in display
|
||||||
|
} else god.counter -= 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GodState::THROW:{
|
case GodState::THROW: {
|
||||||
cout << "FROM NOW ON ANYTHING CAN HAPPEN" << endl;
|
++god.counter;
|
||||||
break;
|
|
||||||
|
|
||||||
|
Position invaderPos = god.getLeftHandPos(pm.getScreenWidth());
|
||||||
|
applyTransformation(invaderPos, GOD_HAND_SIZE, confData.invadersSize);
|
||||||
|
Position a = god.thrownVector * (god.counter / 100.0);
|
||||||
|
invaderPos = invaderPos + a;
|
||||||
|
|
||||||
|
bool touched = false;
|
||||||
|
|
||||||
|
// check if OOB (Out Of Bounds)
|
||||||
|
if (invaderPos.getY() >= pm.getScreenWidth() &&
|
||||||
|
(invaderPos.getX() < 0 || invaderPos.getX() + confData.invadersSize >= pm.getScreenWidth())) {
|
||||||
|
touched = true;
|
||||||
|
// check player collision
|
||||||
|
} else if (invaderPos.getY() + confData.invadersSize >= pm.getScreenWidth() - PLAYER_HEIGHT) {
|
||||||
|
for (Player &p: players) {
|
||||||
|
if (areLinesColliding(
|
||||||
|
p.x, p.x + confData.playersWidth,
|
||||||
|
invaderPos.getX(), invaderPos.getX() + confData.invadersSize
|
||||||
|
)) {
|
||||||
|
// TODO manage player death
|
||||||
|
touched = true;
|
||||||
|
// do not break, the other player also deserves to be hit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (touched){
|
||||||
|
god.state = GodState::WAIT;
|
||||||
|
god.counter = 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* we do not need to reset other members, they'll be treated as non-initialized
|
||||||
|
* When we cycle back between states
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position God::getLeftHandPos(unsigned screenWidth) const {
|
||||||
|
return Position(screenWidth - GOD_HAND_DISTANCE - GOD_HAND_SIZE, GOD_HAND_SIZE);
|
||||||
|
}
|
@ -96,11 +96,11 @@ void PixelManager::endFrame() const {
|
|||||||
window.finishFrame();
|
window.finishFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::displayGodBench(int y) const {
|
void PixelManager::drawGodBench(int y) const {
|
||||||
window << Rectangle(Position(0, y), Position(getScreenWidth(), y+GOD_BENCH_SIZE), nsGraphics::KGray);
|
window << Rectangle(Position(0, y), Position(getScreenWidth(), y+GOD_BENCH_SIZE), nsGraphics::KGray);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::displayGodRightHand(const Position& pos, bool closed) const {
|
void PixelManager::drawGodRightHand(const Position& pos, bool closed) const {
|
||||||
if(closed){
|
if(closed){
|
||||||
drawSprite(rightHandClosed, pos);
|
drawSprite(rightHandClosed, pos);
|
||||||
}else{
|
}else{
|
||||||
@ -108,7 +108,7 @@ void PixelManager::displayGodRightHand(const Position& pos, bool closed) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixelManager::displayGodLeftHand(const Position& pos, bool closed) const {
|
void PixelManager::drawGodLeftHand(const Position& pos, bool closed) const {
|
||||||
if(closed){
|
if(closed){
|
||||||
drawSprite(leftHandClosed, pos);
|
drawSprite(leftHandClosed, pos);
|
||||||
}else{
|
}else{
|
||||||
|
@ -16,3 +16,8 @@ size_t InvadersColumn::getOutterInvader() const {
|
|||||||
}
|
}
|
||||||
return size();
|
return size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyTransformation(Position& pos, unsigned sizeFrom, unsigned sizeTo){
|
||||||
|
pos += Position(sizeFrom/2, sizeFrom/2);
|
||||||
|
pos -= Position(sizeTo/2, sizeTo/2);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user