SuperSpaceInvaderTurboApoca.../src/game/display.cpp
2022-01-05 00:01:53 +01:00

110 lines
3.0 KiB
C++

#include "game.h"
/** Displays the screen once, and returns
* The more important stuff must be drawn last
*/
void Game::display(unsigned fps) const {
pm.drawBackground();
for (unsigned i = 0; i < this->grid.size(); ++i){
for (unsigned j = 0; j < this->grid[i].size(); ++j){
Position vec(
basePos.getX() + i * confData.invadersSize + i * confData.invadersDistance,
basePos.getY() + j * confData.invadersSize + j * confData.invadersDistance
);
displayInvader(vec, grid[i][j]);
}
}
for(const missile& miss : missiles){
pm.drawMissile(miss, confData.missilesWidth, confData.missilesColor);
}
for(const torpedo& tor : torpedos){
pm.drawTorpedo(tor, confData.torpedosWidth, confData.torpedosColor);
}
for(size_t i=0;i<players.size();++i){
pm.drawPlayer(players[i].x, confData.playersWidth, confData.playerDefs[i].color);
}
displayGod();
pm.drawFPS(fps);
}
void Game::displayInvader(const Position& pos, InvaderType type) const {
if(type==InvaderType::NONE)return;
InvaderTypeDef invDef = confData.invadersDef.at(type);
switch(type){
case InvaderType::TYPEA:{
pm.drawInvaderA(pos, confData.invadersSize, invDef.color);
return;
}
case InvaderType::TYPEB:{
pm.drawInvaderB(pos, confData.invadersSize, invDef.color);
return;
}
case InvaderType::TYPEC:{
pm.drawInvaderC(pos, confData.invadersSize, invDef.color);
return;
}
}
}
void applyBezier(Position& pos, const Position& point, const double percent) {
pos += (point-pos)*percent;
}
#include<mingl/shape/circle.h>
void Game::displayGod() const {
switch (god.state) {
case GodState::NONE:
return;
case GodState::AWAKE: {
unsigned dividedCounter = god.counter/1;
pm.displayGodBench(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);
pm.displayGodLeftHand(leftHand);
pm.displayGodRightHand(rightHand);
break;
}
case GodState::WAIT:{
pm.displayGodBench(0);
Position leftHand(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
Position rightHand(GOD_HAND_DISTANCE, 0);
pm.displayGodLeftHand(leftHand);
pm.displayGodRightHand(rightHand);
break;
}
case GodState::RETRIEVE1:
case GodState::RETRIEVE2:{
// Bezier curve
// counter goes [0-100]
pm.displayGodBench(0);
Position pos(pm.getScreenWidth()-GOD_HAND_DISTANCE-GOD_HAND_SIZE, 0);
Position endPos = invIndexToPos(god.throwedInvPosX, god.throwedInvPosY);
applyBezier(pos, god.thrownTransition, 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
pm.displayGodLeftHand(Position(GOD_HAND_DISTANCE, 0));
pm.displayGodRightHand(pos);
if(god.state==GodState::RETRIEVE2){
// TODO maybe a little transition to pos to better reflect the invader's position ?
displayInvader(pos, god.thrownInvType);
}
}
case GodState::THROW:{
break;
}
}
}