diff --git a/samples/golf/src/golf/GolfState.cpp b/samples/golf/src/golf/GolfState.cpp index 31b92e0db..e3d002434 100644 --- a/samples/golf/src/golf/GolfState.cpp +++ b/samples/golf/src/golf/GolfState.cpp @@ -1505,6 +1505,8 @@ void GolfState::handleMessage(const cro::Message& msg) e.getComponent().active = false; }; m_gameScene.getSystem()->sendCommand(cmd); + + m_inputParser.setActive(false, m_currentPlayer.terrain); } break; case GolfEvent::NiceTiming: diff --git a/samples/scratchpad/src/pseuthe/PseutheBackgroundState.cpp b/samples/scratchpad/src/pseuthe/PseutheBackgroundState.cpp index c1bfe1e3d..f02caf9c5 100644 --- a/samples/scratchpad/src/pseuthe/PseutheBackgroundState.cpp +++ b/samples/scratchpad/src/pseuthe/PseutheBackgroundState.cpp @@ -49,10 +49,12 @@ PseutheBackgroundState::PseutheBackgroundState(cro::StateStack& stack, cro::Stat loadAssets(); createScene(); - //TODO push menu on load cacheState(States::ScratchPad::PseutheGame); cacheState(States::ScratchPad::PseutheMenu); }); + + //TODO push menu on load + requestStackPush(States::ScratchPad::PseutheGame); } //public diff --git a/samples/scratchpad/src/pseuthe/PseutheConsts.hpp b/samples/scratchpad/src/pseuthe/PseutheConsts.hpp index aa2af425e..d43ff6468 100644 --- a/samples/scratchpad/src/pseuthe/PseutheConsts.hpp +++ b/samples/scratchpad/src/pseuthe/PseutheConsts.hpp @@ -3,6 +3,7 @@ #include #include #include +#include static inline constexpr glm::uvec2 SceneSize(1920u, 1080u); static inline constexpr glm::vec2 SceneSizeFloat(SceneSize); @@ -22,6 +23,9 @@ constexpr std::int32_t MinBallSize = 40; constexpr std::int32_t MaxBallSize = 92; constexpr float BallSize = 128.f; //this is the sprite size +//constexpr cro::Colour PlayerColour(std::uint8_t(200u), 200u, 230u, 180u); +constexpr cro::Colour PlayerColour(std::uint8_t(140u), 140u, 161u, 180u); + struct ShaderID final { enum diff --git a/samples/scratchpad/src/pseuthe/PseutheGameState.cpp b/samples/scratchpad/src/pseuthe/PseutheGameState.cpp index a6949cd94..cc8925e91 100644 --- a/samples/scratchpad/src/pseuthe/PseutheGameState.cpp +++ b/samples/scratchpad/src/pseuthe/PseutheGameState.cpp @@ -20,7 +20,9 @@ #include #include +#include #include +#include PseutheGameState::PseutheGameState(cro::StateStack& stack, cro::State::Context context) : cro::State (stack, context), @@ -100,7 +102,7 @@ void PseutheGameState::loadAssets() void PseutheGameState::createScene() { - + createPlayer(); auto& cam = m_gameScene.getActiveCamera().getComponent(); cam.resizeCallback = std::bind(cameraCallback, std::placeholders::_1); @@ -114,4 +116,89 @@ void PseutheGameState::createUI() auto& cam = m_uiScene.getActiveCamera().getComponent(); cam.resizeCallback = std::bind(cameraCallback, std::placeholders::_1); cameraCallback(cam); +} + +void PseutheGameState::createPlayer() +{ + cro::SpriteSheet spriteSheet; + + //head part + spriteSheet.loadFromFile("pseuthe/assets/sprites/head.spt", m_resources.textures); + + auto entity = m_gameScene.createEntity(); + entity.addComponent().setPosition(SceneSizeFloat / 2.f); + entity.addComponent(); + entity.addComponent() = spriteSheet.getSprite("head"); + entity.getComponent().setColour(PlayerColour); //TODO this could be part of the sprite sheet + entity.addComponent().play(0); + auto bounds = entity.getComponent().getTextureBounds(); + entity.getComponent().setOrigin({ bounds.width / 2.f, bounds.height / 2.f }); + auto headEnt = entity; + + + //mouth part + spriteSheet.loadFromFile("pseuthe/assets/sprites/mouth.spt", m_resources.textures); + + entity = m_gameScene.createEntity(); + entity.addComponent().setPosition({0.f, 0.f, -0.2f}); + entity.addComponent(); + entity.addComponent() = spriteSheet.getSprite("mouth"); + entity.getComponent().setColour(PlayerColour); + entity.addComponent();// .play(0); + headEnt.getComponent().addChild(entity.getComponent()); + + //antennae root + entity = m_gameScene.createEntity(); + entity.addComponent().setPosition({ bounds.width / 2.f, bounds.height / 2.f, 0.1f }); + headEnt.getComponent().addChild(entity.getComponent()); + auto rootEnt = entity; + + + constexpr float WigglerOffset = 24.f; + + struct WigglerCallback final + { + const float Rotation = 35.f * cro::Util::Const::degToRad; + float direction = 1.f; + cro::Entity head; + + WigglerCallback(float d, cro::Entity h) + : direction(d), head(h) {} + + void operator()(cro::Entity e, float dt) + { + const auto rot = head.getComponent().getRotation2D(); + const auto amt = cro::Util::Maths::shortestRotation(e.getComponent().getRotation2D(), rot + (Rotation * direction)); + e.getComponent().rotate(amt * dt); + } + }; + + //left wiggler + spriteSheet.loadFromFile("pseuthe/assets/sprites/wiggler.spt", m_resources.textures); + entity = m_gameScene.createEntity(); + entity.addComponent(); + entity.addComponent(); + entity.addComponent() = spriteSheet.getSprite("wiggler"); + entity.getComponent().setColour(PlayerColour); + entity.addComponent().play(0); + bounds = entity.getComponent().getTextureBounds(); + entity.getComponent().setOrigin({ bounds.width + WigglerOffset, bounds.height / 2.f }); + entity.addComponent().active = true; + entity.getComponent().function = WigglerCallback(1.f, headEnt); + rootEnt.getComponent().addChild(entity.getComponent()); + + //right wiggler + entity = m_gameScene.createEntity(); + entity.addComponent(); + entity.addComponent(); + entity.addComponent() = spriteSheet.getSprite("wiggler"); + entity.getComponent().setColour(PlayerColour); + entity.addComponent().play(0); + bounds = entity.getComponent().getTextureBounds(); + entity.getComponent().setOrigin({ bounds.width + WigglerOffset, bounds.height / 2.f }); + entity.addComponent().active = true; + entity.getComponent().function = WigglerCallback(-1.f, headEnt); + rootEnt.getComponent().addChild(entity.getComponent()); + + //TODO implement the 'tail' part } \ No newline at end of file diff --git a/samples/scratchpad/src/pseuthe/PseutheGameState.hpp b/samples/scratchpad/src/pseuthe/PseutheGameState.hpp index 40584d4f3..81fd7bbca 100644 --- a/samples/scratchpad/src/pseuthe/PseutheGameState.hpp +++ b/samples/scratchpad/src/pseuthe/PseutheGameState.hpp @@ -31,4 +31,7 @@ class PseutheGameState final : public cro::State, public cro::GuiClient void loadAssets(); void createScene(); void createUI(); + + void createPlayer(); + void addBodyPart(cro::Entity); }; \ No newline at end of file diff --git a/samples/scratchpad/src/pseuthe/PseutheShaders.inl b/samples/scratchpad/src/pseuthe/PseutheShaders.inl index 65a0b7a85..d0cabc7d0 100644 --- a/samples/scratchpad/src/pseuthe/PseutheShaders.inl +++ b/samples/scratchpad/src/pseuthe/PseutheShaders.inl @@ -132,9 +132,13 @@ void main() //outer circle vec3 ringColour = v_colour.rgb * 0.5; ringColour *= u_ambientColour; - ringColour += (lightColour * lightIntensity) * v_colour.rgb * 0.5; + ringColour += (lightColour * lightIntensity) * v_colour.rgb; vec2 UVNorm = mod(v_texCoord, UVSize) / UVSize; float l = length(UVNorm - vec2(0.5)); - FRAG_OUT.rgb = mix(blendedColour, ringColour, smoothstep(0.47, 0.472, l) * (1.0 - smoothstep(0.498, 0.5, l))); + float circleInner = smoothstep(0.46, 0.482, l); + + blendedColour += vec3(v_colour.r * (100.0 / 255.0)) * (1.0 - circleInner); + FRAG_OUT.rgb = mix(blendedColour, ringColour, circleInner * (1.0 - smoothstep(0.498, 0.5, l))); + })"; \ No newline at end of file