Minimap system now functioning with regenerating map optimization.

pull/1/head
sigonasr2 2 years ago
parent b0113e77a2
commit 408c05176a
  1. 2
      Faceball2030/assets/map/map1.map
  2. 107
      Faceball2030/main.cpp
  3. 6
      Faceball2030/main.h

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

@ -95,6 +95,7 @@ bool Enemy::isExplosive() {
void Enemy::setExploded(bool exploded) {
this->exploded = exploded;
game->RegenerateMinimap();
}
Enemy Enemy::freshCopy(bool randomizeLoc){
@ -238,6 +239,9 @@ void Enemy::OnDeathEvent() {
if (game->enemyData[id].powerupDrop != PowerupType::NONE) {
game->SpawnPowerup(game->enemyData[id].powerupDrop, pos);
}
if (game->PlayerHasMapUpgrade()){
game->RegenerateMinimap();
}
}
vf2d FaceBall::GetPlayerPos() {
@ -427,6 +431,50 @@ void FaceBall::LoadLevel(int level)
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 });
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);
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<6){
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,WHITE);
}
if (square.wallS){
DrawLine(squareLoc+vf2d{0,1.f}*minimapGridSize,squareLoc+vf2d{1,1}*minimapGridSize,WHITE);
}
if (square.wallE){
DrawLine(squareLoc+vf2d{1,0}*minimapGridSize,squareLoc+vf2d{1,1}*minimapGridSize,WHITE);
}
if (square.wallW){
DrawLine(squareLoc,squareLoc+vf2d{0,1}*minimapGridSize,WHITE);
}
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);
}
}
}
}
} 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){
@ -1626,6 +1674,10 @@ void FaceBall::HandleKeys(float fElapsedTime) {
if (GetKey(olc::F1).bPressed) {
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) {
@ -1694,7 +1746,7 @@ bool FaceBall::OnUserCreate()
mapWalls.texture = wall_tex;
mapFloor.texture = floor_tex;
mapSpr=new Sprite(128,128);
mapSpr=new Sprite(minimapGridSize.x*20,minimapGridSize.y*20);
mapDecal=new Decal(mapSpr);
InitializeEnemyData();
@ -1803,11 +1855,13 @@ bool Bullet::Update(float fElapsedTime) {
}
void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) {
if (respawnTimer<=0.0f){
if (shieldDuration >= 0) {
damage = 0;
}
hp = std::max(0, hp - damage);
if (hp <= 0) {
RegenerateMinimap();
respawnTimer = 3.0f;
}
lastHitBy = id;
@ -1818,6 +1872,7 @@ void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) {
else {
screenCol = WHITE;
}
}
}
void FaceBall::Display3DKillerModel() {
@ -1939,6 +1994,7 @@ void FaceBall::RenderHud(float fElapsedTime) {
hudShakeAmt = std::sinf(40 * hudShakeTime);
hudAdjustment.x += hudShakeAmt * 2;
hudAdjustment.y += hudShakeAmt * 4;
hudOffset += hudShakeAmt * 2;
}
vf2d hudLoc = { hudAdjustment.x + (hp>0?hudOffset:0),hudAdjustment.y};
if (hp > 0) {
@ -1986,38 +2042,9 @@ void FaceBall::RenderHud(float fElapsedTime) {
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)};
mapSpr= new Sprite{128,128};
vf2d mapSprSize = {float(mapSpr->width),float(mapSpr->height)};
SetDrawTarget(mapSpr);
Clear(BLACK);
vf2d center = mapSprSize/2;
vf2d minimapGridSize={16,16};
for (int x=-5;x<=5;x++){
for (int y=-5;y<=5;y++){
try{
MapSquare&square=map.at(y+int(player.GetPos().z)).at(x+int(player.GetPos().x));
vf2d squareLoc = center+vf2d{x*minimapGridSize.x,y*minimapGridSize.y};
if (square.wallN){
DrawLine(squareLoc+vf2d{-0.5f,-0.5f}*minimapGridSize,squareLoc+vf2d{0.5f,-0.5f}*minimapGridSize,WHITE);
}
if (square.wallS){
DrawLine(squareLoc+vf2d{-0.5f,0.5f}*minimapGridSize,squareLoc+vf2d{0.5f,0.5f}*minimapGridSize,WHITE);
}
if (square.wallE){
DrawLine(squareLoc+vf2d{0.5f,-0.5f}*minimapGridSize,squareLoc+vf2d{0.5f,0.5f}*minimapGridSize,WHITE);
}
if (square.wallW){
DrawLine(squareLoc+vf2d{-0.5f,-0.5f}*minimapGridSize,squareLoc+vf2d{-0.5f,0.5f}*minimapGridSize,WHITE);
}
} catch (std::out_of_range const& exc) {
std::cout << exc.what() << '\n';
}
}
}
FillCircle(center,5,GREEN);
SetDrawTarget(nullptr);
mapDecal=new Decal(mapSpr);
DrawRotatedDecal(mapCenter-mapSprSize,mapDecal,-fYaw-PI/2,mapSprSize/2);
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);
}
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) });
@ -2186,13 +2213,21 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) {
}
}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)
{
delete mapSpr;
delete mapDecal;
fElapsedTime = std::min(0.01667f, fElapsedTime);
gameTimer += fElapsedTime;
switch (mode) {
@ -2217,6 +2252,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
!CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){
enemies.push_back(e);
wave2Enemies.erase(wave2Enemies.begin()+i);
RegenerateMinimap();
goto spawningDone;
}
}
@ -2228,6 +2264,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
!CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){
enemies.push_back(e);
wave3Enemies.erase(wave3Enemies.begin()+i);
RegenerateMinimap();
goto spawningDone;
}
}
@ -2243,6 +2280,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
!CheckPlayerCollision({0,0,0},{e.pos.x,e.pos.z},e.radius*6)){
enemies.push_back(e);
wave2Enemies.erase(wave2Enemies.begin()+i);
RegenerateMinimap();
break;
}
}
@ -2309,6 +2347,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
}break;
case PowerupType::MAP: {
hasMapUpgrade = true;
RegenerateMinimap();
}break;
case PowerupType::COIN: {
AddScore(1000);

@ -214,6 +214,7 @@ struct Enemy : public Object {
bool flippedTriangles = false;
bool finishedAnimation = false;
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);
EnemyID GetID();
//Can set the damage to 0 to cause just a visual hit.
@ -266,6 +267,8 @@ class FaceBall : public PixelGameEngine
Sprite*mapSpr;
Decal*mapDecal;
vf2d minimapGridSize={16,16};
Decal* dot, * enemy_ShootMe_tex,*bullet_tex,*wall_tex,*floor_tex,
*enemy_Sonar_tex,*hud,*exit_wall_tex,*enemy_ShootMe2_tex,*enemy_IShoot_tex,
*life4,*life3,*life2,*life1,*crosshair,*hudmeter,*powerup_tex,*powerup2_tex,
@ -338,6 +341,7 @@ class FaceBall : public PixelGameEngine
};
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;
int hp = baseHP;
int maxHP=hp;
@ -434,4 +438,6 @@ class FaceBall : public PixelGameEngine
vf2d GetPlayerPos();
void AddScore(int score);
vf2d GetRandomizedSpawnPosition();
bool PlayerHasMapUpgrade();
void RegenerateMinimap();
};
Loading…
Cancel
Save