Skip to content

Commit

Permalink
tweak rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Oct 26, 2024
1 parent cdb403e commit 91fbe6c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
10 changes: 7 additions & 3 deletions samples/golf/src/scrub/ScrubAttractState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool ScrubAttractState::simulate(float dt)
tabScrollTime += dt;
if (tabScrollTime > TabDisplayTime)
{
tabScrollTime -= TabDisplayTime;
//tabScrollTime -= TabDisplayTime;
nextTab();
}

Expand Down Expand Up @@ -478,7 +478,7 @@ Press ESCAPE to Pause the game.
entity = m_uiScene.createEntity();
entity.addComponent<cro::Transform>().setPosition(glm::vec3(size / 2.f, sc::TextDepth));
entity.addComponent<cro::Drawable2D>();
entity.addComponent<cro::Text>(smallFont).setCharacterSize(sc::MediumTextSize * getViewScale());
entity.addComponent<cro::Text>(smallFont).setCharacterSize(sc::MediumTextSize/* * getViewScale()*/);
entity.getComponent<cro::Text>().setAlignment(cro::Text::Alignment::Centre);
entity.getComponent<cro::Text>().setFillColour(TextNormalColour);
entity.getComponent<cro::Text>().setShadowColour(LeaderboardTextDark);
Expand All @@ -487,7 +487,7 @@ Press ESCAPE to Pause the game.
bounds = cro::Text::getLocalBounds(entity);
entity.addComponent<cro::CommandTarget>().ID = CommandID::UI::UIElement;
entity.addComponent<UIElement>().relativePosition = glm::vec2(0.5f);
entity.getComponent<UIElement>().absolutePosition = { 0.f, std::floor(bounds.height / 2.f) + 40.f };
entity.getComponent<UIElement>().absolutePosition = { 0.f, std::floor(bounds.height / 2.f) + 40.f }; //hm this doesn't account for the fact that the bounds will be bigger with a bigger text size. We need to constify this
entity.getComponent<UIElement>().characterSize = sc::MediumTextSize;
entity.getComponent<UIElement>().depth = sc::TextDepth;

Expand Down Expand Up @@ -694,13 +694,17 @@ void ScrubAttractState::prevTab()
m_tabs[m_currentTab].getComponent<cro::Callback>().getUserData<TabData>().hide(m_tabs[m_currentTab]);
m_currentTab = (m_currentTab + (m_tabs.size() - 1)) % m_tabs.size();
m_tabs[m_currentTab].getComponent<cro::Callback>().getUserData<TabData>().show(m_tabs[m_currentTab]);

tabScrollTime = std::max(0.f, tabScrollTime - TabDisplayTime);
}

void ScrubAttractState::nextTab()
{
m_tabs[m_currentTab].getComponent<cro::Callback>().getUserData<TabData>().hide(m_tabs[m_currentTab]);
m_currentTab = (m_currentTab + 1) % m_tabs.size();
m_tabs[m_currentTab].getComponent<cro::Callback>().getUserData<TabData>().show(m_tabs[m_currentTab]);

tabScrollTime = std::max(0.f, tabScrollTime - TabDisplayTime);
}

void ScrubAttractState::onCachedPush()
Expand Down
47 changes: 25 additions & 22 deletions samples/golf/src/scrub/ScrubGameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool ScrubGameState::handleEvent(const cro::Event& evt)
{
if (m_score.gameRunning)
{
m_ball.scrub(m_handle.switchDirection(Handle::Down));
m_ball.scrub(m_handle.switchDirection(Handle::Down, m_score.ballsWashed));
m_soundDirector->playSound(AudioID::FXScrubDown, MixerChannel::Effects, 0.4f).getComponent<cro::AudioEmitter>().setPitch(cro::Util::Random::value(0.85f, 1.2f));
}
};
Expand All @@ -142,7 +142,7 @@ bool ScrubGameState::handleEvent(const cro::Event& evt)
{
if (m_score.gameRunning)
{
m_ball.scrub(m_handle.switchDirection(Handle::Up));
m_ball.scrub(m_handle.switchDirection(Handle::Up, m_score.ballsWashed));
m_soundDirector->playSound(AudioID::FXScrubUp, MixerChannel::Effects, 0.4f).getComponent<cro::AudioEmitter>().setPitch(cro::Util::Random::value(0.85f, 1.2f));
}
};
Expand Down Expand Up @@ -359,8 +359,8 @@ bool ScrubGameState::simulate(float dt)


