linux_template
sigonasr2 2 years ago
parent 2abd640dcb
commit cf4ed30867
  1. 117
      Faceball2030/main.cpp
  2. 4
      Faceball2030/main.h

@ -100,6 +100,10 @@ bool Enemy::isBlinking() {
return blinking; return blinking;
} }
bool Enemy::isExploded() {
return exploded;
}
void FaceBall::InitializeEnemyData() { void FaceBall::InitializeEnemyData() {
enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK }; enemyData[EnemyID::NONE] = { "VOID",undefined,BLACK };
enemyData[EXIT] = { "EXIT",undefined,GREEN }; enemyData[EXIT] = { "EXIT",undefined,GREEN };
@ -128,6 +132,7 @@ void FaceBall::ConvertBulletColor(Mesh& bullet, Pixel col) {
void FaceBall::LoadLevel(int level) void FaceBall::LoadLevel(int level)
{ {
this->level = level; this->level = level;
restingTriangleYDepth = 0.f;
exitWallsCleared = false; exitWallsCleared = false;
std::vector<std::vector<Tile>>mapData = editor.LoadLevel(level); std::vector<std::vector<Tile>>mapData = editor.LoadLevel(level);
MAP_SIZE = { (int)mapData[0].size(),(int)mapData.size() }; MAP_SIZE = { (int)mapData[0].size(),(int)mapData.size() };
@ -1577,39 +1582,97 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) {
darkenAmt++; darkenAmt++;
e.decreaseColorFactor(); e.decreaseColorFactor();
} }
for (Triangle& t : tris) { if (e.isExploded()) {
if (t.p[0].y > 0.1) { if (!e.flippedTriangles) {
t.p[0].y = std::max(0.1f, t.p[0].y - 0.3f * fElapsedTime); e.flippedTriangles = true;
for (Triangle& t : tris) {
vec3d temp=t.p[1];
t.p[1] = t.p[2];
t.p[2] = t.p[1];
}
} }
else { for (Triangle& t : tris) {
float dir = std::atan2f(t.p[0].z, t.p[0].x); float dir = std::atan2f(t.p[0].z, t.p[0].x);
t.p[0].x += std::cosf(dir)*0.04f*fElapsedTime; t.p[0].x += std::cosf(dir+ (rand() % 200 / 200.f)- 1) * (rand() % 100/100.f) * fElapsedTime*3;
t.p[0].z += std::sinf(dir) * 0.04f * fElapsedTime; t.p[0].z += std::sinf(dir + (rand() % 200 / 200.f) - 1) * (rand() % 100 / 100.f) * fElapsedTime * 3;
} if (t.p[0].y > 0.041f) {
if (t.p[1].y > 0.1) { t.p[0].y = std::max(0.04f, t.p[0].y - 0.8f * fElapsedTime * 3);
t.p[1].y = std::max(0.1f, t.p[1].y - 0.3f * fElapsedTime); }
} dir = std::atan2f(t.p[1].z, t.p[1].x);
else { t.p[1].x += std::cosf(dir + (rand() % 200 / 200.f) - 1) * (rand() % 100 / 100.f) * fElapsedTime * 3;
float dir = std::atan2f(t.p[1].z, t.p[1].x); t.p[1].z += std::sinf(dir + (rand() % 200 / 200.f) - 1) * (rand() % 100 / 100.f) * fElapsedTime * 3;
t.p[1].x += std::cosf(dir) * 0.06f * fElapsedTime; if (t.p[1].y > 0.041f) {
t.p[1].z += std::sinf(dir) * 0.06f * fElapsedTime; t.p[1].y = std::max(0.04f, t.p[1].y - 0.8f * fElapsedTime * 3);
} }
if (t.p[2].y > 0.1) { dir = std::atan2f(t.p[2].z, t.p[2].x);
t.p[2].y = std::max(0.1f, t.p[2].y - 0.3f * fElapsedTime); t.p[2].x += std::cosf(dir + (rand() % 200 / 200.f) - 1) * (rand() % 70 / 100.f) * fElapsedTime * 3;
t.p[2].z += std::sinf(dir + (rand() % 200 / 200.f) - 1) * (rand() % 70 / 100.f) * fElapsedTime * 3;
if (t.p[2].y > 0.041f) {
t.p[2].y = std::max(0.04f, t.p[2].y - 0.8f * fElapsedTime * 3);
}
if (darkenAmt > 0) {
t.col[0] -= {darkenAmt, darkenAmt, darkenAmt};
t.col[1] -= {darkenAmt, darkenAmt, darkenAmt};
t.col[2] -= {darkenAmt, darkenAmt, darkenAmt};
}
} }
else { }
float dir = std::atan2f(t.p[2].z, t.p[2].x); else {
t.p[2].x += std::cosf(dir) * 0.05f * fElapsedTime; for (Triangle& t : tris) {
t.p[2].z += std::sinf(dir) * 0.05f * fElapsedTime; if (t.p[0].y > 0.1) {
t.p[0].y = std::max(0.1f, t.p[0].y - 0.3f * fElapsedTime);
}
else {
float dir = std::atan2f(t.p[0].z, t.p[0].x);
t.p[0].x += std::cosf(dir) * 0.04f * fElapsedTime;
t.p[0].z += std::sinf(dir) * 0.04f * fElapsedTime;
}
if (t.p[1].y > 0.1) {
t.p[1].y = std::max(0.1f, t.p[1].y - 0.3f * fElapsedTime);
}
else {
float dir = std::atan2f(t.p[1].z, t.p[1].x);
t.p[1].x += std::cosf(dir) * 0.06f * fElapsedTime;
t.p[1].z += std::sinf(dir) * 0.06f * fElapsedTime;
}
if (t.p[2].y > 0.1) {
t.p[2].y = std::max(0.1f, t.p[2].y - 0.3f * fElapsedTime);
}
else {
float dir = std::atan2f(t.p[2].z, t.p[2].x);
t.p[2].x += std::cosf(dir) * 0.05f * fElapsedTime;
t.p[2].z += std::sinf(dir) * 0.05f * fElapsedTime;
}
if (darkenAmt > 0) {
t.col[0] -= {darkenAmt, darkenAmt, darkenAmt};
t.col[1] -= {darkenAmt, darkenAmt, darkenAmt};
t.col[2] -= {darkenAmt, darkenAmt, darkenAmt};
}
} }
if (darkenAmt>0){ }
t.col[0] -= {darkenAmt, darkenAmt, darkenAmt}; if (e.isExploded()) {
t.col[1] -= {darkenAmt, darkenAmt, darkenAmt}; e.increaseDeathTimer(fElapsedTime*3);
t.col[2] -= {darkenAmt, darkenAmt, darkenAmt}; e.increaseColorFactor(fElapsedTime*3);
}
else {
e.increaseDeathTimer(fElapsedTime);
e.increaseColorFactor(fElapsedTime);
}
}
else
if (!e.finishedAnimation){
e.finishedAnimation = true;
if (e.isExploded()) {
for (Triangle& t : e.mesh.tris) {
t.p[0].y = 0.04f+ restingTriangleYDepth;
t.p[1].y = 0.04f + restingTriangleYDepth;
t.p[2].y = 0.04f + restingTriangleYDepth;
restingTriangleYDepth += 0.000001f;
if (restingTriangleYDepth > 0.01f) {
restingTriangleYDepth = 0.f;
}
} }
} }
e.increaseDeathTimer(fElapsedTime);
e.increaseColorFactor(fElapsedTime);
} }
} }
else { else {

@ -193,6 +193,8 @@ struct Enemy : public Object {
float lastHitTime = 0; float lastHitTime = 0;
public: public:
float turnAmt = 0; float turnAmt = 0;
bool flippedTriangles = false;
bool finishedAnimation = false;
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.
@ -213,6 +215,7 @@ struct Enemy : public Object {
bool isExplosive(); bool isExplosive();
void setExploded(bool exploded); void setExploded(bool exploded);
bool isBlinking(); bool isBlinking();
bool isExploded();
}; };
class FaceBall : public PixelGameEngine class FaceBall : public PixelGameEngine
@ -316,6 +319,7 @@ class FaceBall : public PixelGameEngine
void RenderHud(float fElapsedTime); void RenderHud(float fElapsedTime);
void ConvertBulletColor(Mesh& bullet, Pixel col); void ConvertBulletColor(Mesh& bullet, Pixel col);
public: public:
float restingTriangleYDepth = 0.f;
std::vector<Bullet>bullets; std::vector<Bullet>bullets;
Mesh bullet; Mesh bullet;
float shotSpd = 4.0f; float shotSpd = 4.0f;

Loading…
Cancel
Save