Compare commits

...

4 Commits

  1. BIN
      Faceball2030/assets/enemies/IShoot.png
  2. 2
      Faceball2030/assets/map/map1.map
  3. 81
      Faceball2030/main.cpp
  4. 9
      Faceball2030/main.h
  5. 5
      TODO.txt

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

@ -32,7 +32,7 @@
8351 8351
8197 8197
8595 8595
8198 7958
273 273
8196 8196
8195 8195

@ -95,6 +95,7 @@ bool Enemy::isExplosive() {
void Enemy::setExploded(bool exploded) { void Enemy::setExploded(bool exploded) {
this->exploded = exploded; this->exploded = exploded;
game->RegenerateMinimap();
} }
Enemy Enemy::freshCopy(bool randomizeLoc){ Enemy Enemy::freshCopy(bool randomizeLoc){
@ -238,6 +239,9 @@ void Enemy::OnDeathEvent() {
if (game->enemyData[id].powerupDrop != PowerupType::NONE) { if (game->enemyData[id].powerupDrop != PowerupType::NONE) {
game->SpawnPowerup(game->enemyData[id].powerupDrop, pos); game->SpawnPowerup(game->enemyData[id].powerupDrop, pos);
} }
if (game->PlayerHasMapUpgrade()){
game->RegenerateMinimap();
}
} }
vf2d FaceBall::GetPlayerPos() { vf2d FaceBall::GetPlayerPos() {
@ -427,6 +431,51 @@ void FaceBall::LoadLevel(int level)
objects.push_back({ mapFloor,{0,0,0},0,0 }); objects.push_back({ mapFloor,{0,0,0},0,0 });
//objects.push_back({ game->mapExit,{(float)exitCoords.x+0.5f,0,(float)exitCoords.y+0.5f},0,0.4f }); //objects.push_back({ game->mapExit,{(float)exitCoords.x+0.5f,0,(float)exitCoords.y+0.5f},0,0.4f });
exit = { game->mapExit,{(float)exitCoords.x + 0.5f,0.02f,(float)exitCoords.y + 0.5f},0,0.4f }; exit = { game->mapExit,{(float)exitCoords.x + 0.5f,0.02f,(float)exitCoords.y + 0.5f},0,0.4f };
RegenerateMinimap();
}
void FaceBall::RegenerateMinimap(){
vf2d mapCenter = {float(ScreenWidth()-364),float(164)};
vf2d mapSprSize = {float(mapSpr->width),float(mapSpr->height)};
SetDrawTarget(mapSpr);
Clear(BLACK);
const int MAP_VISIBILITY=6;
for (int x=0;x<MAP_SIZE.x;x++){
for (int y=0;y<MAP_SIZE.y;y++){
float dist = std::sqrtf(std::pow(player.GetPos().x-x,2)+std::pow(player.GetPos().z-y,2));
if (dist<MAP_VISIBILITY){
try{
MapSquare&square=map.at(y).at(x);
vf2d squareLoc = vf2d{x*minimapGridSize.x,y*minimapGridSize.y};
if (square.wallN){
DrawLine(squareLoc,squareLoc+vf2d{1.f,0.f}*minimapGridSize,{255,255,255,uint8_t((1-(float(dist)/MAP_VISIBILITY))*255)});
}
if (square.wallS){
DrawLine(squareLoc+vf2d{0,1.f}*minimapGridSize,squareLoc+vf2d{1,1}*minimapGridSize,{255,255,255,uint8_t((1-(float(dist)/MAP_VISIBILITY))*255)});
}
if (square.wallE){
DrawLine(squareLoc+vf2d{1,0}*minimapGridSize,squareLoc+vf2d{1,1}*minimapGridSize,{255,255,255,uint8_t((1-(float(dist)/MAP_VISIBILITY))*255)});
}
if (square.wallW){
DrawLine(squareLoc,squareLoc+vf2d{0,1}*minimapGridSize,{255,255,255,uint8_t((1-(float(dist)/MAP_VISIBILITY))*255)});
}
if (hasMapUpgrade){
for (Enemy&e:enemies){
if (!e.isDead()){
if (vi2d{int(e.pos.x),int(e.pos.z)}==vi2d{x,y}){
FillCircle(vi2d{int(squareLoc.x+0.5*minimapGridSize.x),int(squareLoc.y+0.5*minimapGridSize.y)},3,enemyData[e.GetID()].col*(1-(float(dist)/MAP_VISIBILITY)));
}
}
}
}
} catch (std::out_of_range const& exc) {
std::cout << exc.what() << '\n';
}
}
}
}
SetDrawTarget(nullptr);
mapDecal->Update();
} }
bool FaceBall::CheckCollision(vec3d movementVector,vf2d pos,float radius){ bool FaceBall::CheckCollision(vec3d movementVector,vf2d pos,float radius){
@ -1626,6 +1675,10 @@ void FaceBall::HandleKeys(float fElapsedTime) {
if (GetKey(olc::F1).bPressed) { if (GetKey(olc::F1).bPressed) {
freeRoam = !freeRoam; freeRoam = !freeRoam;
} }
if (vi2d{int(player.GetPos().x),int(player.GetPos().z)}!=playerRoundedCoords){
playerRoundedCoords = vi2d{int(player.GetPos().x),int(player.GetPos().z)};
RegenerateMinimap();
}
} }
void FaceBall::AddWall(int dir, vi2d gridSquare) { void FaceBall::AddWall(int dir, vi2d gridSquare) {
@ -1694,6 +1747,9 @@ bool FaceBall::OnUserCreate()
mapWalls.texture = wall_tex; mapWalls.texture = wall_tex;
mapFloor.texture = floor_tex; mapFloor.texture = floor_tex;
mapSpr=new Sprite(minimapGridSize.x*20,minimapGridSize.y*20);
mapDecal=new Decal(mapSpr);
InitializeEnemyData(); InitializeEnemyData();
InitializePowerupColors(); InitializePowerupColors();
@ -1800,11 +1856,13 @@ bool Bullet::Update(float fElapsedTime) {
} }
void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) { void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) {
if (respawnTimer<=0.0f){
if (shieldDuration >= 0) { if (shieldDuration >= 0) {
damage = 0; damage = 0;
} }
hp = std::max(0, hp - damage); hp = std::max(0, hp - damage);
if (hp <= 0) { if (hp <= 0) {
RegenerateMinimap();
respawnTimer = 3.0f; respawnTimer = 3.0f;
} }
lastHitBy = id; lastHitBy = id;
@ -1816,6 +1874,7 @@ void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) {
screenCol = WHITE; screenCol = WHITE;
} }
} }
}
void FaceBall::Display3DKillerModel() { void FaceBall::Display3DKillerModel() {
// Set up rotation matrices // Set up rotation matrices
@ -1936,6 +1995,7 @@ void FaceBall::RenderHud(float fElapsedTime) {
hudShakeAmt = std::sinf(40 * hudShakeTime); hudShakeAmt = std::sinf(40 * hudShakeTime);
hudAdjustment.x += hudShakeAmt * 2; hudAdjustment.x += hudShakeAmt * 2;
hudAdjustment.y += hudShakeAmt * 4; hudAdjustment.y += hudShakeAmt * 4;
hudOffset += hudShakeAmt * 2;
} }
vf2d hudLoc = { hudAdjustment.x + (hp>0?hudOffset:0),hudAdjustment.y}; vf2d hudLoc = { hudAdjustment.x + (hp>0?hudOffset:0),hudAdjustment.y};
if (hp > 0) { if (hp > 0) {
@ -1982,6 +2042,10 @@ void FaceBall::RenderHud(float fElapsedTime) {
if (camoDuration > 0) { if (camoDuration > 0) {
DrawPartialDecal({ hudOffset + float(ScreenWidth() / 10 - 16), float(ScreenHeight() / 4 + ScreenHeight() / 4 * 2 - 16 * 4) }, vf2d{ 32,32 }*4, powerups_tex, { 5 * 32,0 }, { 32,32 },camoDuration>7?WHITE:camoDuration>2?std::abs(std::sin(10*camoDuration))>0.65?WHITE:BLACK: std::abs(std::sin(30 * camoDuration)) > 0.75 ? WHITE : BLACK); DrawPartialDecal({ hudOffset + float(ScreenWidth() / 10 - 16), float(ScreenHeight() / 4 + ScreenHeight() / 4 * 2 - 16 * 4) }, vf2d{ 32,32 }*4, powerups_tex, { 5 * 32,0 }, { 32,32 },camoDuration>7?WHITE:camoDuration>2?std::abs(std::sin(10*camoDuration))>0.65?WHITE:BLACK: std::abs(std::sin(30 * camoDuration)) > 0.75 ? WHITE : BLACK);
} }
vf2d mapCenter = {float(ScreenWidth()-364),float(164)};
SetDrawTarget(nullptr);
DrawDecal(vf2d{mapCenter.x+hudOffset/2,mapCenter.y}-vf2d{2.5f,2.5f},dot,{5,5},GREEN);
DrawRotatedDecal({mapCenter.x+hudOffset/2,mapCenter.y},mapDecal,-fYaw-PI/2,vf2d{int(player.GetPos().x)+0.5f,int(player.GetPos().z)+0.5f}*minimapGridSize,{1,1});
SetDecalMode(DecalMode::NORMAL); SetDecalMode(DecalMode::NORMAL);
} }
GradientFillRectDecal({ 0,0 }, vf2d{ (float)ScreenWidth()/2,(float)ScreenHeight()/2 }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime > 0.2f ? 64 : 0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }); GradientFillRectDecal({ 0,0 }, vf2d{ (float)ScreenWidth()/2,(float)ScreenHeight()/2 }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime > 0.2f ? 64 : 0) }, { (uint8_t)screenCol.r,(uint8_t)screenCol.g,(uint8_t)screenCol.b,(uint8_t)(hudShakeTime>0.2f?120:hudShakeTime>0?64:0) });
@ -2106,7 +2170,8 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) {
}break; }break;
} }
}break; }break;
case ISHOOT: { case ISHOOT:
case ISHOOT_MAP: {
e.rot += dat.rotSpd * fElapsedTime; e.rot += dat.rotSpd * fElapsedTime;
if (e.CanShoot()) { if (e.CanShoot()) {
e.ShootBullet(myIndex); e.ShootBullet(myIndex);
@ -2149,8 +2214,18 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) {
} }
}break; }break;
} }
if (e.roundedCoords!=vi2d{int(e.pos.x),int(e.pos.z)}){
e.roundedCoords=vi2d{int(e.pos.x),int(e.pos.z)};
if (hasMapUpgrade){
RegenerateMinimap();
}
} }
} }
}
bool FaceBall::PlayerHasMapUpgrade(){
return hasMapUpgrade;
}
bool FaceBall::OnUserUpdate(float fElapsedTime) bool FaceBall::OnUserUpdate(float fElapsedTime)
{ {
@ -2178,6 +2253,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
!CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){ !CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){
enemies.push_back(e); enemies.push_back(e);
wave2Enemies.erase(wave2Enemies.begin()+i); wave2Enemies.erase(wave2Enemies.begin()+i);
RegenerateMinimap();
goto spawningDone; goto spawningDone;
} }
} }
@ -2189,6 +2265,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
!CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){ !CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){
enemies.push_back(e); enemies.push_back(e);
wave3Enemies.erase(wave3Enemies.begin()+i); wave3Enemies.erase(wave3Enemies.begin()+i);
RegenerateMinimap();
goto spawningDone; goto spawningDone;
} }
} }
@ -2204,6 +2281,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
!CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){ !CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){
enemies.push_back(e); enemies.push_back(e);
wave2Enemies.erase(wave2Enemies.begin()+i); wave2Enemies.erase(wave2Enemies.begin()+i);
RegenerateMinimap();
break; break;
} }
} }
@ -2270,6 +2348,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
}break; }break;
case PowerupType::MAP: { case PowerupType::MAP: {
hasMapUpgrade = true; hasMapUpgrade = true;
RegenerateMinimap();
}break; }break;
case PowerupType::COIN: { case PowerupType::COIN: {
AddScore(1000); AddScore(1000);

@ -214,6 +214,7 @@ struct Enemy : public Object {
bool flippedTriangles = false; bool flippedTriangles = false;
bool finishedAnimation = false; bool finishedAnimation = false;
float blinkingAmt = 1; //>0.5 the enemy is visible. float blinkingAmt = 1; //>0.5 the enemy is visible.
vi2d roundedCoords = vi2d{int(pos.x),int(pos.z)};
Enemy(EnemyID id, vec3d pos, float rot, float radius); Enemy(EnemyID id, vec3d pos, float rot, float radius);
EnemyID GetID(); EnemyID GetID();
//Can set the damage to 0 to cause just a visual hit. //Can set the damage to 0 to cause just a visual hit.
@ -263,6 +264,11 @@ class FaceBall : public PixelGameEngine
enemy_Sonar, mapExit,enemy_ShootMe2,powerup,powerup2, enemy_Sonar, mapExit,enemy_ShootMe2,powerup,powerup2,
enemy_IShoot; enemy_IShoot;
Sprite*mapSpr;
Decal*mapDecal;
vf2d minimapGridSize={16,16};
Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex, Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex,
*enemy_Sonar_tex,*hud,*exit_wall_tex,*enemy_ShootMe2_tex,*enemy_IShoot_tex, *enemy_Sonar_tex,*hud,*exit_wall_tex,*enemy_ShootMe2_tex,*enemy_IShoot_tex,
*life4,*life3,*life2,*life1,*crosshair,*hudmeter,*powerup_tex,*powerup2_tex, *life4,*life3,*life2,*life1,*crosshair,*hudmeter,*powerup_tex,*powerup2_tex,
@ -335,6 +341,7 @@ class FaceBall : public PixelGameEngine
}; };
Player player = { {3.7,0.3,0.7}, {{0.5,0.5},0.2} }; Player player = { {3.7,0.3,0.7}, {{0.5,0.5},0.2} };
vi2d playerRoundedCoords = {int(player.GetPos().x),int(player.GetPos().z)};
const int baseHP = 3; const int baseHP = 3;
int hp = baseHP; int hp = baseHP;
int maxHP=hp; int maxHP=hp;
@ -431,4 +438,6 @@ class FaceBall : public PixelGameEngine
vf2d GetPlayerPos(); vf2d GetPlayerPos();
void AddScore(int score); void AddScore(int score);
vf2d GetRandomizedSpawnPosition(); vf2d GetRandomizedSpawnPosition();
bool PlayerHasMapUpgrade();
void RegenerateMinimap();
}; };

@ -0,0 +1,5 @@
- Minimap
- Skybox
- Levels have distinguishing elements (skybox, walls, floor, fog color)
- Main Menu
- Sounds & Music
Loading…
Cancel
Save