m_score.totalRunTime += dt;
#ifndef CRO_DEBUG_
m_score.remainingTime = std::max(m_score.remainingTime - dt, 0.f);
#ifndef CRO_DEBUG_
#endif
m_score.quitTimeout = 0.f;
if (m_score.remainingTime == 0)
Expand Down Expand Up @@ -903,7 +903,7 @@ void ScrubGameState::createUI()
entity.getComponent<cro::Text>().setShadowOffset(sc::MediumTextOffset);
entity.addComponent<cro::CommandTarget>().ID = CommandID::UI::UIElement;
entity.addComponent<UIElement>().relativePosition = glm::vec2(0.5f, 1.f);
entity.getComponent<UIElement>().absolutePosition = { 0.f, -16.f };
entity.getComponent<UIElement>().absolutePosition = { 0.f, -14.f };
entity.getComponent<UIElement>().characterSize = sc::MediumTextSize;
entity.getComponent<UIElement>().depth = sc::TextDepth;
entity.addComponent<cro::Callback>().active = true;
Expand All @@ -925,7 +925,7 @@ void ScrubGameState::createUI()
entity.getComponent<cro::Text>().setShadowOffset(sc::MediumTextOffset);
entity.addComponent<cro::CommandTarget>().ID = CommandID::UI::UIElement;
entity.addComponent<UIElement>().relativePosition = glm::vec2(1.f, 1.f);
entity.getComponent<UIElement>().absolutePosition = { -212.f, -12.f };
entity.getComponent<UIElement>().absolutePosition = { -212.f, -14.f };
entity.getComponent<UIElement>().characterSize = sc::MediumTextSize;
entity.getComponent<UIElement>().depth = sc::TextDepth;
entity.addComponent<cro::Callback>().active = true;
Expand All @@ -937,8 +937,8 @@ void ScrubGameState::createUI()
e.getComponent<cro::Text>().setString(ss.str());
};

static constexpr float BarHeight = 800.f;
static constexpr float BarWidth = 180.f;
static constexpr float BarHeight = 400.f;
static constexpr float BarWidth = 80.f;

//streak count
entity = m_uiScene.createEntity();
Expand Down Expand Up @@ -1001,7 +1001,7 @@ void ScrubGameState::createUI()
[](cro::Entity e, float dt)
{
const auto Speed = 250.f * dt;
static constexpr float MaxOffset = -30.f;
static constexpr float MaxOffset = 30.f;

auto o = e.getComponent<cro::Transform>().getOrigin();
o.y = std::min(MaxOffset, o.y + Speed);
Expand All @@ -1017,22 +1017,25 @@ void ScrubGameState::createUI()


//100% streak
static constexpr float ProgBarHeight = 180.f;
static constexpr float ProgBarWidth = 800.f;

entity = m_uiScene.createEntity();
entity.addComponent<cro::Transform>();
entity.addComponent<cro::Drawable2D>().setVertexData(
{
cro::Vertex2D(glm::vec2(0.f, BarWidth), glm::vec2(0.f, 2.f), cro::Colour::White),
cro::Vertex2D(glm::vec2(0.f, ProgBarHeight), glm::vec2(0.f, 2.f), cro::Colour::White),
cro::Vertex2D(glm::vec2(0.f), glm::vec2(0.f, 0.2f), cro::Colour::White),
cro::Vertex2D(glm::vec2(BarHeight, BarWidth), glm::vec2(1.f, 2.f), cro::Colour::White),
cro::Vertex2D(glm::vec2(BarHeight, 0.f), glm::vec2(1.f, 0.2f), cro::Colour::White)
cro::Vertex2D(glm::vec2(ProgBarWidth, ProgBarHeight), glm::vec2(1.f, 2.f), cro::Colour::White),
cro::Vertex2D(glm::vec2(ProgBarWidth, 0.f), glm::vec2(1.f, 0.2f), cro::Colour::White)
});
m_resources.textures.setFallbackColour(cro::Colour::White);
entity.getComponent<cro::Drawable2D>().setTexture(&m_resources.textures.get("fallback"));
entity.getComponent<cro::Drawable2D>().setShader(&m_resources.shaders.get(sc::ShaderID::Fire));
entity.getComponent<cro::Drawable2D>().setBlendMode(cro::Material::BlendMode::Additive);
entity.addComponent<cro::CommandTarget>().ID = CommandID::UI::UIElement;
entity.addComponent<UIElement>().relativePosition = glm::vec2(0.5f, 1.f);
entity.getComponent<UIElement>().absolutePosition = { -BarHeight / 2.f, -((BarWidth / 2.f) + 52.f) };
entity.getComponent<UIElement>().absolutePosition = { -ProgBarWidth / 2.f, -((ProgBarHeight / 2.f) + 52.f) };
entity.addComponent<cro::Callback>().active = true;
entity.getComponent<cro::Callback>().setUserData<float>(0.f);
entity.getComponent<cro::Callback>().function =
Expand All @@ -1041,7 +1044,7 @@ void ScrubGameState::createUI()
auto& progress = e.getComponent<cro::Callback>().getUserData<float>();
const float target = static_cast<float>(std::min(10, m_score.bonusRun)) / 10.f;

const float Speed = dt * 2.f;
const float Speed = dt / 2.f;
if (progress < target)
{
progress = std::min(target, progress + Speed);
Expand All @@ -1051,7 +1054,7 @@ void ScrubGameState::createUI()
progress = std::max(target, progress - Speed);
}

cro::FloatRect cropping = { 0.f, 0.f, BarHeight * progress, BarWidth };
cro::FloatRect cropping = { 0.f, 0.f, ProgBarWidth * progress, ProgBarHeight };
e.getComponent<cro::Drawable2D>().setCroppingArea(cropping);

static float t = 0.f;
Expand Down Expand Up @@ -1290,7 +1293,7 @@ void ScrubGameState::handleCallback(cro::Entity e, float dt)
{
if (m_handle.speed != 0)
{
m_ball.scrub(m_handle.calcStroke());
m_ball.scrub(m_handle.calcStroke(m_score.ballsWashed));
}
m_handle.speed = 0.f;
}
Expand Down Expand Up @@ -1532,7 +1535,7 @@ void ScrubGameState::updateScore()



if (((m_score.ballsWashed - m_score.countAtThreshold) % (m_score.bonusRun > Score::bonusRunThreshold ? 5 : 6)) == 0)
if (((m_score.ballsWashed - m_score.countAtThreshold) % (m_score.bonusRun > Score::bonusRunThreshold ? 4 : 5)) == 0)
{
//new soap in 3.. 2.. 1..
const auto& font = m_sharedScrubData.fonts->get(sc::FontID::Body);
Expand Down Expand Up @@ -1598,9 +1601,9 @@ void ScrubGameState::updateScore()
};

m_score.threshold = std::min(Ball::MaxFilth - 0.5f, m_score.threshold + 4.f);
m_score.remainingTime += 0.1f;
//m_score.remainingTime += 0.1f;

showMessage("+0.1s");
//showMessage("+0.1s");
m_soundDirector->playSound(AudioID::VONewSoap, MixerChannel::Voice);
}
}
Expand Down Expand Up @@ -1751,7 +1754,7 @@ void ScrubGameState::levelMeterCallback(cro::Entity e)
}

