Skip to content

Commit

Permalink
disable input parser when taking a mulligan
Browse files Browse the repository at this point in the history
draw player head
  • Loading branch information
fallahn committed Aug 23, 2024
1 parent 74935e1 commit ebdf2c3
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 4 deletions.
2 changes: 2 additions & 0 deletions samples/golf/src/golf/GolfState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,8 @@ void GolfState::handleMessage(const cro::Message& msg)
e.getComponent<cro::Callback>().active = false;
};
m_gameScene.getSystem<cro::CommandSystem>()->sendCommand(cmd);

m_inputParser.setActive(false, m_currentPlayer.terrain);
}
break;
case GolfEvent::NiceTiming:
Expand Down
4 changes: 3 additions & 1 deletion samples/scratchpad/src/pseuthe/PseutheBackgroundState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions samples/scratchpad/src/pseuthe/PseutheConsts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <crogine/core/App.hpp>
#include <crogine/ecs/components/Camera.hpp>
#include <crogine/detail/glm/vec2.hpp>
#include <crogine/graphics/Colour.hpp>

static inline constexpr glm::uvec2 SceneSize(1920u, 1080u);
static inline constexpr glm::vec2 SceneSizeFloat(SceneSize);
Expand All @@ -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
Expand Down
89 changes: 88 additions & 1 deletion samples/scratchpad/src/pseuthe/PseutheGameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <crogine/ecs/systems/SpriteAnimator.hpp>
#include <crogine/ecs/systems/RenderSystem2D.hpp>

#include <crogine/graphics/SpriteSheet.hpp>
#include <crogine/util/Constants.hpp>
#include <crogine/util/Maths.hpp>

PseutheGameState::PseutheGameState(cro::StateStack& stack, cro::State::Context context)
: cro::State (stack, context),
Expand Down Expand Up @@ -100,7 +102,7 @@ void PseutheGameState::loadAssets()

void PseutheGameState::createScene()
{

createPlayer();

auto& cam = m_gameScene.getActiveCamera().getComponent<cro::Camera>();
cam.resizeCallback = std::bind(cameraCallback, std::placeholders::_1);
Expand All @@ -114,4 +116,89 @@ void PseutheGameState::createUI()
auto& cam = m_uiScene.getActiveCamera().getComponent<cro::Camera>();
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<cro::Transform>().setPosition(SceneSizeFloat / 2.f);
entity.addComponent<cro::Drawable2D>();
entity.addComponent<cro::Sprite>() = spriteSheet.getSprite("head");
entity.getComponent<cro::Sprite>().setColour(PlayerColour); //TODO this could be part of the sprite sheet
entity.addComponent<cro::SpriteAnimation>().play(0);
auto bounds = entity.getComponent<cro::Sprite>().getTextureBounds();
entity.getComponent<cro::Transform>().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<cro::Transform>().setPosition({0.f, 0.f, -0.2f});
entity.addComponent<cro::Drawable2D>();
entity.addComponent<cro::Sprite>() = spriteSheet.getSprite("mouth");
entity.getComponent<cro::Sprite>().setColour(PlayerColour);
entity.addComponent<cro::SpriteAnimation>();// .play(0);
headEnt.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());

//antennae root
entity = m_gameScene.createEntity();
entity.addComponent<cro::Transform>().setPosition({ bounds.width / 2.f, bounds.height / 2.f, 0.1f });
headEnt.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());
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<cro::Transform>().getRotation2D();
const auto amt = cro::Util::Maths::shortestRotation(e.getComponent<cro::Transform>().getRotation2D(), rot + (Rotation * direction));
e.getComponent<cro::Transform>().rotate(amt * dt);
}
};

//left wiggler
spriteSheet.loadFromFile("pseuthe/assets/sprites/wiggler.spt", m_resources.textures);
entity = m_gameScene.createEntity();
entity.addComponent<cro::Transform>();
entity.addComponent<cro::Drawable2D>();
entity.addComponent<cro::Sprite>() = spriteSheet.getSprite("wiggler");
entity.getComponent<cro::Sprite>().setColour(PlayerColour);
entity.addComponent<cro::SpriteAnimation>().play(0);
bounds = entity.getComponent<cro::Sprite>().getTextureBounds();
entity.getComponent<cro::Transform>().setOrigin({ bounds.width + WigglerOffset, bounds.height / 2.f });
entity.addComponent<cro::Callback>().active = true;
entity.getComponent<cro::Callback>().function = WigglerCallback(1.f, headEnt);
rootEnt.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());

//right wiggler
entity = m_gameScene.createEntity();
entity.addComponent<cro::Transform>();
entity.addComponent<cro::Drawable2D>();
entity.addComponent<cro::Sprite>() = spriteSheet.getSprite("wiggler");
entity.getComponent<cro::Sprite>().setColour(PlayerColour);
entity.addComponent<cro::SpriteAnimation>().play(0);
bounds = entity.getComponent<cro::Sprite>().getTextureBounds();
entity.getComponent<cro::Transform>().setOrigin({ bounds.width + WigglerOffset, bounds.height / 2.f });
entity.addComponent<cro::Callback>().active = true;
entity.getComponent<cro::Callback>().function = WigglerCallback(-1.f, headEnt);
rootEnt.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());

//TODO implement the 'tail' part
}
3 changes: 3 additions & 0 deletions samples/scratchpad/src/pseuthe/PseutheGameState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
8 changes: 6 additions & 2 deletions samples/scratchpad/src/pseuthe/PseutheShaders.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
})";

0 comments on commit ebdf2c3

Please sign in to comment.