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

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

@ -193,6 +193,8 @@ struct Enemy : public Object {
float lastHitTime = 0;
public:
float turnAmt = 0;
bool flippedTriangles = false;
bool finishedAnimation = false;
Enemy(EnemyID id, vec3d pos, float rot, float radius);
EnemyID GetID();
//Can set the damage to 0 to cause just a visual hit.
@ -213,6 +215,7 @@ struct Enemy : public Object {
bool isExplosive();
void setExploded(bool exploded);
bool isBlinking();
bool isExploded();
};
class FaceBall : public PixelGameEngine
@ -316,6 +319,7 @@ class FaceBall : public PixelGameEngine
void RenderHud(float fElapsedTime);
void ConvertBulletColor(Mesh& bullet, Pixel col);
public:
float restingTriangleYDepth = 0.f;
std::vector<Bullet>bullets;
Mesh bullet;
float shotSpd = 4.0f;

Loading…
Cancel
Save