lot of changes in floors
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "enemy.hpp"
|
||||
#include "../utils.hpp"
|
||||
|
||||
#include <loaders/md2_loader.hpp>
|
||||
#include <loaders/bmp_loader.hpp>
|
||||
@@ -27,20 +28,20 @@ Enemy::Enemy(TextureRepository *t_texRepo)
|
||||
meshes = new Mesh[getMeshesCount()];
|
||||
|
||||
meshes[0].loadMD2("poss/", "poss_head", 0.3F, false);
|
||||
meshes[0].position.set(0.00F, 40.00F, 0.00F);
|
||||
meshes[0].rotation.x = -1.566F;
|
||||
meshes[0].rotation.z = 1.566F;
|
||||
|
||||
meshes[1].loadMD2("poss/", "poss_body", 0.3F, false);
|
||||
meshes[1].position.set(0.00F, 40.00F, 0.00F);
|
||||
meshes[1].rotation.x = -1.566F;
|
||||
meshes[1].rotation.z = 1.566F;
|
||||
|
||||
meshes[2].loadMD2("poss/", "poss_weapon", 0.3F, false);
|
||||
meshes[2].position.set(0.00F, 40.00F, 0.00F);
|
||||
meshes[2].rotation.x = -1.566F;
|
||||
meshes[2].rotation.z = 1.566F;
|
||||
|
||||
Vector3 initPos = Vector3(0.00F, 40.00F, 0.00F);
|
||||
setPosition(initPos);
|
||||
|
||||
t_texRepo->addByMesh("poss/", meshes[0], PNG);
|
||||
t_texRepo->addByMesh("poss/", meshes[1], PNG);
|
||||
t_texRepo->addByMesh("poss/", meshes[2], PNG);
|
||||
@@ -49,6 +50,8 @@ Enemy::Enemy(TextureRepository *t_texRepo)
|
||||
meshes[1].playAnimation(1, 6);
|
||||
meshes[2].playAnimation(1, 6);
|
||||
|
||||
isKilled = true;
|
||||
|
||||
PRINT_LOG("Enemy object created!");
|
||||
}
|
||||
|
||||
@@ -61,12 +64,40 @@ Enemy::~Enemy()
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
/** Called by player class. */
|
||||
void Enemy::kill(const Player &player) const
|
||||
void Enemy::setPosition(const Vector3 &t_vec)
|
||||
{
|
||||
printf("killed!\n");
|
||||
position.set(t_vec);
|
||||
for (u8 i = 0; i < getMeshesCount(); i++)
|
||||
meshes[i].position.set(t_vec);
|
||||
}
|
||||
|
||||
void Enemy::setPosition(const float &t_y)
|
||||
{
|
||||
position.y = t_y;
|
||||
for (u8 i = 0; i < getMeshesCount(); i++)
|
||||
meshes[i].position.y = t_y;
|
||||
}
|
||||
|
||||
/** Called by player class. */
|
||||
void Enemy::kill(const Player &player)
|
||||
{
|
||||
isKilled = true;
|
||||
}
|
||||
|
||||
void Enemy::update(const FloorManager &floorManager)
|
||||
{
|
||||
if (isKilled)
|
||||
{
|
||||
isKilled = false;
|
||||
int randFloor = rand() % (floorManager.floorAmount + 1);
|
||||
currentFloor = &floorManager.floors[randFloor];
|
||||
setPosition(currentFloor->mesh.position);
|
||||
}
|
||||
updateGravity();
|
||||
}
|
||||
|
||||
void Enemy::updateGravity()
|
||||
{
|
||||
Utils::getMinMax(currentFloor->mesh, currFloorMin, currFloorMax);
|
||||
setPosition(currFloorMax.y);
|
||||
}
|
||||
|
||||
@@ -26,13 +26,19 @@ public:
|
||||
|
||||
inline Mesh *getMeshes() const { return meshes; }
|
||||
inline u8 getMeshesCount() const { return 3; }
|
||||
inline Vector3 &getPosition() const { return meshes[1].position; }
|
||||
void kill(const Player &player) const;
|
||||
inline Vector3 getPosition() const { return position; }
|
||||
void setPosition(const Vector3 &t_vec);
|
||||
void setPosition(const float &t_y);
|
||||
void kill(const Player &player);
|
||||
void update(const FloorManager &t_floorManager);
|
||||
|
||||
private:
|
||||
/** 0 - head, 1 - body, 2 - weapon */
|
||||
Mesh *meshes;
|
||||
const Floor *currentFloor;
|
||||
Vector3 position, currFloorMin, currFloorMax;
|
||||
u8 isKilled;
|
||||
void updateGravity();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "player.hpp"
|
||||
#include "../utils.hpp"
|
||||
|
||||
#include <loaders/md2_loader.hpp>
|
||||
#include <loaders/bmp_loader.hpp>
|
||||
@@ -27,6 +28,7 @@ Player::Player(Audio *t_audio)
|
||||
gravity = 0.1F;
|
||||
lift = -1.0F;
|
||||
jumpCounter = 0;
|
||||
speed = 1.0F;
|
||||
killedEnemies = 0;
|
||||
isWalking = false;
|
||||
isFighting = false;
|
||||
@@ -45,6 +47,7 @@ Player::Player(Audio *t_audio)
|
||||
|
||||
walkAdpcm = audio->loadADPCM("walk.adpcm");
|
||||
jumpAdpcm = audio->loadADPCM("jump.adpcm");
|
||||
boomAdpcm = audio->loadADPCM("boom.adpcm");
|
||||
audio->setADPCMVolume(60, 0);
|
||||
|
||||
PRINT_LOG("Player object created!");
|
||||
@@ -59,7 +62,7 @@ Player::~Player()
|
||||
// ----
|
||||
|
||||
/** Update player position and control gravity */
|
||||
void Player::update(const Pad &t_pad, const Camera &t_camera, const FloorManager &floorManager, const Enemy &enemy)
|
||||
void Player::update(const Pad &t_pad, const Camera &t_camera, const FloorManager &floorManager, Enemy &enemy)
|
||||
{
|
||||
Vector3 *nextPos = getNextPosition(t_pad, t_camera);
|
||||
FloorsCheck *floorsCheck = checkFloors(floorManager, *nextPos);
|
||||
@@ -76,6 +79,7 @@ Vector3 *Player::getNextPosition(const Pad &t_pad, const Camera &t_camera)
|
||||
Vector3 *result = new Vector3(mesh.position);
|
||||
Vector3 normalizedCamera = Vector3(t_camera.unitCirclePosition);
|
||||
normalizedCamera.normalize();
|
||||
normalizedCamera *= speed;
|
||||
if (t_pad.lJoyV <= 100)
|
||||
{
|
||||
result->x += -normalizedCamera.x;
|
||||
@@ -100,7 +104,7 @@ Vector3 *Player::getNextPosition(const Pad &t_pad, const Camera &t_camera)
|
||||
}
|
||||
|
||||
/** Move player when pad move buttons are pressed and is not blocked by any floor side */
|
||||
void Player::updatePosition(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, const FloorsCheck &t_floorsCheck, const Vector3 &t_nextPos, const Enemy &enemy)
|
||||
void Player::updatePosition(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, const FloorsCheck &t_floorsCheck, const Vector3 &t_nextPos, Enemy &enemy)
|
||||
{
|
||||
if (t_pad.rJoyH >= 200)
|
||||
mesh.rotation.z += 0.08;
|
||||
@@ -121,9 +125,11 @@ void Player::updatePosition(const Pad &t_pad, const Camera &t_camera, const Floo
|
||||
if (fightTimer.getTimeDelta() > 25000)
|
||||
{ // end of fighting
|
||||
float distance = getPosition().distanceTo(enemy.getPosition());
|
||||
if (12.0F > distance)
|
||||
if (16.0F > distance)
|
||||
{
|
||||
enemy.kill(*this);
|
||||
audio->playADPCM(boomAdpcm);
|
||||
speed += .5F;
|
||||
killedEnemies++;
|
||||
}
|
||||
isFightingAnimationSet = false;
|
||||
@@ -207,7 +213,7 @@ FloorsCheck *Player::checkFloors(const FloorManager &t_floorManager, const Vecto
|
||||
Vector3 max = Vector3();
|
||||
for (u32 i = 0; i < t_floorManager.floorAmount; i++)
|
||||
{
|
||||
getMinMax(t_floorManager.floors[i].mesh, min, max);
|
||||
Utils::getMinMax(t_floorManager.floors[i].mesh, min, max);
|
||||
if (result->currentFloor == NULL && this->mesh.position.isOnSquare(min, max))
|
||||
{
|
||||
result->currentFloor = &t_floorManager.floors[i];
|
||||
@@ -225,39 +231,3 @@ FloorsCheck *Player::checkFloors(const FloorManager &t_floorManager, const Vecto
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Calculates minimum and maximum X, Y, Z of mesh vertices + current position */
|
||||
void Player::getMinMax(const Mesh &t_mesh, Vector3 &t_min, Vector3 &t_max)
|
||||
{
|
||||
Vector3 calc = Vector3();
|
||||
u8 isInitialized = 0;
|
||||
Vector3 *boundingBox = t_mesh.getCurrentBoundingBox();
|
||||
for (u32 i = 0; i < 8; i++)
|
||||
{
|
||||
calc.set(
|
||||
boundingBox[i].x + t_mesh.position.x,
|
||||
boundingBox[i].y + t_mesh.position.y,
|
||||
boundingBox[i].z + t_mesh.position.z);
|
||||
if (isInitialized == 0)
|
||||
{
|
||||
isInitialized = 1;
|
||||
t_min.set(calc);
|
||||
t_max.set(calc);
|
||||
}
|
||||
|
||||
if (t_min.x > calc.x)
|
||||
t_min.x = calc.x;
|
||||
if (calc.x > t_max.x)
|
||||
t_max.x = calc.x;
|
||||
|
||||
if (t_min.y > calc.y)
|
||||
t_min.y = calc.y;
|
||||
if (calc.y > t_max.y)
|
||||
t_max.y = calc.y;
|
||||
|
||||
if (t_min.z > calc.z)
|
||||
t_min.z = calc.z;
|
||||
if (calc.z > t_max.z)
|
||||
t_max.z = calc.z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,10 @@ public:
|
||||
Player(Audio *t_audio);
|
||||
~Player();
|
||||
|
||||
void update(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, const Enemy &enemy);
|
||||
void update(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, Enemy &enemy);
|
||||
void onBeforePlayerFloorMove(Floor *t_floor, float &t_newY);
|
||||
const inline u32 &getJumpCount() const { return jumpCounter; }
|
||||
const inline u32 &getKilledEnemiesCount() const { return killedEnemies; }
|
||||
inline const Vector3 &getPosition() const { return mesh.position; }
|
||||
|
||||
private:
|
||||
@@ -49,9 +50,10 @@ private:
|
||||
u8 isFighting, isWalking;
|
||||
Audio *audio;
|
||||
Timer walkTimer, fightTimer;
|
||||
audsrv_adpcm_t *walkAdpcm, *jumpAdpcm;
|
||||
audsrv_adpcm_t *walkAdpcm, *jumpAdpcm, *boomAdpcm;
|
||||
float speed;
|
||||
void getMinMax(const Mesh &t_mesh, Vector3 &t_min, Vector3 &t_max);
|
||||
void updatePosition(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, const FloorsCheck &t_floorsCheck, const Vector3 &nextPos, const Enemy &enemy);
|
||||
void updatePosition(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, const FloorsCheck &t_floorsCheck, const Vector3 &nextPos, Enemy &enemy);
|
||||
void updateGravity(FloorsCheck *t_floorsCheck);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user