Merge branch 'develop' of https://github.com/ps2-tyra/tyra into develop
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -189,7 +189,8 @@ private:
|
||||
TextureType _type;
|
||||
std::vector<TextureLink> texLinks;
|
||||
u32 id;
|
||||
u8 width, height, _isNameSet, _isSizeSet;
|
||||
u16 width, height;
|
||||
u8 _isNameSet, _isSizeSet;
|
||||
unsigned char *data;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ private:
|
||||
packet2_t *currPacket;
|
||||
u8 context;
|
||||
packet2_t *matricesPacket __attribute__((aligned(64)));
|
||||
MATRIX localWorld, localScreen;
|
||||
VECTOR position, rotation;
|
||||
u32 vertCount;
|
||||
};
|
||||
|
||||
@@ -203,19 +203,19 @@ void Renderer::allocateBuffers(float t_screenW, float t_screenH)
|
||||
frameBuffers[0].width = (u16)t_screenW;
|
||||
frameBuffers[0].height = (u16)t_screenH;
|
||||
frameBuffers[0].mask = 0;
|
||||
frameBuffers[0].psm = GS_PSM_32;
|
||||
frameBuffers[0].psm = GS_PSM_24;
|
||||
frameBuffers[0].address = graph_vram_allocate((u16)t_screenW, (u16)t_screenH, frameBuffers[0].psm, GRAPH_ALIGN_PAGE);
|
||||
|
||||
frameBuffers[1].width = (u16)t_screenW;
|
||||
frameBuffers[1].height = (u16)t_screenH;
|
||||
frameBuffers[1].mask = 0;
|
||||
frameBuffers[1].psm = GS_PSM_32;
|
||||
frameBuffers[1].psm = GS_PSM_24;
|
||||
frameBuffers[1].address = graph_vram_allocate((u16)t_screenW, (u16)t_screenH, frameBuffers[1].psm, GRAPH_ALIGN_PAGE);
|
||||
|
||||
zBuffer.enable = DRAW_ENABLE;
|
||||
zBuffer.mask = 0;
|
||||
zBuffer.method = ZTEST_METHOD_GREATER_EQUAL;
|
||||
zBuffer.zsm = GS_ZBUF_32;
|
||||
zBuffer.zsm = GS_ZBUF_24;
|
||||
zBuffer.address = graph_vram_allocate((u16)t_screenW, (u16)t_screenH, zBuffer.zsm, GRAPH_ALIGN_PAGE);
|
||||
PRINT_LOG("Framebuffers, zBuffer set and allocated!");
|
||||
|
||||
|
||||
@@ -71,12 +71,12 @@ void VifSender::uploadMicroProgram()
|
||||
|
||||
void VifSender::sendMatrices(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation)
|
||||
{
|
||||
vec3ToNative(position, t_position, 1.0F);
|
||||
vec3ToNative(rotation, t_rotation, 1.0F);
|
||||
create_local_world(localWorld, position, rotation);
|
||||
create_local_screen(localScreen, localWorld, t_renderData.worldView->data, t_renderData.perspective->data);
|
||||
Matrix viewProj = Matrix();
|
||||
viewProj.rotation(t_rotation); // model matrix
|
||||
viewProj.translate(t_position); // model matrix
|
||||
viewProj *= *t_renderData.worldView * *t_renderData.perspective; // viewproj = model * (view * projection)
|
||||
packet2_reset(matricesPacket, false);
|
||||
packet2_utils_vu_add_unpack_data(matricesPacket, 0, &localScreen, 8, 0);
|
||||
packet2_utils_vu_add_unpack_data(matricesPacket, 0, &viewProj.data, 8, 0);
|
||||
packet2_utils_vu_add_end_tag(matricesPacket);
|
||||
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
|
||||
dma_channel_send_packet2(matricesPacket, DMA_CHANNEL_VIF1, 1);
|
||||
|
||||
@@ -6,6 +6,7 @@ EE_OBJS = \
|
||||
camera.o \
|
||||
objects/player.o \
|
||||
objects/collectible.o \
|
||||
objects/mine.o \
|
||||
dolphin.o \
|
||||
main.o
|
||||
|
||||
|
||||
@@ -14,19 +14,40 @@
|
||||
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() {}
|
||||
Dolphin::~Dolphin()
|
||||
{
|
||||
delete[] oysters;
|
||||
delete[] mines;
|
||||
}
|
||||
|
||||
void Dolphin::onInit()
|
||||
{
|
||||
player.init(engine);
|
||||
engine->renderer->setCameraDefinitions(&camera.worldView, &camera.position, camera.planes);
|
||||
|
||||
engine->audio.loadSong("sound/dirediredocks.wav");
|
||||
engine->audio.playSong();
|
||||
engine->audio.setSongVolume(60);
|
||||
|
||||
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);
|
||||
|
||||
texRepo = engine->renderer->getTextureRepository();
|
||||
|
||||
engine->renderer->disableVSync();
|
||||
@@ -39,9 +60,15 @@ 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);
|
||||
waterOverlay.setMode(MODE_STRETCH);
|
||||
watOverlayTex->addLink(waterOverlay.getId());
|
||||
printf("Loaded.\n");
|
||||
|
||||
@@ -52,6 +79,13 @@ void Dolphin::onInit()
|
||||
water.shouldBeFrustumCulled = false;
|
||||
water.shouldBeBackfaceCulled = false;
|
||||
|
||||
printf("Loading seabed...\n");
|
||||
seabed.loadObj("seabed/", "seabed", 10.0F, false);
|
||||
seabed.position.set(0, -250.0F, 0);
|
||||
texRepo->addByMesh("seabed/", seabed, BMP);
|
||||
seabed.shouldBeBackfaceCulled = false;
|
||||
seabed.shouldBeFrustumCulled = false;
|
||||
|
||||
skybox.loadObj("skybox/", "skybox", 400.0F, false);
|
||||
skybox.shouldBeFrustumCulled = false;
|
||||
|
||||
@@ -81,6 +115,35 @@ 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++)
|
||||
{
|
||||
lifeSprites[i].size.set(64.0F, 64.0F);
|
||||
lifeSprites[i].setMode(MODE_STRETCH);
|
||||
lifeSprites[i].position.set(395 + (64 * i), 0);
|
||||
pLifeTex->addLink(lifeSprites[i].getId());
|
||||
}
|
||||
|
||||
texRepo->addByMesh("dolphin/", player.mesh, BMP);
|
||||
texRepo->addByMesh("sunnyisl/", island, BMP);
|
||||
texRepo->addByMesh("skybox/", skybox, BMP);
|
||||
@@ -93,8 +156,17 @@ 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("PlayerPos (%f,%f), FPS:%f\n", player.mesh.position.x, player.mesh.position.z, this->engine->fps);
|
||||
printf("Delta multiplier: %f\n", 60.0F / engine->fps);
|
||||
|
||||
float xDist = player.mesh.position.x - water.position.x;
|
||||
float zDist = player.mesh.position.z - water.position.z;
|
||||
@@ -113,12 +185,33 @@ 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].setActive(false);
|
||||
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 = vecDist.length();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +226,7 @@ void Dolphin::onUpdate()
|
||||
engine->renderer->draw(water);
|
||||
engine->renderer->draw(skybox);
|
||||
engine->renderer->draw(waterbox);
|
||||
engine->renderer->draw(seabed);
|
||||
for (u8 i = 0; i < OYSTERS_COUNT; i++)
|
||||
{
|
||||
if (oysters[i].isActive())
|
||||
@@ -140,7 +234,25 @@ 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]);
|
||||
}
|
||||
engine->renderer->draw(player.mesh);
|
||||
if (camera.position.y < WATER_LEVEL)
|
||||
{
|
||||
engine->renderer->draw(waterOverlay);
|
||||
engine->audio.setADPCMVolume(0, 0); //Surface ambient
|
||||
engine->audio.setADPCMVolume(65, 1); //Underwater ambient
|
||||
}
|
||||
else
|
||||
{
|
||||
engine->audio.setADPCMVolume(50, 0); //Surface ambient
|
||||
engine->audio.setADPCMVolume(0, 1); //Underwater ambient
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "./camera.hpp"
|
||||
#include "./objects/player.hpp"
|
||||
#include "./objects/collectible.hpp"
|
||||
#include "./objects/mine.hpp"
|
||||
|
||||
class Dolphin : public Game
|
||||
{
|
||||
@@ -33,15 +34,29 @@ public:
|
||||
void onUpdate();
|
||||
|
||||
Engine *engine;
|
||||
static float engineFPS;
|
||||
|
||||
private:
|
||||
/*DO NOT TOUCH ORDER OF DECLARATION!
|
||||
GCC BUG CAUSES RENDERING TO FAIL IN ANY OTHER ORDER OF DECLARATION!*/
|
||||
Mesh seabed;
|
||||
Mesh island;
|
||||
Mesh skybox;
|
||||
Mesh mine;
|
||||
LightBulb bulb;
|
||||
Player player;
|
||||
Camera camera;
|
||||
Mesh island, skybox, water, waterbox;
|
||||
Collectible *oysters;
|
||||
TextureRepository *texRepo;
|
||||
Sprite waterOverlay;
|
||||
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
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
# ______ ____ ___
|
||||
# | \/ ____| |___|
|
||||
# | | | \ | |
|
||||
#-----------------------------------------------------------------------
|
||||
# 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.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++;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include "player.hpp"
|
||||
#include "dolphin.hpp"
|
||||
|
||||
#include <loaders/obj_loader.hpp>
|
||||
#include <loaders/bmp_loader.hpp>
|
||||
@@ -22,14 +23,21 @@ 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;
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
{
|
||||
}
|
||||
|
||||
void Player::init(Engine *t_engine)
|
||||
{
|
||||
pEngine = t_engine;
|
||||
waterImpact = t_engine->audio.loadADPCM("sound/water_impact.sad");
|
||||
}
|
||||
|
||||
void Player::update(Pad &t_pad)
|
||||
{
|
||||
if (lift > 0.0F)
|
||||
@@ -38,7 +46,6 @@ void Player::update(Pad &t_pad)
|
||||
lift += 0.05F;
|
||||
if (lift < 0.1F && lift > -0.1F)
|
||||
lift = 0;
|
||||
velocity = 0;
|
||||
if (t_pad.lJoyV <= 100)
|
||||
velocity = 1;
|
||||
else if (t_pad.lJoyV >= 200)
|
||||
@@ -80,10 +87,26 @@ void Player::update(Pad &t_pad)
|
||||
printf("Swim animation\n");
|
||||
mesh.playAnimation(1, 14, 0);
|
||||
}
|
||||
if (mesh.getCurrentAnimationFrame() == 42)
|
||||
{
|
||||
if (!bIsImpactingWater)
|
||||
{
|
||||
pEngine->audio.setADPCMVolume(50, 2);
|
||||
pEngine->audio.playADPCM(waterImpact, 2);
|
||||
}
|
||||
bIsImpactingWater = true;
|
||||
}
|
||||
else if (bIsImpactingWater)
|
||||
{
|
||||
bIsImpactingWater = false;
|
||||
}
|
||||
|
||||
velocity *= 60.0F / Dolphin::engineFPS; //Moving by deltatime of last frame.
|
||||
mesh.position.z +=
|
||||
Math::cos(mesh.rotation.z) * velocity * (bIsJumping + 1);
|
||||
mesh.position.x +=
|
||||
Math::sin(mesh.rotation.z) * velocity * (bIsJumping + 1);
|
||||
mesh.position.y += lift;
|
||||
|
||||
velocity = 0;
|
||||
}
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
#define WATER_LEVEL -5.0F
|
||||
|
||||
#include "../camera.hpp"
|
||||
#include <audsrv.h>
|
||||
#include <modules/pad.hpp>
|
||||
#include <tamtypes.h>
|
||||
|
||||
class Engine;
|
||||
class Player
|
||||
{
|
||||
|
||||
@@ -25,12 +26,19 @@ public:
|
||||
Mesh mesh;
|
||||
Player();
|
||||
~Player();
|
||||
void init(Engine *t_engine);
|
||||
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;
|
||||
Vector3 playerNextPosition;
|
||||
u8 lifes;
|
||||
audsrv_adpcm_t *waterImpact;
|
||||
Engine *pEngine;
|
||||
u8 bIsImpactingWater;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user