diff --git a/src/samples/dolphin/Makefile b/src/samples/dolphin/Makefile index c4e5f83..5c92574 100755 --- a/src/samples/dolphin/Makefile +++ b/src/samples/dolphin/Makefile @@ -5,6 +5,7 @@ TYRA_DIR = ./../../engine EE_OBJS = \ camera.o \ objects/player.o \ + objects/collectible.o \ dolphin.o \ main.o diff --git a/src/samples/dolphin/camera.cpp b/src/samples/dolphin/camera.cpp index 0fb871f..5c122f7 100755 --- a/src/samples/dolphin/camera.cpp +++ b/src/samples/dolphin/camera.cpp @@ -16,7 +16,7 @@ const float CAMERA_Y = 15.0F; Camera::Camera(ScreenSettings *t_screen) : CameraBase(t_screen, &position, &up) { - verticalLevel = 80.0F; + verticalLevel = 30.0F; up.x = 0.0F; up.y = 1.0F; up.z = 0.0F; @@ -26,6 +26,10 @@ Camera::~Camera() {} 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); followBy(t_mesh); 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) { - if (t_pad.rJoyH <= 50) + if (t_pad.rJoyH <= 100) 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; diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index 8b622b3..704a04b 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -11,11 +11,14 @@ #include "dolphin.hpp" #include "utils/math.hpp" -const u8 WATER_TILE_SCALE = 5.0F; -const u8 WATER_SIZE = 100.0F; +const u8 WATER_TILE_SCALE = 5; +const u8 WATER_SIZE = 100; + +const u8 OYSTERS_COUNT = 15; Dolphin::Dolphin(Engine *t_engine) : engine(t_engine), camera(&engine->screen) { + oysters = new Collectible[OYSTERS_COUNT]; } Dolphin::~Dolphin() {} @@ -29,15 +32,15 @@ void Dolphin::onInit() engine->renderer->disableVSync(); printf("loading island..\n"); - island.loadDff("sunnyisl/", "sunnyisl", 1.0F, false); + island.loadDff("sunnyisl/", "sunnyisl", 5.0F, false); printf("Loaded..\n"); 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.shouldBeFrustumCulled = false; 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); watOverlayTex->addLink(waterOverlay.getId()); printf("Loaded.\n"); @@ -58,6 +61,26 @@ void Dolphin::onInit() waterbox.rotation.x = Math::PI; 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("sunnyisl/", island, BMP); texRepo->addByMesh("skybox/", skybox, BMP); @@ -86,6 +109,19 @@ void Dolphin::onUpdate() 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) player.mesh.position.y = WATER_LEVEL - 5; @@ -97,7 +133,14 @@ void Dolphin::onUpdate() engine->renderer->draw(water); engine->renderer->draw(skybox); 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); - //if (player.mesh.position.y < WATER_LEVEL) - //engine->renderer->draw(waterOverlay); + if (camera.position.y < WATER_LEVEL) + engine->renderer->draw(waterOverlay); } diff --git a/src/samples/dolphin/dolphin.hpp b/src/samples/dolphin/dolphin.hpp index 6c00556..9630f5e 100755 --- a/src/samples/dolphin/dolphin.hpp +++ b/src/samples/dolphin/dolphin.hpp @@ -11,7 +11,6 @@ #ifndef _DRIVER_ #define _DRIVER_ - #include #include #include @@ -21,6 +20,7 @@ #include #include "./camera.hpp" #include "./objects/player.hpp" +#include "./objects/collectible.hpp" class Dolphin : public Game { @@ -39,6 +39,7 @@ private: Player player; Camera camera; Mesh island, skybox, water, waterbox; + Collectible *oysters; TextureRepository *texRepo; Sprite waterOverlay; }; diff --git a/src/samples/dolphin/main.cpp b/src/samples/dolphin/main.cpp index 9c5f37e..d094a17 100755 --- a/src/samples/dolphin/main.cpp +++ b/src/samples/dolphin/main.cpp @@ -13,6 +13,7 @@ int main() { Engine engine = Engine(); + engine.screen.fov = 75.F; Dolphin game = Dolphin(&engine); game.engine->init(&game, 128); SleepThread(); diff --git a/src/samples/dolphin/objects/collectible.cpp b/src/samples/dolphin/objects/collectible.cpp new file mode 100644 index 0000000..9cd7d78 --- /dev/null +++ b/src/samples/dolphin/objects/collectible.cpp @@ -0,0 +1,51 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "collectible.hpp" + +#include +#include +#include +#include +#include + +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; + } + } +} diff --git a/src/samples/dolphin/objects/collectible.hpp b/src/samples/dolphin/objects/collectible.hpp new file mode 100644 index 0000000..32795ea --- /dev/null +++ b/src/samples/dolphin/objects/collectible.hpp @@ -0,0 +1,35 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _COLLECTIBLE_ +#define _COLLECTIBLE_ + +#include "../camera.hpp" +#include + +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 diff --git a/src/samples/dolphin/objects/player.cpp b/src/samples/dolphin/objects/player.cpp index 207dfdc..aafe048 100755 --- a/src/samples/dolphin/objects/player.cpp +++ b/src/samples/dolphin/objects/player.cpp @@ -23,7 +23,7 @@ Player::Player() mesh.position.set(0.0F, 0.0F, 10.0f); mesh.rotation.x = -1.6F; mesh.setAnimSpeed(0.05F); - isJumping = false; + bIsJumping = false; } Player::~Player() @@ -45,9 +45,9 @@ void Player::update(Pad &t_pad) velocity = -1; if (t_pad.lJoyH >= 200) - mesh.rotation.z -= 0.1; + mesh.rotation.z -= 0.05; else if (t_pad.lJoyH <= 100) - mesh.rotation.z += 0.1; + mesh.rotation.z += 0.05; if (t_pad.rJoyV >= 200 && lift <= 1) lift += 0.2F; @@ -62,16 +62,17 @@ void Player::update(Pad &t_pad) } if (mesh.getCurrentAnimationFrame() > 25 && mesh.getCurrentAnimationFrame() < 47) - isJumping = true; + bIsJumping = true; else - isJumping = false; - + bIsJumping = false; + /* if (lift < 0) mesh.rotation.y = 1; else if (lift > 0) mesh.rotation.y = -1; else mesh.rotation.y = 0; + */ if (velocity > 0 && mesh.getCurrentAnimationFrame() == 0) { @@ -81,8 +82,8 @@ void Player::update(Pad &t_pad) } mesh.position.z += - Math::cos(mesh.rotation.z) * velocity * (isJumping + 1); + Math::cos(mesh.rotation.z) * velocity * (bIsJumping + 1); mesh.position.x += - Math::sin(mesh.rotation.z) * velocity * (isJumping + 1); + Math::sin(mesh.rotation.z) * velocity * (bIsJumping + 1); mesh.position.y += lift; -} \ No newline at end of file +} diff --git a/src/samples/dolphin/objects/player.hpp b/src/samples/dolphin/objects/player.hpp index bd990be..c615d13 100755 --- a/src/samples/dolphin/objects/player.hpp +++ b/src/samples/dolphin/objects/player.hpp @@ -26,9 +26,10 @@ public: Player(); ~Player(); void update(Pad &t_pad); + const u8 &isJumping() { return bIsJumping; } private: - u8 isJumping; + u8 bIsJumping; Vector3 playerNextPosition; };