Merge pull request #1 from Foxar/master

Master to develop
This commit is contained in:
Michał Mostowik
2020-12-10 16:35:09 +01:00
committed by GitHub
8 changed files with 146 additions and 8 deletions
+6 -6
View File
@@ -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
+1
View File
@@ -6,6 +6,7 @@ EE_OBJS = \
camera.o \
objects/player.o \
objects/collectible.o \
objects/mine.o \
dolphin.o \
main.o
+62 -1
View File
@@ -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);
@@ -53,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);
@@ -103,6 +111,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++)
@@ -125,6 +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);
@@ -151,11 +186,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;
@@ -175,6 +231,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]);
+5
View File
@@ -21,6 +21,7 @@
#include "./camera.hpp"
#include "./objects/player.hpp"
#include "./objects/collectible.hpp"
#include "./objects/mine.hpp"
class Dolphin : public Game
{
@@ -41,6 +42,7 @@ private:
Mesh seabed;
Mesh island;
Mesh skybox;
Mesh mine;
LightBulb bulb;
Player player;
Camera camera;
@@ -50,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
+35
View File
@@ -0,0 +1,35 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Michał Mostowik <mostek3pl@gmail.com>
*/
#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++;
}
}
+35
View File
@@ -0,0 +1,35 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Michał Mostowik <mostek3pl@gmail.com>
*/
#ifndef _MINE_
#define _MINE_
#include <tamtypes.h>
#include <models/mesh.hpp>
#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
+1 -1
View File
@@ -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;
}
+1
View File
@@ -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;