Added: Mines now explode and hurt the player, added new makefile and made more mines spawn on game start.
This commit is contained in:
@@ -6,6 +6,7 @@ EE_OBJS = \
|
||||
camera.o \
|
||||
objects/player.o \
|
||||
objects/collectible.o \
|
||||
objects/mine.o \
|
||||
dolphin.o \
|
||||
main.o
|
||||
|
||||
|
||||
@@ -14,13 +14,15 @@
|
||||
const u8 WATER_TILE_SCALE = 5;
|
||||
const u8 WATER_SIZE = 100;
|
||||
|
||||
const u8 OYSTERS_COUNT = 15;
|
||||
const u8 MINES_COUNT = 15;
|
||||
const u8 OYSTERS_COUNT = 5;
|
||||
|
||||
float Dolphin::engineFPS = 60.F;
|
||||
|
||||
Dolphin::Dolphin(Engine *t_engine) : engine(t_engine), camera(&engine->screen)
|
||||
{
|
||||
oysters = new Collectible[OYSTERS_COUNT];
|
||||
mines = new Mine[MINES_COUNT];
|
||||
}
|
||||
|
||||
Dolphin::~Dolphin() {}
|
||||
@@ -37,6 +39,7 @@ void Dolphin::onInit()
|
||||
surfaceAmbient = engine->audio.loadADPCM("sound/surface.sad");
|
||||
underwaterAmbient = engine->audio.loadADPCM("sound/underwater.sad");
|
||||
pickupSound = engine->audio.loadADPCM("sound/pickup.sad");
|
||||
boomSound = engine->audio.loadADPCM("sound/boom.sad");
|
||||
|
||||
engine->audio.playADPCM(surfaceAmbient, 0);
|
||||
engine->audio.playADPCM(underwaterAmbient, 1);
|
||||
@@ -74,10 +77,6 @@ void Dolphin::onInit()
|
||||
seabed.shouldBeBackfaceCulled = false;
|
||||
seabed.shouldBeFrustumCulled = false;
|
||||
|
||||
mine.loadObj("mine/", "mine", 5.0F, false);
|
||||
mine.position.set(0, 0, 0);
|
||||
texRepo->addByMesh("mine/", mine, BMP);
|
||||
|
||||
skybox.loadObj("skybox/", "skybox", 400.0F, false);
|
||||
skybox.shouldBeFrustumCulled = false;
|
||||
|
||||
@@ -107,6 +106,25 @@ void Dolphin::onInit()
|
||||
oysters[i].mesh.position.set(i * -100, 5.0F, i * -100);
|
||||
}
|
||||
|
||||
printf("Loading mine .obj\n");
|
||||
mines[0].mesh.loadObj("mine/", "mine", 10.F, false);
|
||||
printf("Loaded.");
|
||||
mines[0].mesh.shouldBeBackfaceCulled = false;
|
||||
mines[0].mesh.shouldBeFrustumCulled = false;
|
||||
mines[0].mesh.position.set(5, -15, 32);
|
||||
texRepo->addByMesh("mine/", mines[0].mesh, BMP);
|
||||
printf("Adding mine texture.\n");
|
||||
for (int i = 1; i < MINES_COUNT; i++)
|
||||
{
|
||||
printf("Processing mine %d\n", i);
|
||||
mines[i].mesh.loadFrom(mines[0].mesh);
|
||||
mines[i].mesh.shouldBeBackfaceCulled = false;
|
||||
mines[i].mesh.shouldBeFrustumCulled = false;
|
||||
texRepo->getByMesh(mines[0].mesh.getId(), mines[0].mesh.getMaterial(0).getId())
|
||||
->addLink(mines[i].mesh.getId(), mines[i].mesh.getMaterial(0).getId());
|
||||
mines[i].mesh.position.set(i * -10, 0.0F, i * -68);
|
||||
}
|
||||
|
||||
Texture *pLifeTex = texRepo->add("2d/", "life", PNG);
|
||||
//pLifeTex->addLink(lifeSprites[0].getId());
|
||||
for (int i = 0; i < 3; i++)
|
||||
@@ -129,6 +147,7 @@ void Dolphin::onInit()
|
||||
|
||||
void Dolphin::onUpdate()
|
||||
{
|
||||
|
||||
Dolphin::engineFPS = engine->fps;
|
||||
if (engine->pad.isCrossClicked)
|
||||
printf("Delta multiplier: %f\n", 60.0F / engine->fps);
|
||||
@@ -155,11 +174,32 @@ void Dolphin::onUpdate()
|
||||
{
|
||||
printf("Pickup %d Dist %d\n", i, dist);
|
||||
oysters[i].disappear();
|
||||
player.setLife(player.getLifes() + 1);
|
||||
engine->audio.setADPCMVolume(30, 3);
|
||||
engine->audio.playADPCM(pickupSound, 3);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MINES_COUNT; i++)
|
||||
{
|
||||
mines[i].update();
|
||||
Vector3 vecDist = mines[i].mesh.position - player.mesh.position;
|
||||
float dist = Math::sqrt((vecDist.x * vecDist.x) +
|
||||
(vecDist.y * vecDist.y) +
|
||||
(vecDist.z * vecDist.z));
|
||||
if (dist < 20.F && !mines[i].getExplosionTicks())
|
||||
{
|
||||
printf("Vecdist %f,%f,%f\n", vecDist.x, vecDist.y, vecDist.z);
|
||||
printf("Explode %d Dist %d\n", i, dist);
|
||||
mines[i].explode();
|
||||
player.setLife(player.getLifes() - 1);
|
||||
//Buffer switching to prevent playing two sounds on one buffer
|
||||
engine->audio.setADPCMVolume(65, Mine::lastSoundBuffer);
|
||||
engine->audio.playADPCM(boomSound, Mine::lastSoundBuffer);
|
||||
Mine::lastSoundBuffer = Mine::lastSoundBuffer == 4 ? 5 : 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (player.mesh.position.y > WATER_LEVEL - 5)
|
||||
player.mesh.position.y = WATER_LEVEL - 5;
|
||||
|
||||
@@ -172,7 +212,6 @@ void Dolphin::onUpdate()
|
||||
engine->renderer->draw(skybox);
|
||||
engine->renderer->draw(waterbox);
|
||||
engine->renderer->draw(seabed);
|
||||
engine->renderer->draw(mine);
|
||||
for (u8 i = 0; i < OYSTERS_COUNT; i++)
|
||||
{
|
||||
if (oysters[i].isActive())
|
||||
@@ -180,6 +219,11 @@ void Dolphin::onUpdate()
|
||||
engine->renderer->draw(oysters[i].mesh);
|
||||
}
|
||||
}
|
||||
for (u8 i = 0; i < MINES_COUNT; i++)
|
||||
{
|
||||
if (mines[i].getExplosionTicks() < MINE_EXPLOSION_TICKS)
|
||||
engine->renderer->draw(mines[i].mesh);
|
||||
}
|
||||
for (u8 i = 0; i < player.getLifes(); i++)
|
||||
{
|
||||
engine->renderer->draw(lifeSprites[i]);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "./camera.hpp"
|
||||
#include "./objects/player.hpp"
|
||||
#include "./objects/collectible.hpp"
|
||||
#include "./objects/mine.hpp"
|
||||
|
||||
class Dolphin : public Game
|
||||
{
|
||||
@@ -51,8 +52,11 @@ private:
|
||||
Mesh water;
|
||||
Mesh waterbox;
|
||||
Sprite lifeSprites[3];
|
||||
Sprite gameOver;
|
||||
audsrv_adpcm_t *underwaterAmbient, *surfaceAmbient;
|
||||
audsrv_adpcm_t *pickupSound;
|
||||
audsrv_adpcm_t *boomSound;
|
||||
Mine *mines;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,7 @@ Player::Player()
|
||||
mesh.shouldBeFrustumCulled = false;
|
||||
mesh.position.set(0.0F, 0.0F, 10.0f);
|
||||
mesh.rotation.x = -1.6F;
|
||||
mesh.setAnimSpeed(0.05F);
|
||||
mesh.setAnimSpeed(0.04F);
|
||||
bIsJumping = false;
|
||||
lifes = 3;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
void update(Pad &t_pad);
|
||||
const u8 &isJumping() { return bIsJumping; }
|
||||
const u8 &getLifes() { return lifes; }
|
||||
void setLife(const u8 &l) { lifes = lifes = l < 4 ? l : 3; }
|
||||
|
||||
private:
|
||||
u8 bIsJumping;
|
||||
|
||||
Reference in New Issue
Block a user