Compare commits

...

3 Commits

  1. 55
      Faceball2030/main.cpp
  2. 14
      Faceball2030/main.h

@ -26,6 +26,7 @@ void Enemy::Hurt(int damage) {
t.col[2] = BLACK;
}
health-=damage;
blinkingAmt = 1;
}
bool Enemy::isDead() {
@ -119,7 +120,6 @@ void Enemy::OnDeathEvent() {
if (game->enemyData[id].powerupDrop != PowerupType::NONE) {
game->SpawnPowerup(game->enemyData[id].powerupDrop, pos);
}
blinkingAmt = 1;
}
void FaceBall::InitializeEnemyData() {
@ -128,7 +128,7 @@ void FaceBall::InitializeEnemyData() {
enemyData[START] = { "SPAWN POSITION",undefined,{128,64,0} };
enemyData[SHOOTME] = { "SHOOTME",enemy_ShootMe,YELLOW,1,1,PI / 8,2,1,0.2f,true };
enemyData[SHOOTME2] = { "SHOOTME2",enemy_IShoot,YELLOW,1,1,PI / 6,2,1,0.3f,true };
enemyData[SHOOTME_ARMOR] = { "SHOOTME_ARMOR",enemy_ShootMe,YELLOW,6,1,PI / 6,2,1,0.3f,true,PowerupType::ARMOR,true };
enemyData[SHOOTME_ARMOR] = { "SHOOTME",enemy_ShootMe,YELLOW,6,1,PI / 6,2,1,0.3f,true,PowerupType::ARMOR,true };
enemyData[SONAR] = { "Sonar",enemy_Sonar,RED,5,1,PI / 8,2,1 };
enemyData[COIN] = { "Coin",undefined,BLUE };
enemyData[POWERUP_ARMOR] = { "Armor",undefined,{96,0,96} };
@ -141,23 +141,23 @@ void FaceBall::InitializeEnemyData() {
}
void FaceBall::InitializePowerupColors() {
powerupColorData[PowerupType::ARMOR] = DARK_GREEN;
powerupColorData[PowerupType::SPEED] = DARK_BLUE;
powerupColorData[PowerupType::SHOTS] = DARK_RED;
powerupColorData[PowerupType::STOP] = RED;
powerupColorData[PowerupType::SHIELD] = CYAN;
powerupColorData[PowerupType::CAMO] = MAGENTA;
powerupColorData[PowerupType::MAP] = GREEN;
powerupColorData[PowerupType::COIN] = BLUE;
powerupData[PowerupType::ARMOR] = { "Armor UP",DARK_GREEN };
powerupData[PowerupType::SPEED] = { "Speed UP", DARK_BLUE};
powerupData[PowerupType::SHOTS] = { "Shots UP", DARK_RED};
powerupData[PowerupType::STOP] = { "< STOP >", RED};
powerupData[PowerupType::SHIELD] = { "< Invincibility Shield >", CYAN};
powerupData[PowerupType::CAMO] = { "< Camouflage >", MAGENTA};
powerupData[PowerupType::MAP] = { "< Minimap >", GREEN};
powerupData[PowerupType::COIN] = { "Coin", BLUE };
}
Powerup::Powerup(Mesh mesh, vec3d pos, float rot, PowerupType type)
: type(type), col(game->powerupColorData[type]), Object{ mesh,pos,rot,0.375f } {}
: type(type), col(game->powerupData[type].col), Object{ mesh,pos,rot,0.375f } {}
bool Powerup::Update(float fElapsedTime) {
aliveTime += fElapsedTime;
colorCycle = std::sinf(10 * aliveTime);
col = game->powerupColorData[type] * colorCycle;
col = game->powerupData[type].col * colorCycle;
opened = false; //Open state is false until a player causes it to open.
return true;
}
@ -165,9 +165,9 @@ bool Powerup::Update(float fElapsedTime) {
void FaceBall::SpawnPowerup(PowerupType type, vec3d pos) {
Mesh mesh = (type <= PowerupType::SHOTS) ? powerup : powerup2;
for (Triangle& t : mesh.tris) {
t.col[0] = powerupColorData[type];
t.col[1] = powerupColorData[type];
t.col[2] = powerupColorData[type];
t.col[0] = powerupData[type].col;
t.col[1] = powerupData[type].col;
t.col[2] = powerupData[type].col;
}
powerups.push_back({ mesh,pos,0,type });
}
@ -1146,11 +1146,11 @@ void FaceBall::RenderWorld() {
for (auto& bullet : bullets) {
RenderBulletMesh(matView, vecTrianglesToRasterTranslucent, bullet);
}
RenderMesh(matView, vecTrianglesToRaster, walls);
RenderMesh(matView, vecTrianglesToRasterTranslucent, walls, true);
for (auto& powerup : powerups) {
RenderPowerupMesh(matView, vecTrianglesToRasterTranslucent, powerup);
}
RenderMesh(matView, vecTrianglesToRaster, walls);
RenderMesh(matView, vecTrianglesToRasterTranslucent, walls, true);
//std::sort(vecTrianglesToRaster.begin(),vecTrianglesToRaster.end(),[](triangle&t1,triangle&t2){return (t1.p[0].z+t1.p[1].z+t1.p[2].z)/3.0f>(t2.p[0].z+t2.p[1].z+t2.p[2].z)/3.0f;});
ClearBuffer(BLACK, true);
@ -1206,7 +1206,7 @@ void FaceBall::RenderWorld() {
{t.uv[1].u,t.uv[1].v},
{t.uv[2].u,t.uv[2].v},
}, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { t.col[0],t.col[1],t.col[2]});
SetDecalMode(DecalMode::WIREFRAME);
/*SetDecalMode(DecalMode::WIREFRAME);
DrawPolygonDecal(nullptr,{
{t.p[0].x, t.p[0].y},
{t.p[1].x, t.p[1].y},
@ -1215,7 +1215,7 @@ void FaceBall::RenderWorld() {
{0,0},
{0,0},
{0,0},
}, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { WHITE,WHITE,WHITE});
}, { t.uv[0].w,t.uv[1].w,t.uv[2].w }, { t.p[0].z,t.p[1].z,t.p[2].z }, { WHITE,WHITE,WHITE});*/
SetDecalStructure(DecalStructure::FAN);
triRenderCount++;
}
@ -1762,7 +1762,9 @@ void FaceBall::RenderHud(float fElapsedTime) {
FillRectDecal({ 0,0 }, { float(ScreenWidth()),float(ScreenHeight()) });
std::string topText = enemyData[lastHitBy].name + " SAYS";
std::string bottomText = "HAVE A NICE DAY !";
Display3DKillerModel();
if (!enemyData[lastHitBy].blinking||std::sinf(30*gameTimer)>0.4f) {
Display3DKillerModel();
}
DrawStringDecal({ (float)(ScreenWidth() / 2 - GetTextSize(topText).x / 2 * 3),140.f }, topText, { 96,96,255 }, { 3,6 });
DrawStringDecal({ float(ScreenWidth() / 2 - GetTextSize(bottomText).x / 2 * 3),float(ScreenHeight() - 140.f) }, bottomText, { 96,96,255 }, { 3,6 });
}
@ -1784,7 +1786,15 @@ void FaceBall::RenderHud(float fElapsedTime) {
if (hp > 0) {
DrawStringDecal(vf2d{ 112 + hudOffset+32,4+18 }+hudAdjustment, "Triangles: " + std::to_string(triRenderCount), BLACK, { 2,4 });
std::string hudText = "Tags Left: " + std::to_string(tagsRemaining) + " Lives: " + std::to_string(lives);
DrawStringPropDecal(vf2d{ hudOffset + (float)(ScreenWidth() / 2 - GetTextSizeProp(hudText).x * 3 / 2)+32,(float)(ScreenHeight() - 64 - GetTextSizeProp(hudText).y * 6)+18 } + hudAdjustment, hudText, WHITE, { 3,6 });
DrawStringPropDecal(vf2d{ hudOffset + (float)(ScreenWidth() / 2 - GetTextSizeProp(hudText).x * 3 / 2)+32,(float)(ScreenHeight() - 2 - GetTextSizeProp(hudText).y * 5)+18 } + hudAdjustment, hudText, VERY_DARK_GREY, { 3,5 });
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
if (x != 0 && y != 0) {
DrawStringDecal(vf2d{ hudOffset + float(ScreenWidth() / 2 - GetTextSize(hudDisplayText).x / 2 * 4) + 32,float(ScreenHeight() - 128 - GetTextSize(hudDisplayText).y * 4) + 18 } + vf2d{ float(x),float(y) }, hudDisplayText, DARK_BLUE, { 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 });
DrawDecal({ float(ScreenWidth() / 2 - crosshair->sprite->width / 2),float(ScreenHeight() / 2 - crosshair->sprite->height / 2) }, crosshair, { 1,1 }, {255,255,255,128});
}
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) });
@ -2045,9 +2055,11 @@ void FaceBall::RunEnemyAI(Enemy& e,float fElapsedTime,int myIndex) {
bool FaceBall::OnUserUpdate(float fElapsedTime)
{
fElapsedTime = std::min(0.01667f, fElapsedTime);
gameTimer += fElapsedTime;
switch (mode) {
case GAME: {
hudDisplayText = "";
for (std::vector<Bullet>::iterator it = bullets.begin(); it != bullets.end();) {
Bullet& b = *it;
if (!b.Update(fElapsedTime)) {
@ -2078,6 +2090,7 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
vec3d vForward = Vector_Mul(vLookDir, std::min(player.GetRadius() - 0.00001f, moveSpd * fElapsedTime));
if (CheckPowerupCollision({ vForward.x,0,vForward.z }, { player.GetPos().x,player.GetPos().z }, player.GetRadius() * 1.25) != -1) {
powerups[lastPowerupCollidedWith].opened = true;
hudDisplayText = powerupData[powerups[lastPowerupCollidedWith].type].name;
if (GetKey(F).bPressed) {
powerups.erase(powerups.begin() + lastPowerupCollidedWith);
lastPowerupCollidedWith = -1;

@ -84,7 +84,7 @@ struct Mesh
private:
void Parse(std::string str, int& v, int& uv) {
std::cout << str << "\n";
//std::cout << str << "\n";
std::stringstream s(str.substr(0, str.find("/") + 1));
s >> v;
str.erase(0, str.find("/") + 1);
@ -110,14 +110,14 @@ private:
float x, y, z;
f >> x >> y >> z;
verts.push_back({ x,y,z });
std::cout << x << " " << y << " " << z << "\n";
//std::cout << x << " " << y << " " << z << "\n";
}
else
if (data == "vt") {
float u, v;
f >> u >> v;
uvs.push_back({ u,1 - v });
std::cout << u << " " << v << "\n";
//std::cout << u << " " << v << "\n";
}
else
if (data == "f") {
@ -178,6 +178,11 @@ struct Powerup : Object {
bool Update(float fElapsedTime);
};
struct PowerupData {
std::string name;
Pixel col;
};
struct EnemyData {
std::string name;
Mesh mesh;
@ -258,7 +263,7 @@ class FaceBall : public PixelGameEngine
EnemyData GetData(EnemyID id);
Decal* circle,*arrow,*YAZAWA;
std::map<EnemyID, EnemyData>enemyData;
std::map<PowerupType, Pixel>powerupColorData;
std::map<PowerupType, PowerupData>powerupData;
std::vector<Enemy>enemies;
std::vector<Powerup>powerups;
private:
@ -281,6 +286,7 @@ class FaceBall : public PixelGameEngine
int lives = 3;
double gameTimer = 0;
int lastPowerupCollidedWith = -1;
std::string hudDisplayText = "";
mat4x4 matProj;

Loading…
Cancel
Save