Compare commits

...

4 Commits

  1. BIN
      Faceball2030/assets/enemies/IShoot.png
  2. 2
      Faceball2030/assets/map/map1.map
  3. 109
      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
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,51 @@ 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);
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){
@ -1626,6 +1675,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,6 +1747,9 @@ bool FaceBall::OnUserCreate()
mapWalls.texture = wall_tex;
mapFloor.texture = floor_tex;
mapSpr=new Sprite(minimapGridSize.x*20,minimapGridSize.y*20);
mapDecal=new Decal(mapSpr);
InitializeEnemyData();
InitializePowerupColors();
@ -1800,20 +1856,23 @@ bool Bullet::Update(float fElapsedTime) {
}
void FaceBall::HurtPlayer(EnemyID id,int damage,bool blinking) {
if (shieldDuration >= 0) {
damage = 0;
}
hp = std::max(0, hp - damage);
if (hp <= 0) {
respawnTimer = 3.0f;
}
lastHitBy = id;
lastHitByBlinking = blinking;
if (shieldDuration < 0) {
screenCol = enemyData[lastHitBy].col;
}
else {
screenCol = WHITE;
if (respawnTimer<=0.0f){
if (shieldDuration >= 0) {
damage = 0;
}
hp = std::max(0, hp - damage);
if (hp <= 0) {
RegenerateMinimap();
respawnTimer = 3.0f;
}
lastHitBy = id;
lastHitByBlinking = blinking;
if (shieldDuration < 0) {
screenCol = enemyData[lastHitBy].col;
}
else {
screenCol = WHITE;
}
}
}
@ -1936,6 +1995,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) {
@ -1982,6 +2042,10 @@ void FaceBall::RenderHud(float fElapsedTime) {
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);
}
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);
}
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;
case ISHOOT: {
case ISHOOT:
case ISHOOT_MAP: {
e.rot += dat.rotSpd * fElapsedTime;
if (e.CanShoot()) {
e.ShootBullet(myIndex);
@ -2149,9 +2214,19 @@ 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)
{
fElapsedTime = std::min(0.01667f, fElapsedTime);
@ -2178,6 +2253,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;
}
}
@ -2189,6 +2265,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;
}
}
@ -2204,6 +2281,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;
}
}
@ -2270,6 +2348,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.
@ -263,6 +264,11 @@ class FaceBall : public PixelGameEngine
enemy_Sonar, mapExit,enemy_ShootMe2,powerup,powerup2,
enemy_IShoot;
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,
@ -335,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;
@ -431,4 +438,6 @@ class FaceBall : public PixelGameEngine
vf2d GetPlayerPos();
void AddScore(int score);
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