Skip to content

Commit

Permalink
Add state start with button
Browse files Browse the repository at this point in the history
  • Loading branch information
Laguna1989 committed Jul 11, 2024
1 parent d067f0e commit 37fc988
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions impl/game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include <log/logger.hpp>
#include <logging_camera.hpp>
#include <random/random.hpp>
#include <state_intro.hpp>
#include <state_manager/logging_state_manager.hpp>
#include <state_manager/state_manager.hpp>
#include <state_start_with_button.hpp>
#include <memory>

std::shared_ptr<jt::GameBase> game;
Expand Down Expand Up @@ -61,7 +61,7 @@ int main(int /*argc*/, char* /*argv*/[])

jt::AudioImpl audio {};

jt::StateManager stateManager { std::make_shared<StateIntro>() };
jt::StateManager stateManager { std::make_shared<StateStartWithButton>() };
jt::LoggingStateManager loggingStateManager { stateManager, logger };

jt::ActionCommandManager actionCommandManager(logger);
Expand Down
27 changes: 27 additions & 0 deletions impl/gamelib/state_start_with_button.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "state_start_with_button.hpp"
#include <drawable_helpers.hpp>
#include <game_interface.hpp>
#include <game_properties.hpp>
#include <state_intro.hpp>
#include <text.hpp>

void StateStartWithButton::onCreate()
{
auto const buttonSize = jt::Vector2u { 128, 48 };
m_button = std::make_shared<jt::Button>(buttonSize, textureManager());
m_button->addCallback(
[this]() { getGame()->stateManager().switchState(std::make_shared<StateIntro>()); });
auto text = jt::dh::createText(renderTarget(), "Start", 24);
text->setTextAlign(jt::Text::TextAlign::LEFT);
text->setOrigin({ -34, -6 });
m_button->setDrawable(text);
m_button->setPosition(
GP::GetScreenSize() * 0.5f - jt::Vector2f { buttonSize.x / 2.0f, buttonSize.y / 2.0f });
add(m_button);
}

void StateStartWithButton::onEnter() { }

void StateStartWithButton::onUpdate(float /*elapsed*/) { }

void StateStartWithButton::onDraw() const { }
17 changes: 17 additions & 0 deletions impl/gamelib/state_start_with_button.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef JAMTEMPLATE_STATE_START_WITH_BUTTON_HPP
#define JAMTEMPLATE_STATE_START_WITH_BUTTON_HPP

#include <button.hpp>
#include <game_state.hpp>
#include <memory>

class StateStartWithButton : public jt::GameState {
void onCreate() override;
void onEnter() override;
void onUpdate(float elapsed) override;
void onDraw() const override;

std::shared_ptr<jt::Button> m_button;
};

#endif // JAMTEMPLATE_STATE_START_WITH_BUTTON_HPP

0 comments on commit 37fc988

Please sign in to comment.