From 94e4f8ea3a36c5a50d0a283b5780a0e2f395ece5 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sun, 6 Dec 2020 16:40:13 +0100 Subject: [PATCH 01/16] fixed camera movement speed --- src/samples/floors/camera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/samples/floors/camera.cpp b/src/samples/floors/camera.cpp index b31d307..c55cad0 100644 --- a/src/samples/floors/camera.cpp +++ b/src/samples/floors/camera.cpp @@ -51,7 +51,7 @@ void Camera::rotate(Pad &t_pad) if (t_pad.rJoyH <= 50) horizontalLevel -= 0.08; else if (t_pad.rJoyH >= 200) - horizontalLevel += 0.04; + horizontalLevel += 0.08; if (t_pad.rJoyV <= 50 && verticalLevel > 25.0F) verticalLevel -= 0.9F; else if (t_pad.rJoyV >= 200 && verticalLevel < 80.0F) From bcad6f794104b0c72b8c11721065820533da8b11 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sun, 6 Dec 2020 16:41:40 +0100 Subject: [PATCH 02/16] added ui, enemy, sounds, fixed anims --- src/samples/floors/Makefile | 2 + src/samples/floors/floors.cpp | 34 +- src/samples/floors/floors.hpp | 5 + src/samples/floors/managers/floor_manager.cpp | 16 +- src/samples/floors/managers/floor_manager.hpp | 2 +- src/samples/floors/objects/enemy.cpp | 72 +++++ src/samples/floors/objects/enemy.hpp | 38 +++ src/samples/floors/objects/floor.hpp | 2 +- src/samples/floors/objects/player.cpp | 296 +++++++++++------- src/samples/floors/objects/player.hpp | 34 +- src/samples/floors/ui.cpp | 71 +++++ src/samples/floors/ui.hpp | 35 +++ 12 files changed, 470 insertions(+), 137 deletions(-) create mode 100644 src/samples/floors/objects/enemy.cpp create mode 100644 src/samples/floors/objects/enemy.hpp create mode 100644 src/samples/floors/ui.cpp create mode 100644 src/samples/floors/ui.hpp diff --git a/src/samples/floors/Makefile b/src/samples/floors/Makefile index 9379326..d49ca98 100644 --- a/src/samples/floors/Makefile +++ b/src/samples/floors/Makefile @@ -6,8 +6,10 @@ EE_OBJS = \ managers/light_manager.o \ managers/floor_manager.o \ camera.o \ + objects/enemy.o \ objects/floor.o \ objects/player.o \ + ui.o \ utils.o \ floors.o \ main.o diff --git a/src/samples/floors/floors.cpp b/src/samples/floors/floors.cpp index 4a7868b..97a2dc0 100644 --- a/src/samples/floors/floors.cpp +++ b/src/samples/floors/floors.cpp @@ -14,15 +14,21 @@ // Constructors/Destructors // ---- -const u8 FLOORS_COUNT = 144; // Temp change it also in floor_manager.hpp +const u16 FLOORS_COUNT = 144; // Temp change it also in floor_manager.hpp Floors::Floors(Engine *t_engine) - : engine(t_engine), floorManager(FLOORS_COUNT), camera(&t_engine->screen) + : engine(t_engine), floorManager(FLOORS_COUNT), + player(&t_engine->audio), camera(&t_engine->screen) { audioTicks = 0; + skip1Beat = 0; } -Floors::~Floors() {} +Floors::~Floors() +{ + delete enemy; + delete ui; +} // ---- // Methods @@ -32,10 +38,13 @@ void Floors::onInit() { engine->renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes); engine->audio.addSongListener(this); - engine->audio.loadSong("NF-CHILL.WAV"); - engine->audio.setSongVolume(100); + engine->audio.loadSong("nob-else.wav"); engine->audio.playSong(); texRepo = engine->renderer->getTextureRepository(); + enemy = new Enemy(texRepo); + ui = new Ui(texRepo); + engine->audio.setSongVolume(80); + texRepo->addByMesh("warrior/", player.mesh, BMP); texRepo->addByMesh("floor/", floorManager.floors[0].mesh, BMP); for (u32 i = 1; i < floorManager.floorAmount; i++) @@ -45,23 +54,26 @@ void Floors::onInit() void Floors::onUpdate() { - if (engine->pad.isCrossClicked) - printf("FPS:%f\n", engine->fps); + ui->update(player); lightManager.update(); camera.update(engine->pad, player.mesh); floorManager.update(player); - player.update(engine->pad, camera, floorManager); + player.update(engine->pad, camera, floorManager, *enemy); engine->renderer->draw(player.mesh); - for (u8 i = 0; i < FLOORS_COUNT; i++) + engine->renderer->draw(enemy->getMeshes(), enemy->getMeshesCount()); + for (u16 i = 0; i < FLOORS_COUNT; i++) engine->renderer->drawByPath3(floorManager.floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount); + ui->render(engine->renderer); // 2D rendering ist LAST step, because layers gonna play there. } void Floors::onAudioTick() { - if ((++audioTicks + 20) % 41 == 0) + if ((++audioTicks + 20) % 28 == 0) { - floorManager.onAudioTick(); + if (skip1Beat) + floorManager.onAudioTick(); lightManager.onAudioTick(); + skip1Beat = !skip1Beat; } if (audioTicks > 10000) audioTicks = 0; diff --git a/src/samples/floors/floors.hpp b/src/samples/floors/floors.hpp index 4652233..c5a68c4 100644 --- a/src/samples/floors/floors.hpp +++ b/src/samples/floors/floors.hpp @@ -18,7 +18,9 @@ #include "managers/light_manager.hpp" #include "modules/texture_repository.hpp" #include "objects/player.hpp" +#include "objects/enemy.hpp" #include "./camera.hpp" +#include "./ui.hpp" class Floors : public Game, AudioListener { @@ -36,11 +38,14 @@ public: private: u32 audioTicks; + u8 skip1Beat; TextureRepository *texRepo; LightManager lightManager; FloorManager floorManager; Player player; Camera camera; + Ui *ui; + Enemy *enemy; }; #endif diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index 0265b17..4e5ae0d 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -80,7 +80,7 @@ void FloorManager::initFloors() floors[0].mesh.loadObj("floor/", "floor", 3.0F, false); floors[0].mesh.shouldBeFrustumCulled = true; floors[0].mesh.shouldBeLighted = true; - for (u8 i = 1; i < floorAmount; i++) + for (u16 i = 1; i < floorAmount; i++) floors[i].init(floors[0].mesh, spirals[i], i); PRINT_LOG("Floors initialized!"); } @@ -92,7 +92,7 @@ void FloorManager::initFloors() */ void FloorManager::update(Player &t_player) { - for (u8 i = 0; i < floorAmount; i++) + for (u16 i = 0; i < floorAmount; i++) { floors[i].animate(t_player); @@ -106,11 +106,11 @@ void FloorManager::update(Player &t_player) /** Called by audio thread */ void FloorManager::onAudioTick() { - if (audioTick++ > 16) + if (audioTick++ > 13) { if (audioMode == 0) { - for (u8 i = 0; i < floorAmount; i++) + for (u16 i = 0; i < floorAmount; i++) { if ((i + audioOffset) % 2 == 0) floors[i].isByAudioTriggered = true; @@ -125,7 +125,7 @@ void FloorManager::onAudioTick() } else if (audioMode == 1) { - for (u8 i = 0; i < floorAmount; i++) + for (u16 i = 0; i < floorAmount; i++) { if (i < floorAmount / (audioOffset + 1)) floors[i].isByAudioTriggered = true; @@ -140,7 +140,7 @@ void FloorManager::onAudioTick() } else if (audioMode == 2) { - for (u8 i = 0; i < floorAmount; i++) + for (u16 i = 0; i < floorAmount; i++) { if ((i + audioOffset) % 4 == 0) floors[i].isByAudioTriggered = true; @@ -155,9 +155,9 @@ void FloorManager::onAudioTick() } else if (audioMode == 3) { - for (u8 i = 0; i < floorAmount; i++) + for (u16 i = 0; i < floorAmount; i++) { - if (u8(i + 1) > floorAmount / (audioOffset + 1)) + if (u16(i + 1) > floorAmount / (audioOffset + 1)) floors[i].isByAudioTriggered = true; else floors[i].isByAudioTriggered = false; diff --git a/src/samples/floors/managers/floor_manager.hpp b/src/samples/floors/managers/floor_manager.hpp index bd11897..847fdca 100644 --- a/src/samples/floors/managers/floor_manager.hpp +++ b/src/samples/floors/managers/floor_manager.hpp @@ -27,7 +27,7 @@ public: FloorManager(int t_floorAmount); ~FloorManager(); Floor floors[144]; // Temp change it also in floors.cpp - u32 floorAmount; + u16 floorAmount; void update(Player &t_player); void onAudioTick(); diff --git a/src/samples/floors/objects/enemy.cpp b/src/samples/floors/objects/enemy.cpp new file mode 100644 index 0000000..691723e --- /dev/null +++ b/src/samples/floors/objects/enemy.cpp @@ -0,0 +1,72 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "enemy.hpp" + +#include +#include +#include +#include +#include + +// ---- +// Constructors/Destructors +// ---- + +Enemy::Enemy(TextureRepository *t_texRepo) +{ + PRINT_LOG("Creating enemy object"); + + 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; + + t_texRepo->addByMesh("poss/", meshes[0], PNG); + t_texRepo->addByMesh("poss/", meshes[1], PNG); + t_texRepo->addByMesh("poss/", meshes[2], PNG); + + meshes[0].playAnimation(1, 6); + meshes[1].playAnimation(1, 6); + meshes[2].playAnimation(1, 6); + + PRINT_LOG("Enemy object created!"); +} + +Enemy::~Enemy() +{ + delete[] meshes; +} + +// ---- +// Methods +// ---- + +/** Called by player class. */ +void Enemy::kill(const Player &player) const +{ + printf("killed!\n"); +} + +void Enemy::update(const FloorManager &floorManager) +{ +} diff --git a/src/samples/floors/objects/enemy.hpp b/src/samples/floors/objects/enemy.hpp new file mode 100644 index 0000000..c5c298d --- /dev/null +++ b/src/samples/floors/objects/enemy.hpp @@ -0,0 +1,38 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#ifndef _ENEMY_ +#define _ENEMY_ + +#include +#include "../managers/floor_manager.hpp" +#include + +/** Player 3D object class */ +class Enemy +{ + +public: + s16 indexOfCurrentFloor; + Enemy(TextureRepository *t_texRepo); + ~Enemy(); + + 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; + void update(const FloorManager &t_floorManager); + +private: + /** 0 - head, 1 - body, 2 - weapon */ + Mesh *meshes; +}; + +#endif diff --git a/src/samples/floors/objects/floor.hpp b/src/samples/floors/objects/floor.hpp index 45d05b7..afd2fae 100644 --- a/src/samples/floors/objects/floor.hpp +++ b/src/samples/floors/objects/floor.hpp @@ -23,7 +23,7 @@ class Floor public: u16 animTimer; - u8 animDirection, initOffset, isByAudioTriggered; + s16 animDirection, initOffset, isByAudioTriggered; Mesh mesh; Floor(); diff --git a/src/samples/floors/objects/player.cpp b/src/samples/floors/objects/player.cpp index 10934ba..6a32148 100644 --- a/src/samples/floors/objects/player.cpp +++ b/src/samples/floors/objects/player.cpp @@ -10,7 +10,7 @@ #include "player.hpp" -#include +#include #include #include #include @@ -20,20 +20,33 @@ // Constructors/Destructors // ---- -Player::Player() +Player::Player(Audio *t_audio) { PRINT_LOG("Creating player object"); - this->gravity = 0.1F; - this->lift = -1.0F; + audio = t_audio; + gravity = 0.1F; + lift = -1.0F; + jumpCounter = 0; + killedEnemies = 0; + isWalking = false; + isFighting = false; + isWalkingAnimationSet = false; + isJumpingAnimationSet = false; + isFightingAnimationSet = false; - this->mesh.loadMD2("warrior/", "warrior", 0.2F, true); - this->mesh.position.set(0.00F, 20.00F, 0.00F); - this->mesh.rotation.x = -1.6F; - this->mesh.shouldBeBackfaceCulled = false; - this->mesh.shouldBeFrustumCulled = false; + mesh.loadMD2("warrior/", "warrior", 0.2F, true); + mesh.position.set(0.00F, 40.00F, 0.00F); + mesh.rotation.x = -1.566F; + mesh.rotation.z = 1.566F; + mesh.shouldBeBackfaceCulled = false; + mesh.shouldBeFrustumCulled = false; + mesh.setAnimSpeed(0.17F); + mesh.playAnimation(0, 0); + + walkAdpcm = audio->loadADPCM("walk.adpcm"); + jumpAdpcm = audio->loadADPCM("jump.adpcm"); + audio->setADPCMVolume(60, 0); - this->mesh.setAnimSpeed(0.2F); - this->mesh.playAnimation(0, 24); PRINT_LOG("Player object created!"); } @@ -46,138 +59,205 @@ Player::~Player() // ---- /** Update player position and control gravity */ -void Player::update(Pad &pad, Camera &camera, FloorManager &floorManager) +void Player::update(const Pad &t_pad, const Camera &t_camera, const FloorManager &floorManager, const Enemy &enemy) { - this->updatePosition(pad, camera, floorManager); - this->updateGravity(pad, floorManager); - if (mesh.position.y < -60.0F) + Vector3 *nextPos = getNextPosition(t_pad, t_camera); + FloorsCheck *floorsCheck = checkFloors(floorManager, *nextPos); + if (floorsCheck->currentFloor != NULL) + indexOfCurrentFloor = floorsCheck->currentFloor->initOffset; + updatePosition(t_pad, t_camera, floorManager, *floorsCheck, *nextPos, enemy); + updateGravity(floorsCheck); + delete floorsCheck; + delete nextPos; +} + +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(); + if (t_pad.lJoyV <= 100) { - mesh.position.y = 60.0F; - velocity = 0; + result->x += -normalizedCamera.x; + result->z += -normalizedCamera.z; } + else if (t_pad.lJoyV >= 200) + { + result->x += normalizedCamera.x; + result->z += normalizedCamera.z; + } + if (t_pad.lJoyH <= 100) + { + result->x += -normalizedCamera.z; + result->z += normalizedCamera.x; + } + else if (t_pad.lJoyH >= 200) + { + result->x += normalizedCamera.z; + result->z += -normalizedCamera.x; + } + return result; } /** Move player when pad move buttons are pressed and is not blocked by any floor side */ -void Player::updatePosition(Pad &pad, Camera &camera, FloorManager &floorManager) +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) { + if (t_pad.rJoyH >= 200) + mesh.rotation.z += 0.08; + else if (t_pad.rJoyH <= 100) + mesh.rotation.z -= 0.08; - if (pad.isDpadUpPressed == 1) + isWalking = mesh.position.x != t_nextPos.x || mesh.position.z != t_nextPos.z; + isFighting = isFighting || t_pad.isCircleClicked; + + if (isFighting) { - this->playerNextPosition.x = this->mesh.position.x + 0.01F * -camera.unitCirclePosition.x; - this->playerNextPosition.z = this->mesh.position.z + 0.01F * -camera.unitCirclePosition.z; + if (!isFightingAnimationSet) + { + isFightingAnimationSet = true; + mesh.playAnimation(8, 19, 0); + fightTimer.prime(); + } + if (fightTimer.getTimeDelta() > 25000) + { // end of fighting + float distance = getPosition().distanceTo(enemy.getPosition()); + if (12.0F > distance) + { + enemy.kill(*this); + killedEnemies++; + } + isFightingAnimationSet = false; + isFighting = false; + } } - if (pad.isDpadDownPressed == 1) + else if (isWalking) { - this->playerNextPosition.x = this->mesh.position.x + 0.01F * camera.unitCirclePosition.x; - this->playerNextPosition.z = this->mesh.position.z + 0.01F * camera.unitCirclePosition.z; + if (!isWalkingAnimationSet) + { + isWalkingAnimationSet = true; + this->mesh.playAnimation(1, 8); + } + if (walkTimer.getTimeDelta() > 8000) + { + walkTimer.prime(); + audio->playADPCM(walkAdpcm, 0); + } } - if (pad.isDpadLeftPressed == 1) + else { - this->playerNextPosition.x = this->mesh.position.x + 0.01F * -camera.unitCirclePosition.z; - this->playerNextPosition.z = this->mesh.position.z + 0.01F * camera.unitCirclePosition.x; + isWalkingAnimationSet = false; + mesh.playAnimation(0, 0); } - if (pad.isDpadRightPressed == 1) + + if (t_floorsCheck.willCollideFloor == NULL && !isFighting) { - this->playerNextPosition.x = this->mesh.position.x + 0.01F * camera.unitCirclePosition.z; - this->playerNextPosition.z = this->mesh.position.z + 0.01F * -camera.unitCirclePosition.x; + mesh.position.x = t_nextPos.x; + mesh.position.z = t_nextPos.z; } - this->playerNextPosition.y = this->mesh.position.y; - this->isCollideFloor = 0; - Vector3 min = Vector3(); - Vector3 max = Vector3(); - for (u32 i = 0; i < floorManager.floorAmount; i++) + + if (t_pad.isCrossClicked == 1) { - getMinMax(&floorManager.floors[i].mesh, &min, &max); - this->isCollideFloor = this->playerNextPosition.collidesSquare(min, max); - if (this->isCollideFloor == 1) - break; - } - if (this->isCollideFloor == 0) - { - this->mesh.position.x = this->playerNextPosition.x; - this->mesh.position.z = this->playerNextPosition.z; + velocity = lift; + audio->playADPCM(jumpAdpcm); + jumpCounter++; } } -/** Do not call this. +/** + * Do not call this. * This is called by Floor::animate() on player's floor move in Y direction */ -void Player::onBeforePlayerFloorMove(Floor *floor, float &newY) +void Player::onBeforePlayerFloorMove(Floor *t_floor, float &t_newY) { - if (floor->animDirection == 0 && newY > 0.0F) - this->mesh.position.y += newY * 1.05F; - else if ((floor->animDirection == 1 && -newY < 0.0F)) - this->mesh.position.y -= -newY * 1.05F; -} - -/** Calculates minimum and maximum X, Y, Z of mesh vertices + current position */ -void Player::getMinMax(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; - } + if (t_floor->animDirection == 0 && t_newY > 0.0F) + this->mesh.position.y += t_newY * 1.05F; + else if ((t_floor->animDirection == 1 && -t_newY < 0.0F)) + this->mesh.position.y -= -t_newY * 1.05F; } /** Update player position by gravity and update index of current floor */ -void Player::updateGravity(Pad &pad, FloorManager &floorManager) +void Player::updateGravity(FloorsCheck *t_floorsCheck) { - Vector3 min = Vector3(); - Vector3 max = Vector3(); - - if (pad.isCrossClicked == 1) - this->velocity = this->lift; - - this->isOnFloor = 0; - for (u32 i = 0; i < floorManager.floorAmount; i++) - { - getMinMax(&floorManager.floors[i].mesh, &min, &max); - this->isOnFloor = this->mesh.position.isOnSquare(min, max); - if (this->isOnFloor == 1) - { - this->indexOfCurrentFloor = floorManager.floors[i].initOffset; - break; - } - } - this->velocity += this->gravity; this->mesh.position.y -= this->velocity; + u8 isOnFloor = t_floorsCheck->currentFloor != NULL && mesh.position.y < t_floorsCheck->currFloorMax.y; - if (this->mesh.position.y >= 60.0F) + if (this->mesh.position.y >= 60.0F || mesh.position.y < -60.0F) { this->mesh.position.y = 60.0F; this->velocity = 0; } - else if ((this->mesh.position.y) < max.y && this->isOnFloor) + else if (isOnFloor) { - this->mesh.position.y = max.y; + this->mesh.position.y = t_floorsCheck->currFloorMax.y; this->velocity = 0; } } + +// --- +// Private +// --- + +FloorsCheck *Player::checkFloors(const FloorManager &t_floorManager, const Vector3 &t_nextPos) +{ + FloorsCheck *result = new FloorsCheck; + result->currentFloor = NULL; + result->willCollideFloor = NULL; + Vector3 min = Vector3(); + Vector3 max = Vector3(); + for (u32 i = 0; i < t_floorManager.floorAmount; i++) + { + getMinMax(t_floorManager.floors[i].mesh, min, max); + if (result->currentFloor == NULL && this->mesh.position.isOnSquare(min, max)) + { + result->currentFloor = &t_floorManager.floors[i]; + result->currFloorMin.set(min); + result->currFloorMax.set(max); + } + if (result->willCollideFloor == NULL && t_nextPos.collidesSquare(min, max)) + { + result->willCollideFloor = &t_floorManager.floors[i]; + result->willCollideFloorMin.set(min); + result->willCollideFloorMax.set(max); + } + if (result->currentFloor != NULL && result->willCollideFloor != NULL) + break; + } + 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; + } +} diff --git a/src/samples/floors/objects/player.hpp b/src/samples/floors/objects/player.hpp index c2cd3f8..c5386d4 100644 --- a/src/samples/floors/objects/player.hpp +++ b/src/samples/floors/objects/player.hpp @@ -13,8 +13,17 @@ #include "../managers/floor_manager.hpp" #include "../camera.hpp" +#include "./enemy.hpp" #include +#include #include +#include + +struct FloorsCheck +{ + const Floor *currentFloor, *willCollideFloor; + Vector3 currFloorMin, willCollideFloorMin, currFloorMax, willCollideFloorMax; +}; /** Player 3D object class */ class Player @@ -22,19 +31,28 @@ class Player public: float gravity, velocity, lift; - u8 isOnFloor, isCollideFloor, indexOfCurrentFloor; Mesh mesh; - Player(); + s16 indexOfCurrentFloor; + Player(Audio *t_audio); ~Player(); - void update(Pad &pad, Camera &camera, FloorManager &floorManager); - void onBeforePlayerFloorMove(Floor *floor, float &newY); + void update(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, const Enemy &enemy); + void onBeforePlayerFloorMove(Floor *t_floor, float &t_newY); + const inline u32 &getJumpCount() const { return jumpCounter; } + inline const Vector3 &getPosition() const { return mesh.position; } private: - Vector3 playerNextPosition; - void getMinMax(Mesh *t_mesh, Vector3 *t_min, Vector3 *t_max); - void updatePosition(Pad &pad, Camera &camera, FloorManager &floorManager); - void updateGravity(Pad &pad, FloorManager &floorManager); + u32 jumpCounter, killedEnemies; + Vector3 *getNextPosition(const Pad &t_pad, const Camera &t_camera); + FloorsCheck *checkFloors(const FloorManager &t_floorManager, const Vector3 &t_nextPos); + u8 isWalkingAnimationSet, isJumpingAnimationSet, isFightingAnimationSet; + u8 isFighting, isWalking; + Audio *audio; + Timer walkTimer, fightTimer; + audsrv_adpcm_t *walkAdpcm, *jumpAdpcm; + 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 updateGravity(FloorsCheck *t_floorsCheck); }; #endif diff --git a/src/samples/floors/ui.cpp b/src/samples/floors/ui.cpp new file mode 100644 index 0000000..97f4a53 --- /dev/null +++ b/src/samples/floors/ui.cpp @@ -0,0 +1,71 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#include "ui.hpp" + +#include + +// ---- +// Constructors/Destructors +// ---- + +Ui::Ui(TextureRepository *t_texRepo) +{ + PRINT_LOG("Initializing ui"); + + isTask1Done = false; + isTask2Done = false; + + task1.size.set(128.0F, 32.0F); + task1.position.set(500.0F, 10.0F); + + task2.size.set(128.0F, 32.0F); + task2.position.set(500.0F, 50.0F); + + task1Checkbox.size.set(32.0F, 32.0F); + task1Checkbox.position.set(460.0F, 10.0F); + + task2Checkbox.size.set(32.0F, 32.0F); + task2Checkbox.position.set(460.0F, 50.0F); + + t_texRepo->add("2d/", "check1_text", PNG)->addLink(task1.getId()); + t_texRepo->add("2d/", "check2_text", PNG)->addLink(task2.getId()); + grayCheckboxTex = t_texRepo->add("2d/", "gray_checkmark", PNG); + blueCheckboxTex = t_texRepo->add("2d/", "blue_checkmark", PNG); + + grayCheckboxTex->addLink(task1Checkbox.getId()); + grayCheckboxTex->addLink(task2Checkbox.getId()); + + PRINT_LOG("Ui initialized!"); +} + +Ui::~Ui() {} + +// ---- +// Methods +// ---- + +void Ui::update(const Player &player) +{ + if (!isTask1Done && player.getJumpCount() >= 10) + { + isTask1Done = true; + grayCheckboxTex->removeLinkBySprite(task1Checkbox.getId()); + blueCheckboxTex->addLink(task1Checkbox.getId()); + } +} + +void Ui::render(Renderer *t_renderer) +{ + t_renderer->draw(task1); + t_renderer->draw(task2); + t_renderer->draw(task1Checkbox); + t_renderer->draw(task2Checkbox); +} diff --git a/src/samples/floors/ui.hpp b/src/samples/floors/ui.hpp new file mode 100644 index 0000000..7b59455 --- /dev/null +++ b/src/samples/floors/ui.hpp @@ -0,0 +1,35 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Sandro Sobczyński +*/ + +#ifndef _UI_ +#define _UI_ + +#include +#include +#include "objects/player.hpp" +#include + +class Ui +{ + +public: + Ui(TextureRepository *t_texRepo); + ~Ui(); + + void update(const Player &player); + void render(Renderer *t_renderer); + +private: + u8 isTask1Done, isTask2Done; + Sprite task1, task2, task1Checkbox, task2Checkbox; + Texture *grayCheckboxTex, *blueCheckboxTex; +}; + +#endif From 97c9a5cd901bd05f39824e94fe373846c8c0dc4b Mon Sep 17 00:00:00 2001 From: h4570 Date: Sun, 6 Dec 2020 20:36:04 +0100 Subject: [PATCH 03/16] fixed var initializing --- src/samples/floors/managers/floor_manager.cpp | 2 +- src/samples/floors/objects/floor.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index 0265b17..3c38887 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -96,7 +96,7 @@ void FloorManager::update(Player &t_player) { floors[i].animate(t_player); - if (floors[i].isByAudioTriggered == true) + if (floors[i].isByAudioTriggered) floors[i].mesh.color.a = 0x20; else floors[i].mesh.color.a = 0x80; diff --git a/src/samples/floors/objects/floor.cpp b/src/samples/floors/objects/floor.cpp index 7da6c79..ac859b8 100644 --- a/src/samples/floors/objects/floor.cpp +++ b/src/samples/floors/objects/floor.cpp @@ -23,7 +23,13 @@ const float FLOOR_ANIMATION_Y_MAX = 10.0F; // Constructors/Destructors // ---- -Floor::Floor() {} +Floor::Floor() +{ + animTimer = 0; + animDirection = 0; + initOffset = 0; + isByAudioTriggered = false; +} Floor::~Floor() {} @@ -44,7 +50,6 @@ void Floor::init(const Mesh &mother, const Point &spiral, const u8 &initOffset) this->animTimer = rand() % FLOOR_ANIMATION_LENGTH; this->mesh.shouldBeLighted = true; this->mesh.shouldBeFrustumCulled = true; - this->animDirection = 0; this->mesh.position.x = spiral.x * 80.0F; this->mesh.position.z = spiral.y * 80.0F; } From fbbb41580cac616e2523462eb488954b182697dd Mon Sep 17 00:00:00 2001 From: h4570 Date: Sun, 6 Dec 2020 21:20:24 +0100 Subject: [PATCH 04/16] decreased vol --- src/samples/floors/floors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/samples/floors/floors.cpp b/src/samples/floors/floors.cpp index 97a2dc0..68bebac 100644 --- a/src/samples/floors/floors.cpp +++ b/src/samples/floors/floors.cpp @@ -43,7 +43,7 @@ void Floors::onInit() texRepo = engine->renderer->getTextureRepository(); enemy = new Enemy(texRepo); ui = new Ui(texRepo); - engine->audio.setSongVolume(80); + engine->audio.setSongVolume(20); texRepo->addByMesh("warrior/", player.mesh, BMP); texRepo->addByMesh("floor/", floorManager.floors[0].mesh, BMP); From 8a1bc254c56bc06dcce8c2f132882f4b7322e3a8 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 17:18:43 +0100 Subject: [PATCH 05/16] added sprite modes (stretch/repeat) --- src/engine/include/models/sprite.hpp | 13 +++++++++++++ src/engine/models/sprite.cpp | 1 + src/engine/modules/renderer.cpp | 28 ++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/engine/include/models/sprite.hpp b/src/engine/include/models/sprite.hpp index 14772c5..a606d2c 100644 --- a/src/engine/include/models/sprite.hpp +++ b/src/engine/include/models/sprite.hpp @@ -15,6 +15,12 @@ #include #include +enum SpriteMode +{ + MODE_STRETCH, + MODE_REPEAT +}; + /** * Class which have contain 2D image data. */ @@ -37,10 +43,16 @@ public: /** Auto generated unique Id. */ inline const u32 &getId() const { return id; }; + /** Get sprite drawing mode. */ + inline const SpriteMode &getMode() const { return mode; }; + // ---- // Setters // ---- + /** Set sprite drawing mode. */ + void setMode(const SpriteMode &t_val) { mode = t_val; } + // ---- // Other // ---- @@ -59,6 +71,7 @@ public: private: u32 id; + SpriteMode mode; u8 _isSizeSet, _flipH, _flipV; void setDefaultColor(); void setDefaultLODAndClut(); diff --git a/src/engine/models/sprite.cpp b/src/engine/models/sprite.cpp index 160d8c5..5151a0f 100644 --- a/src/engine/models/sprite.cpp +++ b/src/engine/models/sprite.cpp @@ -24,6 +24,7 @@ Sprite::Sprite() _flipH = false; _flipV = false; scale = 1.0F; + mode = MODE_REPEAT; setDefaultColor(); setDefaultLODAndClut(); } diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index 7bd7a60..6e33355 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -101,14 +101,26 @@ void Renderer::changeTexture(Texture *t_tex) void Renderer::draw(Sprite &t_sprite) { + Texture *texture = textureRepo.getBySprite(t_sprite.getId()); texrect_t rect; - float texMax = t_sprite.size.x > t_sprite.size.y ? t_sprite.size.x : t_sprite.size.y; - float texS = texMax; - float texT = texMax; - if (t_sprite.size.x > t_sprite.size.y) - texT = texMax / (t_sprite.size.x / t_sprite.size.y); - else if (t_sprite.size.y > t_sprite.size.x) - texS = texMax / (t_sprite.size.y / t_sprite.size.x); + float sizeX, sizeY; + if (t_sprite.getMode() == MODE_REPEAT) + { + sizeX = t_sprite.size.x; + sizeY = t_sprite.size.y; + } + else + { + sizeX = (float)texture->getWidth(); + sizeY = (float)texture->getHeight(); + } + + float texS, texT; + float texMax = texT = texS = sizeX > sizeY ? sizeX : sizeY; + if (sizeX > sizeY) + texT = texMax / (sizeX / sizeY); + else if (sizeY > sizeX) + texS = texMax / (sizeY / sizeX); rect.t0.s = t_sprite.isFlippedHorizontally() ? texS : 0.0F; rect.t0.t = t_sprite.isFlippedVertically() ? texT : 0.0F; rect.t1.s = t_sprite.isFlippedHorizontally() ? 0.0F : texS; @@ -125,7 +137,7 @@ void Renderer::draw(Sprite &t_sprite) rect.v1.y = (t_sprite.size.y * t_sprite.scale) + t_sprite.position.y; rect.v1.z = (u32)-1; beginFrameIfNeeded(); - changeTexture(textureRepo.getBySprite(t_sprite.getId())); + changeTexture(texture); packet2_t *packet2 = packet2_create(12, P2_TYPE_NORMAL, P2_MODE_NORMAL, 0); packet2_update(packet2, draw_primitive_xyoffset(packet2->next, 0, 2048, 2048)); packet2_utils_gif_add_set(packet2, 1); From 5fb685867822226e1f9bb43e2dd1417d85056333 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 17:19:34 +0100 Subject: [PATCH 06/16] marked getters as inline --- src/engine/include/models/texture.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/engine/include/models/texture.hpp b/src/engine/include/models/texture.hpp index d1fd2bb..6872e9f 100644 --- a/src/engine/include/models/texture.hpp +++ b/src/engine/include/models/texture.hpp @@ -47,38 +47,38 @@ public: * again texture in renderer, when last sent texture id * by renderer will be equal to this id. */ - const u32 &getId() const { return id; }; + inline const u32 getId() const { return id; }; - const u8 &getWidth() const { return width; }; + inline const u16 getWidth() const { return width; }; - const u8 &getHeight() const { return height; }; + inline const u16 getHeight() const { return height; }; - const TextureType &getType() const { return _type; }; + inline const TextureType getType() const { return _type; }; - u32 getTextureLinksCount() const { return static_cast(texLinks.size()); }; + inline u32 getTextureLinksCount() const { return static_cast(texLinks.size()); }; - texwrap_t *getWrapSettings() { return &wrapSettings; }; + inline texwrap_t *getWrapSettings() { return &wrapSettings; }; /** * Returns always width * width * 3/4. * 3 for RGB, 4 for RGBA. */ - u32 getDataSize() const { return _type == TEX_TYPE_RGB ? width * height * 3 : width * height * 4; }; + inline u32 getDataSize() const { return _type == TEX_TYPE_RGB ? width * height * 3 : width * height * 4; }; /** * Texture data, used by renderer. * Array of size getDataSize(). */ - unsigned char *getData() const { return data; }; + inline unsigned char *getData() const { return data; }; /** * Get texture name. * For "textures/abc.bmp" result will be: "abc" */ - char *getName() const { return name; }; + inline char *getName() const { return name; }; /** Array of texture links. Size of getTextureLinksCount() */ - const std::vector &getTextureLinks() const { return texLinks; }; + inline const std::vector &getTextureLinks() const { return texLinks; }; /** * Returns index of link. From dd49fc165e450e5887e2ac71faf5bba0c75420b4 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 20:47:41 +0100 Subject: [PATCH 07/16] lot of changes in floors --- src/samples/floors/camera.cpp | 2 +- src/samples/floors/floors.cpp | 19 +++++- src/samples/floors/floors.hpp | 1 + src/samples/floors/managers/floor_manager.cpp | 62 ++++++++++++++++++- src/samples/floors/managers/floor_manager.hpp | 5 ++ src/samples/floors/managers/light_manager.cpp | 4 +- src/samples/floors/objects/enemy.cpp | 43 +++++++++++-- src/samples/floors/objects/enemy.hpp | 10 ++- src/samples/floors/objects/player.cpp | 50 +++------------ src/samples/floors/objects/player.hpp | 8 ++- src/samples/floors/ui.cpp | 6 ++ src/samples/floors/utils.cpp | 36 +++++++++++ src/samples/floors/utils.hpp | 3 + 13 files changed, 190 insertions(+), 59 deletions(-) diff --git a/src/samples/floors/camera.cpp b/src/samples/floors/camera.cpp index c55cad0..b9c583e 100644 --- a/src/samples/floors/camera.cpp +++ b/src/samples/floors/camera.cpp @@ -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; diff --git a/src/samples/floors/floors.cpp b/src/samples/floors/floors.cpp index 68bebac..823a850 100644 --- a/src/samples/floors/floors.cpp +++ b/src/samples/floors/floors.cpp @@ -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; diff --git a/src/samples/floors/floors.hpp b/src/samples/floors/floors.hpp index c5a68c4..bf2905f 100644 --- a/src/samples/floors/floors.hpp +++ b/src/samples/floors/floors.hpp @@ -37,6 +37,7 @@ public: Engine *engine; private: + void setBgColorAndAmbientColor(); u32 audioTicks; u8 skip1Beat; TextureRepository *texRepo; diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index 251491c..d97523e 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -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,17 +96,67 @@ 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; + { + 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.a = 0x80; + { + 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 */ void FloorManager::onAudioTick() { @@ -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; } } diff --git a/src/samples/floors/managers/floor_manager.hpp b/src/samples/floors/managers/floor_manager.hpp index 847fdca..c7eb14a 100644 --- a/src/samples/floors/managers/floor_manager.hpp +++ b/src/samples/floors/managers/floor_manager.hpp @@ -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(); }; diff --git a/src/samples/floors/managers/light_manager.cpp b/src/samples/floors/managers/light_manager.cpp index c9c33a0..a87f322 100644 --- a/src/samples/floors/managers/light_manager.cpp +++ b/src/samples/floors/managers/light_manager.cpp @@ -142,7 +142,7 @@ void LightManager::onAudioTick() } else { - bulbs[0].intensity += 6; - bulbs[1].intensity += 6; + bulbs[0].intensity += 9; + bulbs[1].intensity += 9; } } diff --git a/src/samples/floors/objects/enemy.cpp b/src/samples/floors/objects/enemy.cpp index 691723e..4d11344 100644 --- a/src/samples/floors/objects/enemy.cpp +++ b/src/samples/floors/objects/enemy.cpp @@ -9,6 +9,7 @@ */ #include "enemy.hpp" +#include "../utils.hpp" #include #include @@ -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); } diff --git a/src/samples/floors/objects/enemy.hpp b/src/samples/floors/objects/enemy.hpp index c5c298d..601a4e9 100644 --- a/src/samples/floors/objects/enemy.hpp +++ b/src/samples/floors/objects/enemy.hpp @@ -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 diff --git a/src/samples/floors/objects/player.cpp b/src/samples/floors/objects/player.cpp index 6a32148..0946a8e 100644 --- a/src/samples/floors/objects/player.cpp +++ b/src/samples/floors/objects/player.cpp @@ -9,6 +9,7 @@ */ #include "player.hpp" +#include "../utils.hpp" #include #include @@ -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; - } -} diff --git a/src/samples/floors/objects/player.hpp b/src/samples/floors/objects/player.hpp index c5386d4..75b1ccb 100644 --- a/src/samples/floors/objects/player.hpp +++ b/src/samples/floors/objects/player.hpp @@ -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); }; diff --git a/src/samples/floors/ui.cpp b/src/samples/floors/ui.cpp index 97f4a53..3f3dc14 100644 --- a/src/samples/floors/ui.cpp +++ b/src/samples/floors/ui.cpp @@ -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) diff --git a/src/samples/floors/utils.cpp b/src/samples/floors/utils.cpp index eb7d2ba..5195cf9 100644 --- a/src/samples/floors/utils.cpp +++ b/src/samples/floors/utils.cpp @@ -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; + } +} diff --git a/src/samples/floors/utils.hpp b/src/samples/floors/utils.hpp index da8af9f..2d7293f 100644 --- a/src/samples/floors/utils.hpp +++ b/src/samples/floors/utils.hpp @@ -12,12 +12,15 @@ #define _TYRA_UTILS_ #include +#include +#include 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 From 3284c5a598f35862cc38575366f9f5bdee3691f5 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 21:02:06 +0100 Subject: [PATCH 08/16] added setAmbientLight(), setWorldColor() --- src/engine/include/modules/gif_sender.hpp | 8 +++++--- src/engine/include/modules/light.hpp | 8 ++++++-- src/engine/include/modules/renderer.hpp | 13 ++++++++++++- src/engine/include/modules/vif_sender.hpp | 4 +++- src/engine/modules/gif_sender.cpp | 16 ++++++++-------- src/engine/modules/light.cpp | 8 +++++--- src/engine/modules/renderer.cpp | 16 +++++++++++++--- src/engine/modules/vif_sender.cpp | 3 ++- 8 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/engine/include/modules/gif_sender.hpp b/src/engine/include/modules/gif_sender.hpp index 1d695e8..88b9676 100644 --- a/src/engine/include/modules/gif_sender.hpp +++ b/src/engine/include/modules/gif_sender.hpp @@ -17,6 +17,7 @@ #include #include #include +#include "./light.hpp" #include "../models/mesh.hpp" #include "../models/math/matrix.hpp" #include "../models/screen_settings.hpp" @@ -29,17 +30,18 @@ class GifSender { public: - GifSender(u32 t_packetSize, ScreenSettings *t_screen); + GifSender(u32 t_packetSize, ScreenSettings *t_screen, Light *t_light); ~GifSender(); void initPacket(u8 context); void addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer); - void addClear(zbuffer_t *t_zBuffer); + void addClear(zbuffer_t *t_zBuffer, color_t *rgb); void sendPacket(); - void sendClear(zbuffer_t *t_zBuffer); + void sendClear(zbuffer_t *t_zBuffer, color_t *rgb); static void sendTexture(Texture &texture, texbuffer_t *t_texBuffer); private: + Light *light; xyz_t *xyz; color_t *rgbaq; texel_t *st; diff --git a/src/engine/include/modules/light.hpp b/src/engine/include/modules/light.hpp index 71f1cfd..ded1f2a 100644 --- a/src/engine/include/modules/light.hpp +++ b/src/engine/include/modules/light.hpp @@ -23,10 +23,14 @@ public: Light(); ~Light(); - static u16 getLightsCount(u32 t_bulbsCount); - static void calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int *t_lightTypes, LightBulb *t_bulbs, u32 t_lightsCount, Vector3 t_objPosition); + u16 getLightsCount(u32 t_bulbsCount); + + /** Values from 0.0000F to 1.0000F */ + void setAmbientLight(const Vector3 &t_rgb); + void calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int *t_lightTypes, LightBulb *t_bulbs, u32 t_lightsCount, Vector3 t_objPosition); private: + Vector3 ambientLight; }; #endif diff --git a/src/engine/include/modules/renderer.hpp b/src/engine/include/modules/renderer.hpp index c215eda..d2cdb76 100644 --- a/src/engine/include/modules/renderer.hpp +++ b/src/engine/include/modules/renderer.hpp @@ -16,6 +16,7 @@ #include #include "gif_sender.hpp" #include "vif_sender.hpp" +#include "light.hpp" #include "../models/math/plane.hpp" #include "../models/sprite.hpp" #include "../models/screen_settings.hpp" @@ -102,11 +103,19 @@ public: void setCameraDefinitions(Matrix *t_worldView, Vector3 *t_cameraPos, Plane *t_planes); + void setWorldColor(const color_t &t_rgb); + void endFrame(float fps); - TextureRepository *getTextureRepository() { return &textureRepo; }; + void setAmbientLight(const Vector3 &t_rgb) { light.setAmbientLight(t_rgb); } + + TextureRepository *getTextureRepository() + { + return &textureRepo; + }; private: + // We have some GCC bug here. Just try to reorder declarations. For example move worldColor up - game will crash. void changeTexture(Texture *t_tex); u32 lastTextureId; texbuffer_t textureBuffer; @@ -117,12 +126,14 @@ private: void beginFrameIfNeeded(); u8 isFrameEmpty; Matrix perspective; + Light light; RenderData renderData; TextureRepository textureRepo; ScreenSettings *screen; GifSender *gifSender; VifSender *vifSender; packet2_t *flipPacket; + color_t worldColor; void allocateBuffers(float t_screenW, float t_screenH); void initDrawingEnv(float t_screenW, float t_screenH); void setPrim(); diff --git a/src/engine/include/modules/vif_sender.hpp b/src/engine/include/modules/vif_sender.hpp index 6291a75..467e111 100644 --- a/src/engine/include/modules/vif_sender.hpp +++ b/src/engine/include/modules/vif_sender.hpp @@ -14,6 +14,7 @@ #include #include #include "../models/render_data.hpp" +#include "./light.hpp" #include "../models/light_bulb.hpp" #include "../models/mesh.hpp" #include "../models/math/matrix.hpp" @@ -24,7 +25,7 @@ class VifSender { public: - VifSender(); + VifSender(Light *t_light); ~VifSender(); // TODO refactor @@ -32,6 +33,7 @@ public: void sendMatrices(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation); private: + Light *light; void uploadMicroProgram(); void setDoubleBuffer(); void drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer); diff --git a/src/engine/modules/gif_sender.cpp b/src/engine/modules/gif_sender.cpp index 5e2d06c..d923049 100644 --- a/src/engine/modules/gif_sender.cpp +++ b/src/engine/modules/gif_sender.cpp @@ -12,7 +12,6 @@ #include "../include/utils/math.hpp" #include "../include/utils/debug.hpp" -#include "../include/modules/light.hpp" #include #include #include @@ -29,9 +28,10 @@ /** Initializes vars and creates data transfer packets * @param packetSize Size of data packet, should be increased when more data will be rendered */ -GifSender::GifSender(u32 t_packetSize, ScreenSettings *t_screen) : screen(t_screen) +GifSender::GifSender(u32 t_packetSize, ScreenSettings *t_screen, Light *t_light) : screen(t_screen) { PRINT_LOG("Initializing GifSender"); + light = t_light; packetSize = t_packetSize; packets[0] = packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, false); packets[1] = packet2_create(t_packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, false); @@ -76,7 +76,7 @@ void GifSender::sendTexture(Texture &texture, texbuffer_t *t_texBuffer) packet2_free(packet2); } -void GifSender::sendClear(zbuffer_t *t_zBuffer) +void GifSender::sendClear(zbuffer_t *t_zBuffer, color_t *rgb) { packet2_t *packet2 = packet2_create(36, P2_TYPE_NORMAL, P2_MODE_CHAIN, false); packet2_chain_open_end(packet2, 0, 0); @@ -84,7 +84,7 @@ void GifSender::sendClear(zbuffer_t *t_zBuffer) packet2_update(packet2, draw_clear(packet2->next, 0, 2048.0F - (screen->width / 2), 2048.0F - (screen->height / 2), screen->width, screen->height, - 0x10, 0x10, 0x10)); + rgb->r, rgb->g, rgb->b)); packet2_update(packet2, draw_enable_tests(packet2->next, 0, t_zBuffer)); packet2_update(packet2, draw_finish(packet2->next)); packet2_chain_close_tag(packet2); @@ -118,14 +118,14 @@ void GifSender::sendPacket() } /** Adds clear screen to current packet */ -void GifSender::addClear(zbuffer_t *t_zBuffer) +void GifSender::addClear(zbuffer_t *t_zBuffer, color_t *rgb) { packet2_chain_open_cnt(currentPacket, 0, 0, 0); packet2_update(currentPacket, draw_disable_tests(currentPacket->next, 0, t_zBuffer)); packet2_update(currentPacket, draw_clear(currentPacket->next, 0, 2048.0F - (screen->width / 2), 2048.0F - (screen->height / 2), screen->width, screen->height, - 0x10, 0x10, 0x10)); + rgb->r, rgb->g, rgb->b)); packet2_update(currentPacket, draw_enable_tests(currentPacket->next, 0, t_zBuffer)); packet2_chain_close_tag(currentPacket); } @@ -180,7 +180,7 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount if (SHOULD_BE_LIGHTED) { - const u16 lightsCount = Light::getLightsCount(t_bulbsCount); + const u16 lightsCount = light->getLightsCount(t_bulbsCount); VECTOR *lightDirections = new VECTOR[lightsCount]; VECTOR *lightColors = new VECTOR[lightsCount]; int *lightTypes = new int[lightsCount]; @@ -188,7 +188,7 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount VECTOR *lights = new VECTOR[vertexCount]; calculate_normals(normals, vertexCount, normals, localLight); - Light::calculateLight(lightDirections, lightColors, lightTypes, t_bulbs, lightsCount, t_mesh.position); + light->calculateLight(lightDirections, lightColors, lightTypes, t_bulbs, lightsCount, t_mesh.position); calculate_lights(lights, vertexCount, normals, lightDirections, lightColors, lightTypes, lightsCount); diff --git a/src/engine/modules/light.cpp b/src/engine/modules/light.cpp index b8a1d09..19f2702 100644 --- a/src/engine/modules/light.cpp +++ b/src/engine/modules/light.cpp @@ -26,6 +26,8 @@ const u8 ADDITIONAL_LIGHTS = 1; // Ambient const float LIGHT_MAX = 255.0F; const float LIGHT_DIS_MOD = 4.0F; +void Light::setAmbientLight(const Vector3 &t_rgb) { ambientLight.set(t_rgb); } + u16 Light::getLightsCount(u32 t_bulbsCount) { return t_bulbsCount + ADDITIONAL_LIGHTS; } /** Calculates lighting. Used in gifSender in object 3D calculations */ @@ -40,9 +42,9 @@ void Light::calculateLight(VECTOR *t_lightDirections, VECTOR *t_lightColors, int t_lightDirections[0][2] = 0.0F; t_lightDirections[0][3] = 1.0F; - t_lightColors[0][0] = 0.0F; - t_lightColors[0][1] = 0.0F; - t_lightColors[0][2] = 0.0F; + t_lightColors[0][0] = ambientLight.x; + t_lightColors[0][1] = ambientLight.y; + t_lightColors[0][2] = ambientLight.z; t_lightColors[0][3] = 1.0F; // --- diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index 6e33355..9b55597 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -44,9 +44,12 @@ Renderer::Renderer(u32 t_packetSize, ScreenSettings *t_screen) allocateBuffers(t_screen->width, t_screen->height); initDrawingEnv(t_screen->width, t_screen->height); setPrim(); + worldColor.r = 0x10; + worldColor.g = 0x10; + worldColor.b = 0x10; screen = t_screen; - gifSender = new GifSender(t_packetSize, t_screen); - vifSender = new VifSender(); + gifSender = new GifSender(t_packetSize, t_screen, &light); + vifSender = new VifSender(&light); perspective.setPerspective(*t_screen); renderData.perspective = &perspective; PRINT_LOG("Renderer initialized!"); @@ -187,6 +190,13 @@ void Renderer::setPrim() PRINT_LOG("Prim set!"); } +void Renderer::setWorldColor(const color_t &t_rgb) +{ + worldColor.r = t_rgb.r; + worldColor.g = t_rgb.g; + worldColor.b = t_rgb.b; +} + /** Defines and allocates framebuffers and zbuffer */ void Renderer::allocateBuffers(float t_screenW, float t_screenH) { @@ -305,7 +315,7 @@ void Renderer::beginFrameIfNeeded() if (isFrameEmpty) { isFrameEmpty = false; - gifSender->sendClear(&zBuffer); + gifSender->sendClear(&zBuffer, &worldColor); } } diff --git a/src/engine/modules/vif_sender.cpp b/src/engine/modules/vif_sender.cpp index 7458a58..9158a8d 100644 --- a/src/engine/modules/vif_sender.cpp +++ b/src/engine/modules/vif_sender.cpp @@ -29,8 +29,9 @@ extern u32 VU1Draw3D_CodeStart __attribute__((section(".vudata"))); extern u32 VU1Draw3D_CodeEnd __attribute__((section(".vudata"))); // -VifSender::VifSender() +VifSender::VifSender(Light *t_light) { + light = t_light; PRINT_LOG("Initializing VifSender"); PRINT_LOG("VifSender initialized!"); dma_channel_initialize(DMA_CHANNEL_VIF1, NULL, 0); From e00e677d1ee9bc9c636f0f4a2d3a7d74d7b6a6fc Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 21:04:38 +0100 Subject: [PATCH 09/16] fixed naming convention --- src/engine/include/modules/gif_sender.hpp | 4 ++-- src/engine/modules/gif_sender.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/engine/include/modules/gif_sender.hpp b/src/engine/include/modules/gif_sender.hpp index 88b9676..0c7646b 100644 --- a/src/engine/include/modules/gif_sender.hpp +++ b/src/engine/include/modules/gif_sender.hpp @@ -35,9 +35,9 @@ public: void initPacket(u8 context); void addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer); - void addClear(zbuffer_t *t_zBuffer, color_t *rgb); + void addClear(zbuffer_t *t_zBuffer, color_t *t_rgb); void sendPacket(); - void sendClear(zbuffer_t *t_zBuffer, color_t *rgb); + void sendClear(zbuffer_t *t_zBuffer, color_t *t_rgb); static void sendTexture(Texture &texture, texbuffer_t *t_texBuffer); private: diff --git a/src/engine/modules/gif_sender.cpp b/src/engine/modules/gif_sender.cpp index d923049..08dad58 100644 --- a/src/engine/modules/gif_sender.cpp +++ b/src/engine/modules/gif_sender.cpp @@ -76,7 +76,7 @@ void GifSender::sendTexture(Texture &texture, texbuffer_t *t_texBuffer) packet2_free(packet2); } -void GifSender::sendClear(zbuffer_t *t_zBuffer, color_t *rgb) +void GifSender::sendClear(zbuffer_t *t_zBuffer, color_t *t_rgb) { packet2_t *packet2 = packet2_create(36, P2_TYPE_NORMAL, P2_MODE_CHAIN, false); packet2_chain_open_end(packet2, 0, 0); @@ -84,7 +84,7 @@ void GifSender::sendClear(zbuffer_t *t_zBuffer, color_t *rgb) packet2_update(packet2, draw_clear(packet2->next, 0, 2048.0F - (screen->width / 2), 2048.0F - (screen->height / 2), screen->width, screen->height, - rgb->r, rgb->g, rgb->b)); + t_rgb->r, t_rgb->g, t_rgb->b)); packet2_update(packet2, draw_enable_tests(packet2->next, 0, t_zBuffer)); packet2_update(packet2, draw_finish(packet2->next)); packet2_chain_close_tag(packet2); @@ -118,14 +118,14 @@ void GifSender::sendPacket() } /** Adds clear screen to current packet */ -void GifSender::addClear(zbuffer_t *t_zBuffer, color_t *rgb) +void GifSender::addClear(zbuffer_t *t_zBuffer, color_t *t_rgb) { packet2_chain_open_cnt(currentPacket, 0, 0, 0); packet2_update(currentPacket, draw_disable_tests(currentPacket->next, 0, t_zBuffer)); packet2_update(currentPacket, draw_clear(currentPacket->next, 0, 2048.0F - (screen->width / 2), 2048.0F - (screen->height / 2), screen->width, screen->height, - rgb->r, rgb->g, rgb->b)); + t_rgb->r, t_rgb->g, t_rgb->b)); packet2_update(currentPacket, draw_enable_tests(currentPacket->next, 0, t_zBuffer)); packet2_chain_close_tag(currentPacket); } From 0474fc07a583dcd2ac252187ba8e07c557add7cb Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 21:05:46 +0100 Subject: [PATCH 10/16] doc: usefull tip for loadADPCM() --- src/engine/include/modules/audio.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/include/modules/audio.hpp b/src/engine/include/modules/audio.hpp index 8bfa868..ea1dfe2 100644 --- a/src/engine/include/modules/audio.hpp +++ b/src/engine/include/modules/audio.hpp @@ -87,7 +87,8 @@ public: // ADPCM /** - * Load ADPCM sample. + * Load ADPCM sample. ADPCM sample is an output from + * "adpenc" tool, shipped with PS2SDK. * @param t_path Example: "hit.adpcm" or "folder/jump.adpcm" */ audsrv_adpcm_t *loadADPCM(char *t_path); From 87ae4b05074455eac1e333425f3af072d08be8fc Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 21:20:08 +0100 Subject: [PATCH 11/16] added info banner --- src/samples/floors/ui.cpp | 5 +++++ src/samples/floors/ui.hpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/samples/floors/ui.cpp b/src/samples/floors/ui.cpp index 3f3dc14..33ace3a 100644 --- a/src/samples/floors/ui.cpp +++ b/src/samples/floors/ui.cpp @@ -23,6 +23,9 @@ Ui::Ui(TextureRepository *t_texRepo) isTask1Done = false; isTask2Done = false; + info.size.set(128.0F, 32.0F); + info.position.set(500.0F, 430.0F); + task1.size.set(128.0F, 32.0F); task1.position.set(500.0F, 10.0F); @@ -35,6 +38,7 @@ Ui::Ui(TextureRepository *t_texRepo) task2Checkbox.size.set(32.0F, 32.0F); task2Checkbox.position.set(460.0F, 50.0F); + t_texRepo->add("2d/", "info_text", PNG)->addLink(info.getId()); t_texRepo->add("2d/", "check1_text", PNG)->addLink(task1.getId()); t_texRepo->add("2d/", "check2_text", PNG)->addLink(task2.getId()); grayCheckboxTex = t_texRepo->add("2d/", "gray_checkmark", PNG); @@ -70,6 +74,7 @@ void Ui::update(const Player &player) void Ui::render(Renderer *t_renderer) { + t_renderer->draw(info); t_renderer->draw(task1); t_renderer->draw(task2); t_renderer->draw(task1Checkbox); diff --git a/src/samples/floors/ui.hpp b/src/samples/floors/ui.hpp index 7b59455..2eee558 100644 --- a/src/samples/floors/ui.hpp +++ b/src/samples/floors/ui.hpp @@ -28,7 +28,7 @@ public: private: u8 isTask1Done, isTask2Done; - Sprite task1, task2, task1Checkbox, task2Checkbox; + Sprite task1, task2, task1Checkbox, task2Checkbox, info; Texture *grayCheckboxTex, *blueCheckboxTex; }; From 11a92c32eebf99e35f3c8c530d9f7e5acdef30d1 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 21:51:44 +0100 Subject: [PATCH 12/16] audio changes --- src/samples/floors/managers/floor_manager.cpp | 2 +- src/samples/floors/objects/player.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index d97523e..ba2216e 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -160,7 +160,7 @@ void FloorManager::doTheTrick() /** Called by audio thread */ void FloorManager::onAudioTick() { - if (audioTick++ > 13) + if (audioTick++ > 19) { if (audioMode == 0) { diff --git a/src/samples/floors/objects/player.cpp b/src/samples/floors/objects/player.cpp index 0946a8e..e5d9ce9 100644 --- a/src/samples/floors/objects/player.cpp +++ b/src/samples/floors/objects/player.cpp @@ -48,7 +48,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); + audio->setADPCMVolume(70, 0); PRINT_LOG("Player object created!"); } From 96fe7c380ebaa7d919edafbc8e522880daf0f10c Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 21:51:48 +0100 Subject: [PATCH 13/16] added reward --- src/samples/floors/ui.cpp | 7 +++++++ src/samples/floors/ui.hpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/samples/floors/ui.cpp b/src/samples/floors/ui.cpp index 33ace3a..6639dc3 100644 --- a/src/samples/floors/ui.cpp +++ b/src/samples/floors/ui.cpp @@ -26,6 +26,10 @@ Ui::Ui(TextureRepository *t_texRepo) info.size.set(128.0F, 32.0F); info.position.set(500.0F, 430.0F); + reward.size.set(128.0F, 128.0F); + reward.position.set(500.0F, 280.0F); + reward.flipVertically(true); + task1.size.set(128.0F, 32.0F); task1.position.set(500.0F, 10.0F); @@ -38,6 +42,7 @@ Ui::Ui(TextureRepository *t_texRepo) task2Checkbox.size.set(32.0F, 32.0F); task2Checkbox.position.set(460.0F, 50.0F); + t_texRepo->add("2d/", "reward", BMP)->addLink(reward.getId()); t_texRepo->add("2d/", "info_text", PNG)->addLink(info.getId()); t_texRepo->add("2d/", "check1_text", PNG)->addLink(task1.getId()); t_texRepo->add("2d/", "check2_text", PNG)->addLink(task2.getId()); @@ -74,6 +79,8 @@ void Ui::update(const Player &player) void Ui::render(Renderer *t_renderer) { + if (isTask1Done && isTask2Done) + t_renderer->draw(reward); t_renderer->draw(info); t_renderer->draw(task1); t_renderer->draw(task2); diff --git a/src/samples/floors/ui.hpp b/src/samples/floors/ui.hpp index 2eee558..f96edb9 100644 --- a/src/samples/floors/ui.hpp +++ b/src/samples/floors/ui.hpp @@ -28,7 +28,7 @@ public: private: u8 isTask1Done, isTask2Done; - Sprite task1, task2, task1Checkbox, task2Checkbox, info; + Sprite task1, task2, task1Checkbox, task2Checkbox, info, reward; Texture *grayCheckboxTex, *blueCheckboxTex; }; From 6d9b93998aeee04a14f1ac80251e5c7aefc20e39 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 22:05:06 +0100 Subject: [PATCH 14/16] changed paths --- src/samples/floors/floors.cpp | 6 +++--- src/samples/floors/managers/floor_manager.cpp | 2 +- src/samples/floors/objects/enemy.cpp | 12 ++++++------ src/samples/floors/objects/player.cpp | 8 ++++---- src/samples/floors/ui.cpp | 12 ++++++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/samples/floors/floors.cpp b/src/samples/floors/floors.cpp index 823a850..1c1324d 100644 --- a/src/samples/floors/floors.cpp +++ b/src/samples/floors/floors.cpp @@ -39,15 +39,15 @@ void Floors::onInit() setBgColorAndAmbientColor(); engine->renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes); engine->audio.addSongListener(this); - engine->audio.loadSong("mafikizolo-loot.wav"); + engine->audio.loadSong("sounds/mafikizolo-loot.wav"); engine->audio.playSong(); texRepo = engine->renderer->getTextureRepository(); enemy = new Enemy(texRepo); ui = new Ui(texRepo); engine->audio.setSongVolume(80); - texRepo->addByMesh("warrior/", player.mesh, BMP); - texRepo->addByMesh("floor/", floorManager.floors[0].mesh, BMP); + texRepo->addByMesh("meshes/player/", player.mesh, BMP); + texRepo->addByMesh("meshes/floor/", floorManager.floors[0].mesh, BMP); for (u32 i = 1; i < floorManager.floorAmount; i++) texRepo->getByMesh(floorManager.floors[0].mesh.getId(), floorManager.floors[0].mesh.getMaterial(0).getId()) ->addLink(floorManager.floors[i].mesh.getId(), floorManager.floors[i].mesh.getMaterial(0).getId()); diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index ba2216e..6c81df1 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -81,7 +81,7 @@ void FloorManager::calcSpiral(int X, int Y) void FloorManager::initFloors() { PRINT_LOG("Initializing floors"); - floors[0].mesh.loadObj("floor/", "floor", 3.0F, false); + floors[0].mesh.loadObj("meshes/floor/", "floor", 3.0F, false); floors[0].mesh.shouldBeFrustumCulled = true; floors[0].mesh.shouldBeLighted = true; for (u16 i = 1; i < floorAmount; i++) diff --git a/src/samples/floors/objects/enemy.cpp b/src/samples/floors/objects/enemy.cpp index 4d11344..858e79c 100644 --- a/src/samples/floors/objects/enemy.cpp +++ b/src/samples/floors/objects/enemy.cpp @@ -27,24 +27,24 @@ Enemy::Enemy(TextureRepository *t_texRepo) meshes = new Mesh[getMeshesCount()]; - meshes[0].loadMD2("poss/", "poss_head", 0.3F, false); + meshes[0].loadMD2("meshes/enemy/", "poss_head", 0.3F, false); meshes[0].rotation.x = -1.566F; meshes[0].rotation.z = 1.566F; - meshes[1].loadMD2("poss/", "poss_body", 0.3F, false); + meshes[1].loadMD2("meshes/enemy/", "poss_body", 0.3F, false); meshes[1].rotation.x = -1.566F; meshes[1].rotation.z = 1.566F; - meshes[2].loadMD2("poss/", "poss_weapon", 0.3F, false); + meshes[2].loadMD2("meshes/enemy/", "poss_weapon", 0.3F, false); 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); + t_texRepo->addByMesh("meshes/enemy/", meshes[0], PNG); + t_texRepo->addByMesh("meshes/enemy/", meshes[1], PNG); + t_texRepo->addByMesh("meshes/enemy/", meshes[2], PNG); meshes[0].playAnimation(1, 6); meshes[1].playAnimation(1, 6); diff --git a/src/samples/floors/objects/player.cpp b/src/samples/floors/objects/player.cpp index e5d9ce9..1de292f 100644 --- a/src/samples/floors/objects/player.cpp +++ b/src/samples/floors/objects/player.cpp @@ -36,7 +36,7 @@ Player::Player(Audio *t_audio) isJumpingAnimationSet = false; isFightingAnimationSet = false; - mesh.loadMD2("warrior/", "warrior", 0.2F, true); + mesh.loadMD2("meshes/player/", "warrior", 0.2F, true); mesh.position.set(0.00F, 40.00F, 0.00F); mesh.rotation.x = -1.566F; mesh.rotation.z = 1.566F; @@ -45,9 +45,9 @@ Player::Player(Audio *t_audio) mesh.setAnimSpeed(0.17F); mesh.playAnimation(0, 0); - walkAdpcm = audio->loadADPCM("walk.adpcm"); - jumpAdpcm = audio->loadADPCM("jump.adpcm"); - boomAdpcm = audio->loadADPCM("boom.adpcm"); + walkAdpcm = audio->loadADPCM("sounds/walk.adpcm"); + jumpAdpcm = audio->loadADPCM("sounds/jump.adpcm"); + boomAdpcm = audio->loadADPCM("sounds/boom.adpcm"); audio->setADPCMVolume(70, 0); PRINT_LOG("Player object created!"); diff --git a/src/samples/floors/ui.cpp b/src/samples/floors/ui.cpp index 6639dc3..52c43ff 100644 --- a/src/samples/floors/ui.cpp +++ b/src/samples/floors/ui.cpp @@ -42,12 +42,12 @@ Ui::Ui(TextureRepository *t_texRepo) task2Checkbox.size.set(32.0F, 32.0F); task2Checkbox.position.set(460.0F, 50.0F); - t_texRepo->add("2d/", "reward", BMP)->addLink(reward.getId()); - t_texRepo->add("2d/", "info_text", PNG)->addLink(info.getId()); - t_texRepo->add("2d/", "check1_text", PNG)->addLink(task1.getId()); - t_texRepo->add("2d/", "check2_text", PNG)->addLink(task2.getId()); - grayCheckboxTex = t_texRepo->add("2d/", "gray_checkmark", PNG); - blueCheckboxTex = t_texRepo->add("2d/", "blue_checkmark", PNG); + t_texRepo->add("ui/", "reward", BMP)->addLink(reward.getId()); + t_texRepo->add("ui/", "info-text", PNG)->addLink(info.getId()); + t_texRepo->add("ui/", "check1-text", PNG)->addLink(task1.getId()); + t_texRepo->add("ui/", "check2-text", PNG)->addLink(task2.getId()); + grayCheckboxTex = t_texRepo->add("ui/", "gray-checkmark", PNG); + blueCheckboxTex = t_texRepo->add("ui/", "blue-checkmark", PNG); grayCheckboxTex->addLink(task1Checkbox.getId()); grayCheckboxTex->addLink(task2Checkbox.getId()); From 5787b6a920244baa93b127ab6c858d809e1c2d78 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 22:11:21 +0100 Subject: [PATCH 15/16] refactor #1 --- src/samples/floors/floors.cpp | 31 +++++++++---------- src/samples/floors/floors.hpp | 4 +-- src/samples/floors/managers/floor_manager.cpp | 8 ++++- src/samples/floors/managers/floor_manager.hpp | 4 ++- src/samples/floors/objects/player.cpp | 5 ++- src/samples/floors/objects/player.hpp | 3 +- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/samples/floors/floors.cpp b/src/samples/floors/floors.cpp index 1c1324d..2a55ab1 100644 --- a/src/samples/floors/floors.cpp +++ b/src/samples/floors/floors.cpp @@ -17,8 +17,7 @@ const u16 FLOORS_COUNT = 144; // Temp change it also in floor_manager.hpp Floors::Floors(Engine *t_engine) - : engine(t_engine), floorManager(FLOORS_COUNT), - player(&t_engine->audio), camera(&t_engine->screen) + : engine(t_engine), floorManager(), camera(&t_engine->screen) { audioTicks = 0; skip1Beat = 0; @@ -28,6 +27,8 @@ Floors::~Floors() { delete enemy; delete ui; + delete floorManager; + delete player; } // ---- @@ -41,30 +42,26 @@ void Floors::onInit() engine->audio.addSongListener(this); engine->audio.loadSong("sounds/mafikizolo-loot.wav"); engine->audio.playSong(); + engine->audio.setSongVolume(80); texRepo = engine->renderer->getTextureRepository(); enemy = new Enemy(texRepo); ui = new Ui(texRepo); - engine->audio.setSongVolume(80); - - texRepo->addByMesh("meshes/player/", player.mesh, BMP); - texRepo->addByMesh("meshes/floor/", floorManager.floors[0].mesh, BMP); - for (u32 i = 1; i < floorManager.floorAmount; i++) - texRepo->getByMesh(floorManager.floors[0].mesh.getId(), floorManager.floors[0].mesh.getMaterial(0).getId()) - ->addLink(floorManager.floors[i].mesh.getId(), floorManager.floors[i].mesh.getMaterial(0).getId()); + floorManager = new FloorManager(FLOORS_COUNT, texRepo); + player = new Player(&engine->audio, texRepo); } void Floors::onUpdate() { - ui->update(player); - enemy->update(floorManager); + ui->update(*player); + enemy->update(*floorManager); lightManager.update(); - camera.update(engine->pad, player.mesh); - floorManager.update(player); - player.update(engine->pad, camera, floorManager, *enemy); - engine->renderer->draw(player.mesh); + camera.update(engine->pad, player->mesh); + floorManager->update(*player); + player->update(engine->pad, camera, *floorManager, *enemy); + engine->renderer->draw(player->mesh); engine->renderer->draw(enemy->getMeshes(), enemy->getMeshesCount()); for (u16 i = 0; i < FLOORS_COUNT; i++) - engine->renderer->drawByPath3(floorManager.floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount); + engine->renderer->drawByPath3(floorManager->floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount); ui->render(engine->renderer); // 2D rendering ist LAST step, because layers gonna play there. } @@ -73,7 +70,7 @@ void Floors::onAudioTick() if ((++audioTicks + 20) % 21 == 0) { if (skip1Beat) - floorManager.onAudioTick(); + floorManager->onAudioTick(); lightManager.onAudioTick(); skip1Beat = !skip1Beat; } diff --git a/src/samples/floors/floors.hpp b/src/samples/floors/floors.hpp index bf2905f..dc9f8b8 100644 --- a/src/samples/floors/floors.hpp +++ b/src/samples/floors/floors.hpp @@ -42,8 +42,8 @@ private: u8 skip1Beat; TextureRepository *texRepo; LightManager lightManager; - FloorManager floorManager; - Player player; + FloorManager *floorManager; + Player *player; Camera camera; Ui *ui; Enemy *enemy; diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index 6c81df1..e1b1d09 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -20,8 +20,9 @@ /** Calculate square spiral offsets and initialize floors * @param floorAmount must be a number from square root table */ -FloorManager::FloorManager(int t_floorAmount) +FloorManager::FloorManager(int t_floorAmount, TextureRepository *t_texRepo) { + texRepo = t_texRepo; floorAmount = t_floorAmount; spirals = new Point[t_floorAmount]; int floorSpiralMaxOffset = (int)Math::sqrt(t_floorAmount); @@ -84,8 +85,13 @@ void FloorManager::initFloors() floors[0].mesh.loadObj("meshes/floor/", "floor", 3.0F, false); floors[0].mesh.shouldBeFrustumCulled = true; floors[0].mesh.shouldBeLighted = true; + texRepo->addByMesh("meshes/floor/", floors[0].mesh, BMP); for (u16 i = 1; i < floorAmount; i++) + { floors[i].init(floors[0].mesh, spirals[i], i); + texRepo->getByMesh(floors[0].mesh.getId(), floors[0].mesh.getMaterial(0).getId()) + ->addLink(floors[i].mesh.getId(), floors[i].mesh.getMaterial(0).getId()); + } PRINT_LOG("Floors initialized!"); } diff --git a/src/samples/floors/managers/floor_manager.hpp b/src/samples/floors/managers/floor_manager.hpp index c7eb14a..61a64b7 100644 --- a/src/samples/floors/managers/floor_manager.hpp +++ b/src/samples/floors/managers/floor_manager.hpp @@ -14,6 +14,7 @@ class Player; // Forward definition #include +#include #include #include @@ -24,7 +25,7 @@ class FloorManager { public: - FloorManager(int t_floorAmount); + FloorManager(int t_floorAmount, TextureRepository *t_texRepo); ~FloorManager(); Floor floors[144]; // Temp change it also in floors.cpp u16 floorAmount; @@ -32,6 +33,7 @@ public: void onAudioTick(); private: + TextureRepository *texRepo; u8 audioOffset, audioMode; u32 audioTick; float trick; diff --git a/src/samples/floors/objects/player.cpp b/src/samples/floors/objects/player.cpp index 1de292f..a79a833 100644 --- a/src/samples/floors/objects/player.cpp +++ b/src/samples/floors/objects/player.cpp @@ -21,9 +21,10 @@ // Constructors/Destructors // ---- -Player::Player(Audio *t_audio) +Player::Player(Audio *t_audio, TextureRepository *t_texRepo) { PRINT_LOG("Creating player object"); + texRepo = t_texRepo; audio = t_audio; gravity = 0.1F; lift = -1.0F; @@ -45,6 +46,8 @@ Player::Player(Audio *t_audio) mesh.setAnimSpeed(0.17F); mesh.playAnimation(0, 0); + texRepo->addByMesh("meshes/player/", mesh, BMP); + walkAdpcm = audio->loadADPCM("sounds/walk.adpcm"); jumpAdpcm = audio->loadADPCM("sounds/jump.adpcm"); boomAdpcm = audio->loadADPCM("sounds/boom.adpcm"); diff --git a/src/samples/floors/objects/player.hpp b/src/samples/floors/objects/player.hpp index 75b1ccb..b233a12 100644 --- a/src/samples/floors/objects/player.hpp +++ b/src/samples/floors/objects/player.hpp @@ -33,7 +33,7 @@ public: float gravity, velocity, lift; Mesh mesh; s16 indexOfCurrentFloor; - Player(Audio *t_audio); + Player(Audio *t_audio, TextureRepository *t_texRepo); ~Player(); void update(const Pad &t_pad, const Camera &t_camera, const FloorManager &t_floorManager, Enemy &enemy); @@ -43,6 +43,7 @@ public: inline const Vector3 &getPosition() const { return mesh.position; } private: + TextureRepository *texRepo; u32 jumpCounter, killedEnemies; Vector3 *getNextPosition(const Pad &t_pad, const Camera &t_camera); FloorsCheck *checkFloors(const FloorManager &t_floorManager, const Vector3 &t_nextPos); From 8a0f5f7b847a48b2ee58a96acaedf7782fecd676 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 7 Dec 2020 22:14:36 +0100 Subject: [PATCH 16/16] refactor #2 --- src/samples/floors/camera.cpp | 11 ----------- src/samples/floors/objects/floor.cpp | 5 ----- src/samples/floors/objects/player.cpp | 6 ------ 3 files changed, 22 deletions(-) diff --git a/src/samples/floors/camera.cpp b/src/samples/floors/camera.cpp index b9c583e..56c4aa1 100644 --- a/src/samples/floors/camera.cpp +++ b/src/samples/floors/camera.cpp @@ -67,15 +67,4 @@ void Camera::followBy(Mesh &t_mesh) position.x = unitCirclePosition.x + t_mesh.position.x; position.y = unitCirclePosition.y + t_mesh.position.y; position.z = unitCirclePosition.z + t_mesh.position.z; - - if (position.x > (-0.04F * verticalLevel) && - position.x < 0.0F && - position.z > (0.998F * verticalLevel)) - { - // TODO - // position.x = 0.0F; - // position.y = 0.0F; - // position.z = 0.0F; - // horizontalLevel = 0.0F; - } } diff --git a/src/samples/floors/objects/floor.cpp b/src/samples/floors/objects/floor.cpp index ac859b8..61662f4 100644 --- a/src/samples/floors/objects/floor.cpp +++ b/src/samples/floors/objects/floor.cpp @@ -37,11 +37,6 @@ Floor::~Floor() {} // Methods // ---- -/** Init floor position and animation timer position - * @param spec pointer to 3D object specification - * @param spiral Spiral position - * @param initOffset Number of floor (index) - */ void Floor::init(const Mesh &mother, const Point &spiral, const u8 &initOffset) { this->mesh.position.set(0.00F, -10.00F, 0.00F); diff --git a/src/samples/floors/objects/player.cpp b/src/samples/floors/objects/player.cpp index a79a833..6d6ae79 100644 --- a/src/samples/floors/objects/player.cpp +++ b/src/samples/floors/objects/player.cpp @@ -64,7 +64,6 @@ Player::~Player() // Methods // ---- -/** Update player position and control gravity */ void Player::update(const Pad &t_pad, const Camera &t_camera, const FloorManager &floorManager, Enemy &enemy) { Vector3 *nextPos = getNextPosition(t_pad, t_camera); @@ -106,7 +105,6 @@ Vector3 *Player::getNextPosition(const Pad &t_pad, const Camera &t_camera) return result; } -/** 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, Enemy &enemy) { if (t_pad.rJoyH >= 200) @@ -203,10 +201,6 @@ void Player::updateGravity(FloorsCheck *t_floorsCheck) } } -// --- -// Private -// --- - FloorsCheck *Player::checkFloors(const FloorManager &t_floorManager, const Vector3 &t_nextPos) { FloorsCheck *result = new FloorsCheck;