//handle funcs
float ScrubGameState::Handle::switchDirection(float d)
float ScrubGameState::Handle::switchDirection(float d, std::int32_t ballsWashed)
{
CRO_ASSERT(d == Down || d == Up, "");

Expand All @@ -1760,7 +1763,7 @@ float ScrubGameState::Handle::switchDirection(float d)
&& !locked)
{
//do this first as it uses the current direction
ret = calcStroke();
ret = calcStroke(ballsWashed);

direction = d;
speed = MaxSpeed;
Expand All @@ -1773,13 +1776,13 @@ float ScrubGameState::Handle::switchDirection(float d)
return ret;
}

float ScrubGameState::Handle::calcStroke()
float ScrubGameState::Handle::calcStroke(std::int32_t ballsWashed)
{
const float currPos = entity.getComponent<cro::Transform>().getPosition().y;
stroke = ((currPos - strokeStart) / StrokeDistance) * direction;
strokeStart = currPos;

const float difficulty = 0.85f; //TODO make this variable - lower the harder it is to clean
const float difficulty = std::max(0.6f, 1.f - (0.1f * (ballsWashed / 8))); //lower the harder it is to clean

if (hasBall)
{
Expand Down
8 changes: 4 additions & 4 deletions samples/golf/src/scrub/ScrubGameState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class ScrubGameState final : public cro::State, public cro::GuiClient
float strokeStart = 0.f;

//these both return the calc'd stroke
float switchDirection(float);
float calcStroke();
float switchDirection(float, std::int32_t ballsWashed);
float calcStroke(std::int32_t ballsWashed);

cro::Entity entity;

Expand All @@ -123,7 +123,7 @@ class ScrubGameState final : public cro::State, public cro::GuiClient
{
static constexpr float MaxSoap = 10.f;
static constexpr float MinSoap = 3.f;
static constexpr float Reduction = 0.6f;
static constexpr float Reduction = 0.65f;
float amount = MaxSoap;

//the older the soap is the more quickly it diminishes
Expand Down Expand Up @@ -212,7 +212,7 @@ class ScrubGameState final : public cro::State, public cro::GuiClient

//how many balls were 100% in a row
std::int32_t bonusRun = 0;
static constexpr std::int32_t bonusRunThreshold = 4; //after this we only need 3 balls to get more soap
static constexpr std::int32_t bonusRunThreshold = 8; //after this we only need 4 balls to get more soap
std::int32_t countAtThreshold = 0; //number of balls when threshold met to correct for count offset

float totalRunTime = 0.f;
Expand Down

0 comments on commit 91fbe6c

Please sign in to comment.