diff --git a/src/samples/dolphin/Makefile b/src/samples/dolphin/Makefile index d59fe5e..c4e5f83 100755 --- a/src/samples/dolphin/Makefile +++ b/src/samples/dolphin/Makefile @@ -1,53 +1,22 @@ -EE_BIN = driver.elf +EE_BIN = dolphin.elf + +TYRA_DIR = ./../../engine EE_OBJS = \ - ../../engine/models/math/matrix.o \ - ../../engine/models/math/plane.o \ - ../../engine/models/math/point.o \ - ../../engine/models/math/vector3.o \ - ../../engine/models/mesh_frame.o \ - ../../engine/models/mesh_material.o \ - ../../engine/models/mesh.o \ - ../../engine/models/mesh_texture.o \ - ../../engine/modules/audio.o \ - ../../engine/modules/camera_base.o \ - ../../engine/modules/file_service.o \ - ../../engine/modules/gif_sender.o \ - ../../engine/modules/light.o \ - ../../engine/modules/pad.o \ - ../../engine/modules/renderer.o \ - ../../engine/modules/texture_repository.o \ - ../../engine/modules/timer.o \ - ../../engine/modules/vif_sender.o \ - ../../engine/utils/math.o \ - ../../engine/utils/string.o \ - ../../engine/loaders/bmp_loader.o \ - ../../engine/loaders/dff_loader.o \ - ../../engine/loaders/md2_loader.o \ - ../../engine/loaders/obj_loader.o \ - ../../engine/vu1_progs/draw3D.o \ - ../../engine/engine.o \ camera.o \ objects/player.o \ - driver.o \ + dolphin.o \ main.o -EE_LIBS = -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ -EE_INCS := -I./../../engine/include $(EE_INCS) -EE_DVP = dvp-as -EE_VCL = vcl +EE_LIBS = -ltyra all: $(EE_BIN) $(EE_STRIP) --strip-all $(EE_BIN) mv $(EE_BIN) bin/$(EE_BIN) rm $(EE_OBJS) -# https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520 -#%.vsm: %.vcl # sudo service binfmt-support start -# $(EE_VCL) $< >> $@ - -%.o: %.vsm - $(EE_DVP) $< -o $@ +rebuild-engine: + cd $(TYRA_DIR) && make clean && make clean: rm -f $(EE_OBJS) @@ -61,5 +30,4 @@ run: $(EE_BIN) rm $(EE_OBJS) cd bin/ && ps2client execee host:$(EE_BIN) -include $(PS2SDK)/samples/Makefile.pref -include $(PS2SDK)/samples/Makefile.eeglobal +include $(TYRA_DIR)/Makefile.pref diff --git a/src/samples/dolphin/camera.cpp b/src/samples/dolphin/camera.cpp index 8ab5c12..0fb871f 100755 --- a/src/samples/dolphin/camera.cpp +++ b/src/samples/dolphin/camera.cpp @@ -14,7 +14,6 @@ const float CAMERA_Y = 15.0F; - Camera::Camera(ScreenSettings *t_screen) : CameraBase(t_screen, &position, &up) { verticalLevel = 80.0F; @@ -35,14 +34,17 @@ void Camera::update(Pad &t_pad, Mesh &t_mesh) 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); diff --git a/src/samples/dolphin/driver.cpp b/src/samples/dolphin/driver.cpp deleted file mode 100755 index 262f811..0000000 --- a/src/samples/dolphin/driver.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Michał Mostowik -*/ - -#include "driver.hpp" -#include "utils/math.hpp" - -Driver::Driver(Engine *t_engine) : engine(t_engine), camera(&engine->screen) -{ - -} - -Driver::~Driver() {} - -void Driver::onInit() -{ - engine->renderer->setCameraDefinitions(&camera.worldView, &camera.position, camera.planes); - - texRepo = engine->renderer->getTextureRepository(); - - engine->renderer->disableVSync(); - - island.loadDff("sunnyisl/", "sunnyisl", 1.0F, false); - island.rotation.x = -1.6F; - island.position.set(0.0F, 10.0F, 20.0F); - island.shouldBeBackfaceCulled = true; - island.shouldBeFrustumCulled = false; - - texRepo->addByMesh("dolphin/",player.mesh); - texRepo->addByMesh("sunnyisl/",island); - - bulb.intensity=55; - bulb.position.set(5.0F,10.0F,10.0f); -} - -void Driver::onUpdate() -{ - player.update(engine->pad); - camera.update(engine->pad,player.mesh); - engine->renderer->draw(island); - engine->renderer->draw(player.mesh); -} diff --git a/src/samples/dolphin/driver.hpp b/src/samples/dolphin/driver.hpp deleted file mode 100755 index ce25589..0000000 --- a/src/samples/dolphin/driver.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -# ______ ____ ___ -# | \/ ____| |___| -# | | | \ | | -#----------------------------------------------------------------------- -# Copyright 2020, tyra - https://github.com/h4570/tyra -# Licenced under Apache License 2.0 -# Michał Mostowik -*/ - -#ifndef _DRIVER_ -#define _DRIVER_ - -#include -#include -#include -#include -#include -#include -#include "./camera.hpp" -#include "./objects/player.hpp" - - -class Driver : public Game -{ - -public: - Driver(Engine* t_engine); - ~Driver(); - - void onInit(); - void onUpdate(); - - Engine *engine; -private: - LightBulb bulb; - Player player; - Camera camera; - Mesh island; - TextureRepository *texRepo; - - -}; - -#endif diff --git a/src/samples/dolphin/main.cpp b/src/samples/dolphin/main.cpp index 4090b93..9c5f37e 100755 --- a/src/samples/dolphin/main.cpp +++ b/src/samples/dolphin/main.cpp @@ -8,14 +8,13 @@ # Michał Mostowik */ -#include "driver.hpp" +#include "dolphin.hpp" int main() { Engine engine = Engine(); - Driver game = Driver(&engine); - game.engine->init(&game,128); + 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 index 851f372..207dfdc 100755 --- a/src/samples/dolphin/objects/player.cpp +++ b/src/samples/dolphin/objects/player.cpp @@ -18,35 +18,71 @@ Player::Player() { - mesh.loadMD2("dolphin/","dolphin",0.05F,true); + mesh.loadMD2("dolphin/", "dolphin", 0.025F, true); mesh.shouldBeFrustumCulled = false; - mesh.position.set(0.0F,20.0F,-10.0f); + 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) +void Player::update(Pad &t_pad) { - velocity=0; - if(t_pad.lJoyV <= 100) - velocity=1; - else if(t_pad.lJoyV >= 200) - velocity=-1; + 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.lJoyH >= 200) + mesh.rotation.z -= 0.1; + else if (t_pad.lJoyH <= 100) + mesh.rotation.z += 0.1; - if(velocity>0 && mesh.getCurrentAnimationFrame()==0) - mesh.playAnimation(0, 14); + if (t_pad.rJoyV >= 200 && lift <= 1) + lift += 0.2F; + else if (t_pad.rJoyV <= 100 && lift >= -1) + lift -= 0.2F; - mesh.position.z+=Math::cos(mesh.rotation.z)*velocity; - mesh.position.x+=Math::sin(mesh.rotation.z)*velocity; + 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 index b996c1c..bd990be 100755 --- a/src/samples/dolphin/objects/player.hpp +++ b/src/samples/dolphin/objects/player.hpp @@ -11,6 +11,8 @@ #ifndef _PLAYER_ #define _PLAYER_ +#define WATER_LEVEL -5.0F + #include "../camera.hpp" #include #include @@ -19,14 +21,15 @@ class Player { public: - float gravity, velocity; + float gravity, velocity, lift; Mesh mesh; Player(); ~Player(); void update(Pad &t_pad); -private: - Vector3 playerNextPosition; +private: + u8 isJumping; + Vector3 playerNextPosition; }; #endif