Peoplemon  0.1.0
Peoplemon 3 game source documentation
NewGame.cpp
Go to the documentation of this file.
2 
3 #include <Core/Properties.hpp>
4 #include <Core/Resources.hpp>
6 
7 namespace game
8 {
9 namespace state
10 {
11 namespace
12 {
13 constexpr float RotateSpeed = 120.f;
14 constexpr float FadeTime = 1.6f;
15 constexpr float ProfMoveSpeedX = -550.f;
16 constexpr float ProfMoveSpeedY = 450.f;
17 constexpr float ProfRotateSpeed = -75.f;
18 } // namespace
19 
20 NewGame::Ptr NewGame::create(core::system::Systems& systems) { return Ptr(new NewGame(systems)); }
21 
22 NewGame::NewGame(core::system::Systems& systems)
23 : State(systems, bl::engine::StateMask::Menu)
24 , fadeout(nullptr) {}
25 
26 const char* NewGame::name() const { return "NewGame"; }
27 
28 void NewGame::activate(bl::engine::Engine& engine) {
29  if (!bgndTxtr) {
30  bgndTxtr = engine.renderer().texturePool().getOrLoadTexture(bl::util::FileUtil::joinPath(
31  core::Properties::MenuImagePath(), "NewGame/newGameBgnd.png"));
32  profTxtr = engine.renderer().texturePool().getOrLoadTexture(bl::util::FileUtil::joinPath(
33  core::Properties::MenuImagePath(), "NewGame/professor.png"));
34 
35  background.create(engine, bgndTxtr);
36  background.getTransform().setOrigin(bgndTxtr->size() * 0.5f);
37  background.getTransform().setPosition(core::Properties::WindowSize().x * 0.5f,
38  core::Properties::WindowSize().y * 0.5f);
39 
40  prof.create(engine, profTxtr);
41  prof.getTransform().setPosition(background.getTransform().getLocalPosition() -
42  profTxtr->size() * 0.5f);
43  prof.getTransform().setDepth(-1.f); // ensure rendered after background w/o parenting
44  }
45 
46  auto overlay = engine.renderer().getObserver().pushScene<bl::rc::Overlay>();
47  background.addToScene(overlay, bl::rc::UpdateSpeed::Dynamic);
48  prof.addToScene(overlay, bl::rc::UpdateSpeed::Dynamic);
49 
50  systems.hud().displayMessage("Hello there!");
51  systems.hud().displayMessage("I'm the professor in HomeTown. My name is Professor, but you can "
52  "just call me Professor Professor");
54  "Your mom told me she had a kid, but I wasn't really listening. What's your name?",
55  1,
56  24,
57  std::bind(&NewGame::nameSet, this, std::placeholders::_1));
58 }
59 
60 void NewGame::nameSet(const std::string& n) {
61  playerName = n;
62  systems.hud().displayMessage("Wow your parents must not care for you much");
64  "It's hard to tell with, uh... my bad vision, but are you a boy or a girl?",
65  {"Boy", "Girl"},
66  std::bind(&NewGame::genderSet, this, std::placeholders::_1));
67 }
68 
69 void NewGame::genderSet(const std::string& g) {
70  isBoy = g == "Boy";
71  systems.hud().displayMessage("........ Really?");
72  systems.hud().displayMessage("Right then. Well I have to go do important professor things. I'm "
73  "sure you'll figure the rest out",
74  std::bind(&NewGame::fadeOut, this));
75 }
76 
77 void NewGame::fadeOut() {
78  fadeout = systems.engine()
79  .renderer()
80  .getObserver()
81  .getRenderGraph()
82  .putTask<bl::rc::rgi::FadeEffectTask>(FadeTime);
83 }
84 
85 void NewGame::deactivate(bl::engine::Engine& engine) {
86  engine.renderer().getObserver().popScene();
87  fadeout = nullptr;
88 
89  if (!systems.world().switchMaps("Hometown/HometownYourHouseYourRoom.map", 5)) {
90  BL_LOG_ERROR << "Failed to load starting map";
91  systems.engine().flags().set(bl::engine::Flags::Terminate);
92  }
93  systems.clock().set({12, 0});
94  systems.player().newGame(playerName,
96 }
97 
98 void NewGame::update(bl::engine::Engine&, float dt, float) {
99  background.getTransform().rotate(RotateSpeed * dt);
100  if (fadeout) {
101  if (fadeout->complete()) { systems.engine().replaceState(MainGame::create(systems)); }
102 
103  if (prof.getTransform().getRotation() > -90.f) {
104  prof.getTransform().rotate(dt * ProfRotateSpeed);
105  }
106  prof.getTransform().move({dt * ProfMoveSpeedX, dt * ProfMoveSpeedY});
107  }
108 }
109 
110 } // namespace state
111 } // namespace game
Parent namespace for all functionality unique to the game.
static const std::string & MenuImagePath()
Definition: Properties.cpp:303
static sf::Vector2f WindowSize()
Definition: Properties.cpp:262
void set(const Time &time)
Sets the current time.
Definition: Clock.cpp:29
void displayMessage(const std::string &message, const Callback &cb=[](const std::string &) {})
Displays a message in the HUD textbox. Messages are queued in order that they arrive.
Definition: HUD.cpp:92
void promptUser(const std::string &prompt, const std::vector< std::string > &choices, const Callback &cb)
Asks the player a question through the HUD.
Definition: HUD.cpp:112
void getInputString(const std::string &prompt, unsigned int minLen, unsigned int maxLen, const Callback &cb)
Prompts the player to input a string using the screen keyboard.
Definition: HUD.cpp:118
void newGame(const std::string &name, player::Gender gender)
Initializes all player data structures for a new game.
Definition: Player.cpp:59
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Definition: Systems.cpp:35
Player & player()
Returns the player system.
Definition: Systems.cpp:59
Clock & clock()
Accessor for the in game clock.
Definition: Systems.cpp:39
HUD & hud()
Returns the HUD.
Definition: Systems.cpp:69
World & world()
Modifiable accessor for the world system.
Definition: Systems.cpp:43
bool switchMaps(const std::string &newMap, int spawnId)
Switches the current map to the map in the given file.
Definition: World.cpp:26
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates the main game state. The game state must be initialized before invoking the main game state.
Definition: MainGame.cpp:35
This state does the game intro, gets the player's name and gender, and triggers the main game state i...
Definition: NewGame.hpp:18
virtual void activate(bl::engine::Engine &engine) override
Activates the state.
Definition: NewGame.cpp:28
virtual const char * name() const override
Returns "NewGame".
Definition: NewGame.cpp:26
virtual void deactivate(bl::engine::Engine &engine) override
Deactivates the state.
Definition: NewGame.cpp:85
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates the new game state.
Definition: NewGame.cpp:20
virtual void update(bl::engine::Engine &engine, float dt, float) override
Updates the state and menus and whatnot.
Definition: NewGame.cpp:98
Parent to all game states. Provides some commonly required data like core game systems.
Definition: State.hpp:29
core::system::Systems & systems
Definition: State.hpp:66