Merge pull request #42 from Foxar/master
Dolphin sample: Controls adjusted, collectibles float up on pickup, camera adjusted.
This commit is contained in:
@@ -5,6 +5,7 @@ TYRA_DIR = ./../../engine
|
|||||||
EE_OBJS = \
|
EE_OBJS = \
|
||||||
camera.o \
|
camera.o \
|
||||||
objects/player.o \
|
objects/player.o \
|
||||||
|
objects/collectible.o \
|
||||||
dolphin.o \
|
dolphin.o \
|
||||||
main.o
|
main.o
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const float CAMERA_Y = 15.0F;
|
|||||||
|
|
||||||
Camera::Camera(ScreenSettings *t_screen) : CameraBase(t_screen, &position, &up)
|
Camera::Camera(ScreenSettings *t_screen) : CameraBase(t_screen, &position, &up)
|
||||||
{
|
{
|
||||||
verticalLevel = 80.0F;
|
verticalLevel = 30.0F;
|
||||||
up.x = 0.0F;
|
up.x = 0.0F;
|
||||||
up.y = 1.0F;
|
up.y = 1.0F;
|
||||||
up.z = 0.0F;
|
up.z = 0.0F;
|
||||||
@@ -26,6 +26,10 @@ Camera::~Camera() {}
|
|||||||
|
|
||||||
void Camera::update(Pad &t_pad, Mesh &t_mesh)
|
void Camera::update(Pad &t_pad, Mesh &t_mesh)
|
||||||
{
|
{
|
||||||
|
float cameraRot = (t_mesh.rotation.z * 180 / Math::PI) - (horizontalLevel * 180 / Math::PI);
|
||||||
|
cameraRot += 180;
|
||||||
|
cameraRot /= 15;
|
||||||
|
horizontalLevel += cameraRot / (180 / Math::PI);
|
||||||
rotate(t_pad);
|
rotate(t_pad);
|
||||||
followBy(t_mesh);
|
followBy(t_mesh);
|
||||||
Vector3 lookPos = Vector3(t_mesh.position.x, t_mesh.position.y + 10.0F, t_mesh.position.z);
|
Vector3 lookPos = Vector3(t_mesh.position.x, t_mesh.position.y + 10.0F, t_mesh.position.z);
|
||||||
@@ -35,10 +39,10 @@ void Camera::update(Pad &t_pad, Mesh &t_mesh)
|
|||||||
void Camera::rotate(Pad &t_pad)
|
void Camera::rotate(Pad &t_pad)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (t_pad.rJoyH <= 50)
|
if (t_pad.rJoyH <= 100)
|
||||||
horizontalLevel -= 0.08;
|
horizontalLevel -= 0.08;
|
||||||
else if (t_pad.rJoyH >= 200)
|
else if (t_pad.rJoyH >= 200)
|
||||||
horizontalLevel += 0.04;
|
horizontalLevel += 0.08;
|
||||||
/*
|
/*
|
||||||
if (t_pad.rJoyV <= 50 && verticalLevel > 25.0F)
|
if (t_pad.rJoyV <= 50 && verticalLevel > 25.0F)
|
||||||
verticalLevel -= 0.9F;
|
verticalLevel -= 0.9F;
|
||||||
|
|||||||
@@ -11,11 +11,14 @@
|
|||||||
#include "dolphin.hpp"
|
#include "dolphin.hpp"
|
||||||
#include "utils/math.hpp"
|
#include "utils/math.hpp"
|
||||||
|
|
||||||
const u8 WATER_TILE_SCALE = 5.0F;
|
const u8 WATER_TILE_SCALE = 5;
|
||||||
const u8 WATER_SIZE = 100.0F;
|
const u8 WATER_SIZE = 100;
|
||||||
|
|
||||||
|
const u8 OYSTERS_COUNT = 15;
|
||||||
|
|
||||||
Dolphin::Dolphin(Engine *t_engine) : engine(t_engine), camera(&engine->screen)
|
Dolphin::Dolphin(Engine *t_engine) : engine(t_engine), camera(&engine->screen)
|
||||||
{
|
{
|
||||||
|
oysters = new Collectible[OYSTERS_COUNT];
|
||||||
}
|
}
|
||||||
|
|
||||||
Dolphin::~Dolphin() {}
|
Dolphin::~Dolphin() {}
|
||||||
@@ -29,15 +32,15 @@ void Dolphin::onInit()
|
|||||||
engine->renderer->disableVSync();
|
engine->renderer->disableVSync();
|
||||||
|
|
||||||
printf("loading island..\n");
|
printf("loading island..\n");
|
||||||
island.loadDff("sunnyisl/", "sunnyisl", 1.0F, false);
|
island.loadDff("sunnyisl/", "sunnyisl", 5.0F, false);
|
||||||
printf("Loaded..\n");
|
printf("Loaded..\n");
|
||||||
island.rotation.x = -1.6F;
|
island.rotation.x = -1.6F;
|
||||||
island.position.set(0.0F, 10.0F, 20.0F);
|
island.position.set(0.0F, 60.0F, 20.0F);
|
||||||
island.shouldBeBackfaceCulled = true;
|
island.shouldBeBackfaceCulled = true;
|
||||||
island.shouldBeFrustumCulled = false;
|
island.shouldBeFrustumCulled = false;
|
||||||
|
|
||||||
printf("Loading water overlay...\n");
|
printf("Loading water overlay...\n");
|
||||||
waterOverlay.size.set(100.0F, 100.0F);
|
waterOverlay.size.set(640.0F, 480.0F);
|
||||||
Texture *watOverlayTex = texRepo->add("2d/", "underwater_overlay", PNG);
|
Texture *watOverlayTex = texRepo->add("2d/", "underwater_overlay", PNG);
|
||||||
watOverlayTex->addLink(waterOverlay.getId());
|
watOverlayTex->addLink(waterOverlay.getId());
|
||||||
printf("Loaded.\n");
|
printf("Loaded.\n");
|
||||||
@@ -58,6 +61,26 @@ void Dolphin::onInit()
|
|||||||
waterbox.rotation.x = Math::PI;
|
waterbox.rotation.x = Math::PI;
|
||||||
waterbox.position.y = -100.F;
|
waterbox.position.y = -100.F;
|
||||||
|
|
||||||
|
printf("Loading oyster dff\n");
|
||||||
|
//oysters[0].loadDff("oyster/", "oyster", 1.F, false);
|
||||||
|
oysters[0].mesh.loadObj("oyster/", "oyster", 10.F, false);
|
||||||
|
printf("Loaded.");
|
||||||
|
oysters[0].mesh.shouldBeBackfaceCulled = false;
|
||||||
|
oysters[0].mesh.shouldBeFrustumCulled = false;
|
||||||
|
oysters[0].mesh.position.set(15, 0, 15);
|
||||||
|
texRepo->addByMesh("oyster/", oysters[0].mesh, BMP);
|
||||||
|
printf("Adding oyster texture.\n");
|
||||||
|
for (int i = 1; i < OYSTERS_COUNT; i++)
|
||||||
|
{
|
||||||
|
printf("Processing oyster %d\n", i);
|
||||||
|
oysters[i].mesh.loadFrom(oysters[0].mesh);
|
||||||
|
oysters[i].mesh.shouldBeBackfaceCulled = false;
|
||||||
|
oysters[i].mesh.shouldBeFrustumCulled = false;
|
||||||
|
texRepo->getByMesh(oysters[0].mesh.getId(), oysters[0].mesh.getMaterial(0).getId())
|
||||||
|
->addLink(oysters[i].mesh.getId(), oysters[i].mesh.getMaterial(0).getId());
|
||||||
|
oysters[i].mesh.position.set(i * -100, 5.0F, i * -100);
|
||||||
|
}
|
||||||
|
|
||||||
texRepo->addByMesh("dolphin/", player.mesh, BMP);
|
texRepo->addByMesh("dolphin/", player.mesh, BMP);
|
||||||
texRepo->addByMesh("sunnyisl/", island, BMP);
|
texRepo->addByMesh("sunnyisl/", island, BMP);
|
||||||
texRepo->addByMesh("skybox/", skybox, BMP);
|
texRepo->addByMesh("skybox/", skybox, BMP);
|
||||||
@@ -86,6 +109,19 @@ void Dolphin::onUpdate()
|
|||||||
water.position.z = (player.mesh.position.z / WATER_SIZE) * WATER_SIZE;
|
water.position.z = (player.mesh.position.z / WATER_SIZE) * WATER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < OYSTERS_COUNT; i++)
|
||||||
|
{
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
printf("Pickup %d Dist %d\n", i, dist);
|
||||||
|
//oysters[i].setActive(false);
|
||||||
|
oysters[i].disappear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (player.mesh.position.y > WATER_LEVEL - 5)
|
if (player.mesh.position.y > WATER_LEVEL - 5)
|
||||||
player.mesh.position.y = WATER_LEVEL - 5;
|
player.mesh.position.y = WATER_LEVEL - 5;
|
||||||
|
|
||||||
@@ -97,7 +133,14 @@ void Dolphin::onUpdate()
|
|||||||
engine->renderer->draw(water);
|
engine->renderer->draw(water);
|
||||||
engine->renderer->draw(skybox);
|
engine->renderer->draw(skybox);
|
||||||
engine->renderer->draw(waterbox);
|
engine->renderer->draw(waterbox);
|
||||||
|
for (u8 i = 0; i < OYSTERS_COUNT; i++)
|
||||||
|
{
|
||||||
|
if (oysters[i].isActive())
|
||||||
|
{
|
||||||
|
engine->renderer->draw(oysters[i].mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
engine->renderer->draw(player.mesh);
|
engine->renderer->draw(player.mesh);
|
||||||
//if (player.mesh.position.y < WATER_LEVEL)
|
if (camera.position.y < WATER_LEVEL)
|
||||||
//engine->renderer->draw(waterOverlay);
|
engine->renderer->draw(waterOverlay);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#ifndef _DRIVER_
|
#ifndef _DRIVER_
|
||||||
#define _DRIVER_
|
#define _DRIVER_
|
||||||
|
|
||||||
|
|
||||||
#include <tamtypes.h>
|
#include <tamtypes.h>
|
||||||
#include <audsrv.h>
|
#include <audsrv.h>
|
||||||
#include <game.hpp>
|
#include <game.hpp>
|
||||||
@@ -21,6 +20,7 @@
|
|||||||
#include <modules/texture_repository.hpp>
|
#include <modules/texture_repository.hpp>
|
||||||
#include "./camera.hpp"
|
#include "./camera.hpp"
|
||||||
#include "./objects/player.hpp"
|
#include "./objects/player.hpp"
|
||||||
|
#include "./objects/collectible.hpp"
|
||||||
|
|
||||||
class Dolphin : public Game
|
class Dolphin : public Game
|
||||||
{
|
{
|
||||||
@@ -39,6 +39,7 @@ private:
|
|||||||
Player player;
|
Player player;
|
||||||
Camera camera;
|
Camera camera;
|
||||||
Mesh island, skybox, water, waterbox;
|
Mesh island, skybox, water, waterbox;
|
||||||
|
Collectible *oysters;
|
||||||
TextureRepository *texRepo;
|
TextureRepository *texRepo;
|
||||||
Sprite waterOverlay;
|
Sprite waterOverlay;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Engine engine = Engine();
|
Engine engine = Engine();
|
||||||
|
engine.screen.fov = 75.F;
|
||||||
Dolphin game = Dolphin(&engine);
|
Dolphin game = Dolphin(&engine);
|
||||||
game.engine->init(&game, 128);
|
game.engine->init(&game, 128);
|
||||||
SleepThread();
|
SleepThread();
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Michał Mostowik <mostek3pl@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "collectible.hpp"
|
||||||
|
|
||||||
|
#include <loaders/obj_loader.hpp>
|
||||||
|
#include <loaders/bmp_loader.hpp>
|
||||||
|
#include <modules/gif_sender.hpp>
|
||||||
|
#include <utils/debug.hpp>
|
||||||
|
#include <utils/math.hpp>
|
||||||
|
|
||||||
|
Collectible::Collectible()
|
||||||
|
{
|
||||||
|
mesh.loadObj("oyster/", "oyster", 10.F, false);
|
||||||
|
mesh.shouldBeFrustumCulled = false;
|
||||||
|
mesh.position.set(0.0F, 0.0F, 0.0f);
|
||||||
|
bActive = true;
|
||||||
|
bDisappearing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collectible::~Collectible()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Collectible::disappear()
|
||||||
|
{
|
||||||
|
bDisappearing = true;
|
||||||
|
lift = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Collectible::update()
|
||||||
|
{
|
||||||
|
mesh.rotation.y += 0.08F;
|
||||||
|
if (bDisappearing)
|
||||||
|
{
|
||||||
|
mesh.position.y += lift;
|
||||||
|
lift = lift > 0 ? lift / 2 : 0;
|
||||||
|
if (lift < 1)
|
||||||
|
{
|
||||||
|
setActive(false);
|
||||||
|
bDisappearing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
# ______ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2020, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licenced under Apache License 2.0
|
||||||
|
# Michał Mostowik <mostek3pl@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _COLLECTIBLE_
|
||||||
|
#define _COLLECTIBLE_
|
||||||
|
|
||||||
|
#include "../camera.hpp"
|
||||||
|
#include <tamtypes.h>
|
||||||
|
|
||||||
|
class Collectible
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
float rotation;
|
||||||
|
Mesh mesh;
|
||||||
|
Collectible();
|
||||||
|
~Collectible();
|
||||||
|
void update();
|
||||||
|
void disappear();
|
||||||
|
void setActive(const u8 &b) { bActive = b; }
|
||||||
|
u8 isActive() { return bActive; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
u8 bActive, bDisappearing;
|
||||||
|
u8 lift;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -23,7 +23,7 @@ Player::Player()
|
|||||||
mesh.position.set(0.0F, 0.0F, 10.0f);
|
mesh.position.set(0.0F, 0.0F, 10.0f);
|
||||||
mesh.rotation.x = -1.6F;
|
mesh.rotation.x = -1.6F;
|
||||||
mesh.setAnimSpeed(0.05F);
|
mesh.setAnimSpeed(0.05F);
|
||||||
isJumping = false;
|
bIsJumping = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
@@ -45,9 +45,9 @@ void Player::update(Pad &t_pad)
|
|||||||
velocity = -1;
|
velocity = -1;
|
||||||
|
|
||||||
if (t_pad.lJoyH >= 200)
|
if (t_pad.lJoyH >= 200)
|
||||||
mesh.rotation.z -= 0.1;
|
mesh.rotation.z -= 0.05;
|
||||||
else if (t_pad.lJoyH <= 100)
|
else if (t_pad.lJoyH <= 100)
|
||||||
mesh.rotation.z += 0.1;
|
mesh.rotation.z += 0.05;
|
||||||
|
|
||||||
if (t_pad.rJoyV >= 200 && lift <= 1)
|
if (t_pad.rJoyV >= 200 && lift <= 1)
|
||||||
lift += 0.2F;
|
lift += 0.2F;
|
||||||
@@ -62,16 +62,17 @@ void Player::update(Pad &t_pad)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mesh.getCurrentAnimationFrame() > 25 && mesh.getCurrentAnimationFrame() < 47)
|
if (mesh.getCurrentAnimationFrame() > 25 && mesh.getCurrentAnimationFrame() < 47)
|
||||||
isJumping = true;
|
bIsJumping = true;
|
||||||
else
|
else
|
||||||
isJumping = false;
|
bIsJumping = false;
|
||||||
|
/*
|
||||||
if (lift < 0)
|
if (lift < 0)
|
||||||
mesh.rotation.y = 1;
|
mesh.rotation.y = 1;
|
||||||
else if (lift > 0)
|
else if (lift > 0)
|
||||||
mesh.rotation.y = -1;
|
mesh.rotation.y = -1;
|
||||||
else
|
else
|
||||||
mesh.rotation.y = 0;
|
mesh.rotation.y = 0;
|
||||||
|
*/
|
||||||
|
|
||||||
if (velocity > 0 && mesh.getCurrentAnimationFrame() == 0)
|
if (velocity > 0 && mesh.getCurrentAnimationFrame() == 0)
|
||||||
{
|
{
|
||||||
@@ -81,8 +82,8 @@ void Player::update(Pad &t_pad)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mesh.position.z +=
|
mesh.position.z +=
|
||||||
Math::cos(mesh.rotation.z) * velocity * (isJumping + 1);
|
Math::cos(mesh.rotation.z) * velocity * (bIsJumping + 1);
|
||||||
mesh.position.x +=
|
mesh.position.x +=
|
||||||
Math::sin(mesh.rotation.z) * velocity * (isJumping + 1);
|
Math::sin(mesh.rotation.z) * velocity * (bIsJumping + 1);
|
||||||
mesh.position.y += lift;
|
mesh.position.y += lift;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ public:
|
|||||||
Player();
|
Player();
|
||||||
~Player();
|
~Player();
|
||||||
void update(Pad &t_pad);
|
void update(Pad &t_pad);
|
||||||
|
const u8 &isJumping() { return bIsJumping; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u8 isJumping;
|
u8 bIsJumping;
|
||||||
Vector3 playerNextPosition;
|
Vector3 playerNextPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user