diff --git a/src/samples/dolphin/Makefile b/src/samples/dolphin/Makefile new file mode 100755 index 0000000..c4e5f83 --- /dev/null +++ b/src/samples/dolphin/Makefile @@ -0,0 +1,33 @@ +EE_BIN = dolphin.elf + +TYRA_DIR = ./../../engine + +EE_OBJS = \ + camera.o \ + objects/player.o \ + dolphin.o \ + main.o + +EE_LIBS = -ltyra + +all: $(EE_BIN) + $(EE_STRIP) --strip-all $(EE_BIN) + mv $(EE_BIN) bin/$(EE_BIN) + rm $(EE_OBJS) + +rebuild-engine: + cd $(TYRA_DIR) && make clean && make + +clean: + rm -f $(EE_OBJS) + +run: $(EE_BIN) + killall -v ps2client || true + ps2client reset + ps2client reset + $(EE_STRIP) --strip-all $(EE_BIN) + mv $(EE_BIN) bin/$(EE_BIN) + rm $(EE_OBJS) + cd bin/ && ps2client execee host:$(EE_BIN) + +include $(TYRA_DIR)/Makefile.pref diff --git a/src/samples/dolphin/camera.cpp b/src/samples/dolphin/camera.cpp new file mode 100755 index 0000000..0fb871f --- /dev/null +++ b/src/samples/dolphin/camera.cpp @@ -0,0 +1,69 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "camera.hpp" + +#include + +const float CAMERA_Y = 15.0F; + +Camera::Camera(ScreenSettings *t_screen) : CameraBase(t_screen, &position, &up) +{ + verticalLevel = 80.0F; + up.x = 0.0F; + up.y = 1.0F; + up.z = 0.0F; +} + +Camera::~Camera() {} + +void Camera::update(Pad &t_pad, Mesh &t_mesh) +{ + rotate(t_pad); + followBy(t_mesh); + Vector3 lookPos = Vector3(t_mesh.position.x, t_mesh.position.y + 10.0F, t_mesh.position.z); + lookAt(lookPos); +} + +void Camera::rotate(Pad &t_pad) +{ + + if (t_pad.rJoyH <= 50) + horizontalLevel -= 0.08; + else if (t_pad.rJoyH >= 200) + horizontalLevel += 0.04; + /* + if (t_pad.rJoyV <= 50 && verticalLevel > 25.0F) + verticalLevel -= 0.9F; + else if (t_pad.rJoyV >= 200 && verticalLevel < 80.0F) + verticalLevel += 0.9F; + */ + unitCirclePosition.x = (Math::sin(horizontalLevel) * verticalLevel); + unitCirclePosition.y = CAMERA_Y; + unitCirclePosition.z = (Math::cos(horizontalLevel) * verticalLevel); +} + +void Camera::followBy(Mesh &t_mesh) +{ + position.x = unitCirclePosition.x + t_mesh.position.x; + position.y = unitCirclePosition.y + t_mesh.position.y; + position.z = unitCirclePosition.z + t_mesh.position.z; + + if (position.x > (-0.04F * verticalLevel) && + position.x < 0.0F && + position.z > (0.998F * verticalLevel)) + { + // TODO + // position.x = 0.0F; + // position.y = 0.0F; + // position.z = 0.0F; + // horizontalLevel = 0.0F; + } +} \ No newline at end of file diff --git a/src/samples/dolphin/camera.hpp b/src/samples/dolphin/camera.hpp new file mode 100755 index 0000000..7bcbde3 --- /dev/null +++ b/src/samples/dolphin/camera.hpp @@ -0,0 +1,41 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _CAMERA_ +#define _CAMERA_ + +#include +#include +#include +#include +#include +#include + +class Camera : public CameraBase +{ + +public: + Vector3 position,up, unitCirclePosition; + float horizontalLevel, verticalLevel; + + Camera(ScreenSettings *t_screen); + ~Camera(); + + void update(Pad &t_pad, Mesh &t_mesh); + void rotate(Pad &t_pad); + void followBy(Mesh &t_mesh); + +protected: + Vector3 *getPosition() { return &position; }; + Vector3 *getUp() { return &up; }; + ScreenSettings screen; +}; + +#endif diff --git a/src/samples/dolphin/main.cpp b/src/samples/dolphin/main.cpp new file mode 100755 index 0000000..9c5f37e --- /dev/null +++ b/src/samples/dolphin/main.cpp @@ -0,0 +1,20 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "dolphin.hpp" + +int main() +{ + Engine engine = Engine(); + Dolphin game = Dolphin(&engine); + game.engine->init(&game, 128); + SleepThread(); + return 0; +} \ No newline at end of file diff --git a/src/samples/dolphin/objects/player.cpp b/src/samples/dolphin/objects/player.cpp new file mode 100755 index 0000000..207dfdc --- /dev/null +++ b/src/samples/dolphin/objects/player.cpp @@ -0,0 +1,88 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "player.hpp" + +#include +#include +#include +#include +#include + +Player::Player() +{ + mesh.loadMD2("dolphin/", "dolphin", 0.025F, true); + mesh.shouldBeFrustumCulled = false; + mesh.position.set(0.0F, 0.0F, 10.0f); + mesh.rotation.x = -1.6F; + mesh.setAnimSpeed(0.05F); + isJumping = false; +} + +Player::~Player() +{ +} + +void Player::update(Pad &t_pad) +{ + if (lift > 0.0F) + lift -= 0.05F; + if (lift < 0.0F) + 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) + velocity = -1; + + if (t_pad.lJoyH >= 200) + mesh.rotation.z -= 0.1; + else if (t_pad.lJoyH <= 100) + mesh.rotation.z += 0.1; + + if (t_pad.rJoyV >= 200 && lift <= 1) + lift += 0.2F; + else if (t_pad.rJoyV <= 100 && lift >= -1) + lift -= 0.2F; + + if (t_pad.isCrossClicked && mesh.getCurrentAnimationFrame() <= 14 && WATER_LEVEL - 15 < mesh.position.y) + { + printf("Cross\n"); + mesh.setAnimSpeed(0.8F); + mesh.playAnimation(14, 58, 0); + } + + if (mesh.getCurrentAnimationFrame() > 25 && mesh.getCurrentAnimationFrame() < 47) + isJumping = true; + else + isJumping = 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) + { + mesh.setAnimSpeed(0.05F); + printf("Swim animation\n"); + mesh.playAnimation(1, 14, 0); + } + + mesh.position.z += + Math::cos(mesh.rotation.z) * velocity * (isJumping + 1); + mesh.position.x += + Math::sin(mesh.rotation.z) * velocity * (isJumping + 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 new file mode 100755 index 0000000..bd990be --- /dev/null +++ b/src/samples/dolphin/objects/player.hpp @@ -0,0 +1,35 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _PLAYER_ +#define _PLAYER_ + +#define WATER_LEVEL -5.0F + +#include "../camera.hpp" +#include +#include + +class Player +{ + +public: + float gravity, velocity, lift; + Mesh mesh; + Player(); + ~Player(); + void update(Pad &t_pad); + +private: + u8 isJumping; + Vector3 playerNextPosition; +}; + +#endif