Added score and life gaining mechanics.

linux_template
sigonasr2 2 years ago
parent 6a63a73ec8
commit d4e37b6179
  1. 14
      Faceball2030/assets/map/map1.map
  2. 28
      Faceball2030/main.cpp
  3. 4
      Faceball2030/main.h

@ -19,26 +19,26 @@
8192
8194
8192
15632
8196
16272
16276
8193
2
25492
8201
16144
16272
8192
15508
16276
8197
8351
8197
8195
8198
273
15764
16276
8195
8602
8194
8202
8202
16018
15894
8194
16278

@ -219,7 +219,7 @@ bool Enemy::Update(float fElapsedTime) {
//Has Camo powerup code so camo masks the player position.
vf2d Enemy::GetPlayerPosition() {
if (game->PlayerHasCamo()) {
return { int(id) % game->MAP_SIZE.x,int(id) % game->MAP_SIZE.y };
return { float(int(id) % game->MAP_SIZE.x) + 0.5f,float(int(id) % game->MAP_SIZE.y)+0.5f };
}
else {
return game->GetPlayerPos();
@ -227,6 +227,8 @@ vf2d Enemy::GetPlayerPosition() {
}
void Enemy::OnDeathEvent() {
game->AddScore(game->enemyData[id].health*10);
game->SubtractTag();
if (game->enemyData[id].powerupDrop != PowerupType::NONE) {
game->SpawnPowerup(game->enemyData[id].powerupDrop, pos);
@ -1927,6 +1929,14 @@ void FaceBall::RenderHud(float fElapsedTime) {
}
}
}
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
if (x != 0 && y != 0) {
DrawStringPropDecal(vf2d{ hudOffset + (float)(ScreenWidth() / 2 - GetTextSizeProp(std::to_string(score)).x * 4 / 2) + 32,(float)(36 - GetTextSizeProp(std::to_string(score)).y * 4) + 18 } + hudAdjustment + vf2d{float(x),float(y)}, std::to_string(score), VERY_DARK_RED, {4,4});
}
}
}
DrawStringPropDecal(vf2d{ hudOffset + (float)(ScreenWidth() / 2 - GetTextSizeProp(std::to_string(score)).x * 4 / 2) + 32,(float)(36 - GetTextSizeProp(std::to_string(score)).y * 4) + 18 } + hudAdjustment, std::to_string(score), { 192,96,96 }, { 4,4 });
DrawStringDecal(vf2d{ hudOffset + float(ScreenWidth() / 2 - GetTextSize(hudDisplayText).x / 2 * 4) + 32,float(ScreenHeight() - 128 - GetTextSize(hudDisplayText).y * 4) + 18 }, hudDisplayText, { 192,192,255 }, { 4,4 });
SetDecalMode(DecalMode::ADDITIVE);
DrawDecal({ float(ScreenWidth() / 2 - crosshair->sprite->width / 2),float(ScreenHeight() / 2 - crosshair->sprite->height / 2) }, crosshair, { 1,1 }, {255,255,255,128});
@ -2176,7 +2186,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
hasMapUpgrade = true;
}break;
case PowerupType::COIN: {
score += 1000;
AddScore(1000);
}break;
}
powerups.erase(powerups.begin() + lastPowerupCollidedWith);
@ -2238,6 +2248,20 @@ void FaceBall::OnTextEntryComplete(const std::string& sText) {
}
}
//This function adds to the game score and increments lives appropriately.
void FaceBall::AddScore(int score) {
this->score += score;
if (lastAwardedScore/10000 != this->score/10000) {
lives++;
lastAwardedScore = this->score;
}
}
void FaceBall::ResetScore() {
score = 0;
lastAwardedScore = 0;
}
int main()
{
FaceBall demo;

@ -325,6 +325,7 @@ class FaceBall : public PixelGameEngine
int hp = baseHP;
int maxHP=hp;
int score = 0;
int lastAwardedScore = 0;
Object walls;
Object exit;
vec3d freeRoamCamera = { 1,0.5,1 };
@ -395,6 +396,7 @@ class FaceBall : public PixelGameEngine
void ConvertBulletColor(Mesh& bullet, Pixel col);
void Display3DKillerModel();
int CheckPowerupCollision(vec3d movementVector, vf2d pos, float radius);
void ResetScore();
public:
vi2d MAP_SIZE;
float restingTriangleYDepth = 0.f;
@ -410,4 +412,6 @@ class FaceBall : public PixelGameEngine
void HurtPlayer(EnemyID id, int damage=1,bool blinking = false);
void SpawnPowerup(PowerupType type, vec3d pos);
bool PlayerHasCamo();
vf2d GetPlayerPos();
void AddScore(int score);
};
Loading…
Cancel
Save