lot of changes in floors

This commit is contained in:
h4570
2020-12-07 20:47:41 +01:00
parent cad2623649
commit dd49fc165e
13 changed files with 190 additions and 59 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ void Camera::update(Pad &t_pad, Mesh &t_mesh)
*/
void Camera::rotate(Pad &t_pad)
{
if (t_pad.rJoyH <= 50)
if (t_pad.rJoyH <= 100)
horizontalLevel -= 0.08;
else if (t_pad.rJoyH >= 200)
horizontalLevel += 0.08;
+16 -3
View File
@@ -36,14 +36,15 @@ Floors::~Floors()
void Floors::onInit()
{
setBgColorAndAmbientColor();
engine->renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes);
engine->audio.addSongListener(this);
engine->audio.loadSong("nob-else.wav");
engine->audio.loadSong("mafikizolo-loot.wav");
engine->audio.playSong();
texRepo = engine->renderer->getTextureRepository();
enemy = new Enemy(texRepo);
ui = new Ui(texRepo);
engine->audio.setSongVolume(20);
engine->audio.setSongVolume(80);
texRepo->addByMesh("warrior/", player.mesh, BMP);
texRepo->addByMesh("floor/", floorManager.floors[0].mesh, BMP);
@@ -55,6 +56,7 @@ void Floors::onInit()
void Floors::onUpdate()
{
ui->update(player);
enemy->update(floorManager);
lightManager.update();
camera.update(engine->pad, player.mesh);
floorManager.update(player);
@@ -68,7 +70,7 @@ void Floors::onUpdate()
void Floors::onAudioTick()
{
if ((++audioTicks + 20) % 28 == 0)
if ((++audioTicks + 20) % 21 == 0)
{
if (skip1Beat)
floorManager.onAudioTick();
@@ -79,6 +81,17 @@ void Floors::onAudioTick()
audioTicks = 0;
}
void Floors::setBgColorAndAmbientColor()
{
color_t bgColor;
bgColor.r = 0x20;
bgColor.g = 0x20;
bgColor.b = 0x20;
engine->renderer->setWorldColor(bgColor);
Vector3 ambient = Vector3(0.003F, 0.003F, 0.003F);
engine->renderer->setAmbientLight(ambient);
}
void Floors::onAudioFinish()
{
audioTicks = 0;
+1
View File
@@ -37,6 +37,7 @@ public:
Engine *engine;
private:
void setBgColorAndAmbientColor();
u32 audioTicks;
u8 skip1Beat;
TextureRepository *texRepo;
+61 -3
View File
@@ -27,6 +27,10 @@ FloorManager::FloorManager(int t_floorAmount)
int floorSpiralMaxOffset = (int)Math::sqrt(t_floorAmount);
calcSpiral(floorSpiralMaxOffset, floorSpiralMaxOffset);
initFloors();
trick = 0.0F;
trickMode = 0;
isTimeForChangeTriggerColor = true;
isTimeForChangeDefaultColor = true;
audioOffset = audioMode = audioTick = 0;
}
@@ -92,15 +96,65 @@ void FloorManager::initFloors()
*/
void FloorManager::update(Player &t_player)
{
if (isTimeForChangeTriggerColor)
{
isTimeForChangeTriggerColor = false;
trigColor.r = rand() % (128 - 64 + 1) + 64;
trigColor.g = rand() % (128 - 64 + 1) + 64;
trigColor.b = rand() % (128 - 64 + 1) + 64;
}
if (isTimeForChangeDefaultColor)
{
isTimeForChangeDefaultColor = false;
defaultColor.r = rand() % (64 + 1);
defaultColor.g = rand() % (64 + 1);
defaultColor.b = rand() % (64 + 1);
}
doTheTrick();
for (u16 i = 0; i < floorAmount; i++)
{
floors[i].animate(t_player);
if (floors[i].isByAudioTriggered)
floors[i].mesh.color.a = 0x20;
else
floors[i].mesh.color.a = 0x80;
{
floors[i].mesh.color.r = trigColor.r;
floors[i].mesh.color.g = trigColor.g;
floors[i].mesh.color.b = trigColor.b;
}
else
{
floors[i].mesh.color.r = defaultColor.r;
floors[i].mesh.color.g = defaultColor.g;
floors[i].mesh.color.b = defaultColor.b;
}
}
}
void FloorManager::doTheTrick()
{
if (trickMode == 0)
{
if (trick > 3.0F)
{
isTimeForChangeTriggerColor = true;
trickMode = 1;
}
trick += 0.01F;
}
else if (trickMode == 1)
{
if (trick <= 0.1F)
{
isTimeForChangeTriggerColor = true;
trickMode = 0;
}
trick -= 0.01F;
}
floors[0].mesh.getFrames()[0].getST(1).set(trick, trick);
floors[0].mesh.getFrames()[0].getST(4).set(trick, trick);
floors[0].mesh.getFrames()[0].getST(7).set(trick, trick);
floors[0].mesh.getFrames()[0].getST(10).set(trick, trick);
floors[0].mesh.getFrames()[0].getST(13).set(trick, trick);
}
/** Called by audio thread */
@@ -120,6 +174,7 @@ void FloorManager::onAudioTick()
if (++audioOffset > 3)
{
audioOffset = 0;
isTimeForChangeDefaultColor = true;
audioMode = 1;
}
}
@@ -135,6 +190,7 @@ void FloorManager::onAudioTick()
if (++audioOffset > 3)
{
audioOffset = 0;
isTimeForChangeDefaultColor = true;
audioMode = 2;
}
}
@@ -150,6 +206,7 @@ void FloorManager::onAudioTick()
if (++audioOffset > 3)
{
audioOffset = 0;
isTimeForChangeDefaultColor = true;
audioMode = 3;
}
}
@@ -165,6 +222,7 @@ void FloorManager::onAudioTick()
if (++audioOffset > 3)
{
audioOffset = 0;
isTimeForChangeDefaultColor = true;
audioMode = 0;
}
}
@@ -34,8 +34,13 @@ public:
private:
u8 audioOffset, audioMode;
u32 audioTick;
float trick;
u8 isTimeForChangeTriggerColor, isTimeForChangeDefaultColor;
color_t trigColor, defaultColor;
u8 trickMode;
Point *spirals;
void calcSpiral(int X, int Y);
void doTheTrick();
void initFloors();
};
@@ -142,7 +142,7 @@ void LightManager::onAudioTick()
}
else
{
bulbs[0].intensity += 6;
bulbs[1].intensity += 6;
bulbs[0].intensity += 9;
bulbs[1].intensity += 9;
}
}
+37 -6
View File
@@ -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);
}
+8 -2
View File
@@ -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
+10 -40
View File
@@ -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;
}
}
+5 -3
View File
@@ -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);
};
+6
View File
@@ -60,6 +60,12 @@ void Ui::update(const Player &player)
grayCheckboxTex->removeLinkBySprite(task1Checkbox.getId());
blueCheckboxTex->addLink(task1Checkbox.getId());
}
if (!isTask2Done && player.getKilledEnemiesCount() >= 10)
{
isTask2Done = true;
grayCheckboxTex->removeLinkBySprite(task2Checkbox.getId());
blueCheckboxTex->addLink(task2Checkbox.getId());
}
}
void Ui::render(Renderer *t_renderer)
+36
View File
@@ -32,3 +32,39 @@ float Utils::expoEaseInOut(float t, float b, float c, float d)
return c / 2 * (-powf(2, -10 * --t) + 2) + b;
}
/** Calculates minimum and maximum X, Y, Z of mesh vertices + current position */
void Utils::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;
}
}
+3
View File
@@ -12,12 +12,15 @@
#define _TYRA_UTILS_
#include <tamtypes.h>
#include <models/mesh.hpp>
#include <models/math/vector3.hpp>
class Utils
{
public:
static float expoEaseInOut(float t, float b, float c, float d);
static void getMinMax(const Mesh &t_mesh, Vector3 &t_min, Vector3 &t_max);
};
#endif