From fd29a1157977a8df11af720c3be94b0980dced99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Sobczy=C5=84ski?= <32263891+h4570@users.noreply.github.com> Date: Fri, 4 Dec 2020 08:56:45 +0100 Subject: [PATCH 1/7] fixed all ps2-tyra to h4570 --- README.MD | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.MD b/README.MD index a8d4ff6..972e0cf 100644 --- a/README.MD +++ b/README.MD @@ -99,7 +99,7 @@ This is an example of how to list things you need to use the software and how to 1. Clone the repo ```sh -git clone https://github.com/ps2-tyra/tyra.git +git clone https://github.com/h4570/tyra.git ``` 2. Get into src folder and compile it! ```sh @@ -114,7 +114,7 @@ make ## Roadmap ### Roadmap moved to github kanban: -[https://github.com/h4570/tyra/projects/1](https://github.com/ps2-tyra/tyra/projects/1) +[https://github.com/h4570/tyra/projects/1](https://github.com/h4570/tyra/projects/1) See the [open issues](https://github.com/h4570/tyra/issues) for a list of proposed features (and known issues). @@ -150,9 +150,9 @@ Without these guys, everything would be harder: Project Link: [https://github.com/h4570/tyra](https://github.com/h4570/tyra) -[contributors-shield]: https://img.shields.io/github/contributors/ps2-tyra/tyra.svg?style=flat-square -[contributors-url]: https://github.com/ps2-tyra/tyra/graphs/contributors +[contributors-shield]: https://img.shields.io/github/contributors/h4570/tyra.svg?style=flat-square +[contributors-url]: https://github.com/h4570/tyra/graphs/contributors [linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555 [linkedin-url]: https://linkedin.com/in/sandro-sobczyński-28820b15a/ -[license-shield]: https://img.shields.io/github/license/ps2-tyra/tyra.svg?style=flat-square -[license-url]: https://github.com/ps2-tyra/tyra/blob/master/LICENSE +[license-shield]: https://img.shields.io/github/license/h4570/tyra.svg?style=flat-square +[license-url]: https://github.com/h4570/tyra/blob/master/LICENSE From 1c9351e5e95f8b2451de85b28e71d02411234354 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 10 Dec 2020 12:52:54 +0100 Subject: [PATCH 2/7] Added: Sea mines, when fully implemented, will explode and take lifes from player. --- src/samples/dolphin/dolphin.cpp | 5 +++++ src/samples/dolphin/dolphin.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index 9df9247..053e813 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -74,6 +74,10 @@ void Dolphin::onInit() seabed.shouldBeBackfaceCulled = false; seabed.shouldBeFrustumCulled = false; + mine.loadObj("mine/", "mine", 5.0F, false); + mine.position.set(0, 0, 0); + texRepo->addByMesh("mine/", mine, BMP); + skybox.loadObj("skybox/", "skybox", 400.0F, false); skybox.shouldBeFrustumCulled = false; @@ -168,6 +172,7 @@ void Dolphin::onUpdate() engine->renderer->draw(skybox); engine->renderer->draw(waterbox); engine->renderer->draw(seabed); + engine->renderer->draw(mine); for (u8 i = 0; i < OYSTERS_COUNT; i++) { if (oysters[i].isActive()) diff --git a/src/samples/dolphin/dolphin.hpp b/src/samples/dolphin/dolphin.hpp index 614b94f..f48c149 100755 --- a/src/samples/dolphin/dolphin.hpp +++ b/src/samples/dolphin/dolphin.hpp @@ -41,6 +41,7 @@ private: Mesh seabed; Mesh island; Mesh skybox; + Mesh mine; LightBulb bulb; Player player; Camera camera; From e7aa4d13cc40e17f2fe9a9bd90832cc306e54729 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 10 Dec 2020 13:52:45 +0100 Subject: [PATCH 3/7] Added: Mines now explode and hurt the player, added new makefile and made more mines spawn on game start. --- src/samples/dolphin/Makefile | 1 + src/samples/dolphin/dolphin.cpp | 56 +++++++++++++++++++++++--- src/samples/dolphin/dolphin.hpp | 4 ++ src/samples/dolphin/objects/player.cpp | 2 +- src/samples/dolphin/objects/player.hpp | 1 + 5 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/samples/dolphin/Makefile b/src/samples/dolphin/Makefile index 5c92574..c0b302d 100755 --- a/src/samples/dolphin/Makefile +++ b/src/samples/dolphin/Makefile @@ -6,6 +6,7 @@ EE_OBJS = \ camera.o \ objects/player.o \ objects/collectible.o \ + objects/mine.o \ dolphin.o \ main.o diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index 053e813..cf506a6 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -14,13 +14,15 @@ const u8 WATER_TILE_SCALE = 5; const u8 WATER_SIZE = 100; -const u8 OYSTERS_COUNT = 15; +const u8 MINES_COUNT = 15; +const u8 OYSTERS_COUNT = 5; float Dolphin::engineFPS = 60.F; Dolphin::Dolphin(Engine *t_engine) : engine(t_engine), camera(&engine->screen) { oysters = new Collectible[OYSTERS_COUNT]; + mines = new Mine[MINES_COUNT]; } Dolphin::~Dolphin() {} @@ -37,6 +39,7 @@ void Dolphin::onInit() surfaceAmbient = engine->audio.loadADPCM("sound/surface.sad"); underwaterAmbient = engine->audio.loadADPCM("sound/underwater.sad"); pickupSound = engine->audio.loadADPCM("sound/pickup.sad"); + boomSound = engine->audio.loadADPCM("sound/boom.sad"); engine->audio.playADPCM(surfaceAmbient, 0); engine->audio.playADPCM(underwaterAmbient, 1); @@ -74,10 +77,6 @@ void Dolphin::onInit() seabed.shouldBeBackfaceCulled = false; seabed.shouldBeFrustumCulled = false; - mine.loadObj("mine/", "mine", 5.0F, false); - mine.position.set(0, 0, 0); - texRepo->addByMesh("mine/", mine, BMP); - skybox.loadObj("skybox/", "skybox", 400.0F, false); skybox.shouldBeFrustumCulled = false; @@ -107,6 +106,25 @@ void Dolphin::onInit() oysters[i].mesh.position.set(i * -100, 5.0F, i * -100); } + printf("Loading mine .obj\n"); + mines[0].mesh.loadObj("mine/", "mine", 10.F, false); + printf("Loaded."); + mines[0].mesh.shouldBeBackfaceCulled = false; + mines[0].mesh.shouldBeFrustumCulled = false; + mines[0].mesh.position.set(5, -15, 32); + texRepo->addByMesh("mine/", mines[0].mesh, BMP); + printf("Adding mine texture.\n"); + for (int i = 1; i < MINES_COUNT; i++) + { + printf("Processing mine %d\n", i); + mines[i].mesh.loadFrom(mines[0].mesh); + mines[i].mesh.shouldBeBackfaceCulled = false; + mines[i].mesh.shouldBeFrustumCulled = false; + texRepo->getByMesh(mines[0].mesh.getId(), mines[0].mesh.getMaterial(0).getId()) + ->addLink(mines[i].mesh.getId(), mines[i].mesh.getMaterial(0).getId()); + mines[i].mesh.position.set(i * -10, 0.0F, i * -68); + } + Texture *pLifeTex = texRepo->add("2d/", "life", PNG); //pLifeTex->addLink(lifeSprites[0].getId()); for (int i = 0; i < 3; i++) @@ -129,6 +147,7 @@ void Dolphin::onInit() void Dolphin::onUpdate() { + Dolphin::engineFPS = engine->fps; if (engine->pad.isCrossClicked) printf("Delta multiplier: %f\n", 60.0F / engine->fps); @@ -155,11 +174,32 @@ void Dolphin::onUpdate() { printf("Pickup %d Dist %d\n", i, dist); oysters[i].disappear(); + player.setLife(player.getLifes() + 1); engine->audio.setADPCMVolume(30, 3); engine->audio.playADPCM(pickupSound, 3); } } + for (int i = 0; i < MINES_COUNT; i++) + { + mines[i].update(); + Vector3 vecDist = mines[i].mesh.position - player.mesh.position; + float dist = Math::sqrt((vecDist.x * vecDist.x) + + (vecDist.y * vecDist.y) + + (vecDist.z * vecDist.z)); + if (dist < 20.F && !mines[i].getExplosionTicks()) + { + printf("Vecdist %f,%f,%f\n", vecDist.x, vecDist.y, vecDist.z); + printf("Explode %d Dist %d\n", i, dist); + mines[i].explode(); + player.setLife(player.getLifes() - 1); + //Buffer switching to prevent playing two sounds on one buffer + engine->audio.setADPCMVolume(65, Mine::lastSoundBuffer); + engine->audio.playADPCM(boomSound, Mine::lastSoundBuffer); + Mine::lastSoundBuffer = Mine::lastSoundBuffer == 4 ? 5 : 4; + } + } + if (player.mesh.position.y > WATER_LEVEL - 5) player.mesh.position.y = WATER_LEVEL - 5; @@ -172,7 +212,6 @@ void Dolphin::onUpdate() engine->renderer->draw(skybox); engine->renderer->draw(waterbox); engine->renderer->draw(seabed); - engine->renderer->draw(mine); for (u8 i = 0; i < OYSTERS_COUNT; i++) { if (oysters[i].isActive()) @@ -180,6 +219,11 @@ void Dolphin::onUpdate() engine->renderer->draw(oysters[i].mesh); } } + for (u8 i = 0; i < MINES_COUNT; i++) + { + if (mines[i].getExplosionTicks() < MINE_EXPLOSION_TICKS) + engine->renderer->draw(mines[i].mesh); + } for (u8 i = 0; i < player.getLifes(); i++) { engine->renderer->draw(lifeSprites[i]); diff --git a/src/samples/dolphin/dolphin.hpp b/src/samples/dolphin/dolphin.hpp index f48c149..ad7b3c1 100755 --- a/src/samples/dolphin/dolphin.hpp +++ b/src/samples/dolphin/dolphin.hpp @@ -21,6 +21,7 @@ #include "./camera.hpp" #include "./objects/player.hpp" #include "./objects/collectible.hpp" +#include "./objects/mine.hpp" class Dolphin : public Game { @@ -51,8 +52,11 @@ private: Mesh water; Mesh waterbox; Sprite lifeSprites[3]; + Sprite gameOver; audsrv_adpcm_t *underwaterAmbient, *surfaceAmbient; audsrv_adpcm_t *pickupSound; + audsrv_adpcm_t *boomSound; + Mine *mines; }; #endif diff --git a/src/samples/dolphin/objects/player.cpp b/src/samples/dolphin/objects/player.cpp index 7a8d70a..84669cc 100755 --- a/src/samples/dolphin/objects/player.cpp +++ b/src/samples/dolphin/objects/player.cpp @@ -23,7 +23,7 @@ Player::Player() mesh.shouldBeFrustumCulled = false; mesh.position.set(0.0F, 0.0F, 10.0f); mesh.rotation.x = -1.6F; - mesh.setAnimSpeed(0.05F); + mesh.setAnimSpeed(0.04F); bIsJumping = false; lifes = 3; } diff --git a/src/samples/dolphin/objects/player.hpp b/src/samples/dolphin/objects/player.hpp index 3c37938..3aed608 100755 --- a/src/samples/dolphin/objects/player.hpp +++ b/src/samples/dolphin/objects/player.hpp @@ -30,6 +30,7 @@ public: void update(Pad &t_pad); const u8 &isJumping() { return bIsJumping; } const u8 &getLifes() { return lifes; } + void setLife(const u8 &l) { lifes = lifes = l < 4 ? l : 3; } private: u8 bIsJumping; From 0c0512b37f972fab001cf1750545f4bf3fb2a64c Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 10 Dec 2020 14:38:12 +0100 Subject: [PATCH 4/7] Added: Game over screen --- src/samples/dolphin/dolphin.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index cf506a6..782b529 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -56,6 +56,11 @@ void Dolphin::onInit() island.shouldBeBackfaceCulled = true; island.shouldBeFrustumCulled = false; + gameOver.size.set(640.0F, 480.0F); + Texture *gameOverTex = texRepo->add("2d/", "gameover", PNG); + gameOver.setMode(MODE_STRETCH); + gameOverTex->addLink(gameOver.getId()); + printf("Loading water overlay...\n"); waterOverlay.size.set(640.0F, 480.0F); Texture *watOverlayTex = texRepo->add("2d/", "underwater_overlay", PNG); @@ -147,7 +152,14 @@ void Dolphin::onInit() void Dolphin::onUpdate() { - + if (player.getLifes() <= 0) + { + engine->audio.stopSong(); + engine->audio.setADPCMVolume(0, 0); + engine->audio.setADPCMVolume(75, 1); + engine->renderer->draw(gameOver); + return; + } Dolphin::engineFPS = engine->fps; if (engine->pad.isCrossClicked) printf("Delta multiplier: %f\n", 60.0F / engine->fps); From 5129d53b272c00dee7074b198d1fa8e2a22fd745 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 10 Dec 2020 16:32:01 +0100 Subject: [PATCH 5/7] Added: Missing mine class files. --- src/samples/dolphin/objects/mine.cpp | 35 ++++++++++++++++++++++++++++ src/samples/dolphin/objects/mine.hpp | 35 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/samples/dolphin/objects/mine.cpp create mode 100644 src/samples/dolphin/objects/mine.hpp diff --git a/src/samples/dolphin/objects/mine.cpp b/src/samples/dolphin/objects/mine.cpp new file mode 100644 index 0000000..aff4140 --- /dev/null +++ b/src/samples/dolphin/objects/mine.cpp @@ -0,0 +1,35 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "mine.hpp" + +u8 Mine::lastSoundBuffer = 4; + +Mine::Mine() +{ + //mesh.loadObj("mine/", "mine", 10.F, false); + mesh.position.set(0.0F, 0.0F, 0.0F); + + bExploding = false; + explosionTicks = 0; +} + +Mine::~Mine() +{ +} + +void Mine::update() +{ + if (bExploding && explosionTicks < MINE_EXPLOSION_TICKS) + { + explosionTicks++; + mesh.scale++; + } +} \ No newline at end of file diff --git a/src/samples/dolphin/objects/mine.hpp b/src/samples/dolphin/objects/mine.hpp new file mode 100644 index 0000000..5dce106 --- /dev/null +++ b/src/samples/dolphin/objects/mine.hpp @@ -0,0 +1,35 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _MINE_ +#define _MINE_ + +#include +#include + +#define MINE_EXPLOSION_TICKS 10 + +class Mine +{ +public: + static u8 lastSoundBuffer; + Mesh mesh; + void explode() { bExploding = true; } + void update(); + Mine(); + ~Mine(); + const u8 &getExplosionTicks() { return explosionTicks; } + +private: + u8 bExploding; + u8 explosionTicks; +}; + +#endif From 97151ffc78d888df1ccc244ccaf9cce58fda6933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mostowik?= Date: Thu, 10 Dec 2020 17:37:44 +0100 Subject: [PATCH 6/7] PR Review, removing commented line --- src/samples/dolphin/objects/mine.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/samples/dolphin/objects/mine.cpp b/src/samples/dolphin/objects/mine.cpp index aff4140..9a7a19b 100644 --- a/src/samples/dolphin/objects/mine.cpp +++ b/src/samples/dolphin/objects/mine.cpp @@ -14,7 +14,6 @@ u8 Mine::lastSoundBuffer = 4; Mine::Mine() { - //mesh.loadObj("mine/", "mine", 10.F, false); mesh.position.set(0.0F, 0.0F, 0.0F); bExploding = false; @@ -32,4 +31,4 @@ void Mine::update() explosionTicks++; mesh.scale++; } -} \ No newline at end of file +} From 4bee938106fef599f7bc5ff191786e8ee9041d7f Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 10 Dec 2020 17:49:53 +0100 Subject: [PATCH 7/7] PR Review: Memory de-allocation, misc. fixes. --- src/samples/dolphin/dolphin.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index 782b529..6471834 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -25,7 +25,11 @@ Dolphin::Dolphin(Engine *t_engine) : engine(t_engine), camera(&engine->screen) mines = new Mine[MINES_COUNT]; } -Dolphin::~Dolphin() {} +Dolphin::~Dolphin() +{ + delete[] oysters; + delete[] mines; +} void Dolphin::onInit() { @@ -181,8 +185,8 @@ void Dolphin::onUpdate() { oysters[i].update(); Vector3 vecDist = oysters[i].mesh.position - player.mesh.position; - float dist = Math::sqrt(vecDist.x + vecDist.y + vecDist.z); - if (dist < 2.5F && player.isJumping() && oysters[i].isActive()) + float dist = vecDist.length(); + if (dist < 20.F && player.isJumping() && oysters[i].isActive()) { printf("Pickup %d Dist %d\n", i, dist); oysters[i].disappear(); @@ -196,9 +200,8 @@ void Dolphin::onUpdate() { mines[i].update(); Vector3 vecDist = mines[i].mesh.position - player.mesh.position; - float dist = Math::sqrt((vecDist.x * vecDist.x) + - (vecDist.y * vecDist.y) + - (vecDist.z * vecDist.z)); + float dist = vecDist.length(); + if (dist < 20.F && !mines[i].getExplosionTicks()) { printf("Vecdist %f,%f,%f\n", vecDist.x, vecDist.y, vecDist.z);