SFMechSimulator/src/tutorial.cpp

166 lines
7.9 KiB
C++

#include <tutorial.h>
// Constructor
tutorial::tutorial(std::string cwd)
{
step = 0;
visible = false;
if (!gui_background_texture.loadFromFile(cwd + "/assets/textures/gui_background.png"))
{
std::cout << "Failed to load textures.";
}
gui_background_sprite.setTexture(gui_background_texture);
if (!tutorial_font.loadFromFile(cwd + "/assets/Exoplanetaria-gxxJ5.ttf"))
{
std::cout << "Failed to load font.";
}
}
// Draws tutorial messages
void tutorial::draw_tutorial(sf::RenderWindow &window, bool show_keys, float speed, float torso_angle, float heat)
{
if (step == 0)
{
sf::String text = std::string("Key bindings can be changed by modifying the bindings.list file.\n") +
std::string("Press 'show_keys' (F2) now to view all of your current key bindings.\n") +
std::string("Press 'show_keys' (F2) again to stop displaying key bindings.");
tutorial_text.setString(text);
if (show_keys == true)
{
step = 1;
}
}
else if (step == 1)
{
sf::String text = std::string("Your mech's torso and legs are controlled separately.\n") +
std::string("Press the 'look left' or 'look right' key now to rotate\n") +
std::string("your mech's torso 90 degrees to the left or right.");
tutorial_text.setString(text);
if (torso_angle >= 80 || torso_angle <= -80)
{
step = 2;
}
}
else if (step == 2)
{
sf::String text = std::string("Press the 'map' key to increase the size of the mini-map / radar display.\n") +
std::string("The map key cycles between map sizes and toggles display of the map.\n") +
std::string("The white circle represents your mech's position in the world.\n") +
std::string("The green line represents the direction your mech's legs are facing.\n") +
std::string("The red line represents the direction your mech's torso is facing.\n\n") +
std::string("Press enter to continue.");
tutorial_text.setString(text);
}
else if (step == 3)
{
sf::String text = std::string("Rotate your mech's torso back to zero degrees.\n") +
std::string("This means the mech's legs and torso are facing the same direction.");
tutorial_text.setString(text);
if (torso_angle >= -3 && torso_angle <= 3)
{
step = 4;
}
}
else if (step == 4)
{
sf::String text = std::string("Increase your mech's throttle by pressing and holding the 'throttle_up' key.\n") +
std::string("Try increasing the throttle to 25% now.");
tutorial_text.setString(text);
int throttle = floor((speed) / 0.125 * 100);
if (throttle >= 25)
{
step = 5;
}
}
else if (step == 5)
{
sf::String text = std::string("Decrease your mech's throttle by pressing and holding the 'throttle_down' key.\n") +
std::string("Try decreasing the throttle to 3% now.");
tutorial_text.setString(text);
int throttle = floor((speed) / 0.125 * 100);
if (throttle <= 3)
{
step = 6;
}
}
else if (step == 6)
{
sf::String text = std::string("Firing your weapons increases the amount of heat generated by your mech.\n") +
std::string("Generating too much heat will cause damage to the mech's reactor.\n") +
std::string("Autocannons are a long range weapon with a low rate of fire.\n") +
std::string("Pulse lasers are a short range weapon with a higher rate of fire.\n") +
std::string("Autocannons do more damage in a single shot compared to pulse lasers.\n") +
std::string("Fire your weapons now by pressing the 'fire_guns' or 'fire_cannons' key.\n") +
std::string("Pay close attention to the heat readout and meter on your HUD.");
tutorial_text.setString(text);
if (heat > 0)
{
step = 7;
}
}
else if (step == 7)
{
sf::String text = std::string("If your mech's cooler is damaged, your mech will be more likely to overheat.\n") +
std::string("If your mech's arms are damaged, your weapons could be disabled.\n") +
std::string("If your mech's legs are damaged, you may become unable to move.\n") +
std::string("If your mech's cockpit is damaged, torso movement may be disabled.\n") +
std::string("If your mech's reactor is destroyed, the mech becomes inoperable.\n") +
std::string("If total combined damage exceeds 50%, the mech also becomes inoperable.\n\n") +
std::string("Press enter to continue.");
tutorial_text.setString(text);
}
else if (step == 8)
{
sf::String text = std::string("When encountering an enemy mech, press the 'lock_target' key\n") +
std::string("or fire weapons at the mech to activate a target lock.\n") +
std::string("Press the 'select component' key to change which component you are targeting.\n") +
std::string("Damage dealt by either mech is affected by speed and distance.\n") +
std::string("Some components are more resistant to damage such as the cooler and reactor.\n\n") +
std::string("Press enter to continue.");
tutorial_text.setString(text);
}
else if (step == 9)
{
sf::String text = std::string("The objective in each mission is to eliminate all enemy mechs.\n") +
std::string("Enemy mechs increase in number and difficulty as you progress.\n") +
std::string("You will notice enemies have increased armor or firepower in later missions.\n\n") +
std::string("Press enter to continue.");
tutorial_text.setString(text);
}
else if (step == 10)
{
sf::String text = std::string("After each mission, you will have the opportunity to upgrade your mech.\n") +
std::string("More powerful weapons increase heat. An upgraded cooler can help with this.\n") +
std::string("Your mech's chassis can only handle 110 tons of equipment.\n") +
std::string("You will need to keep this in mind when deciding which upgrades to install.\n") +
std::string("Upgrades can be sold for a portion of the original purchase price.\n\n") +
std::string("Press enter to restart the tutorial.\n") +
std::string("Press the 'show tutorial' key to hide these messages.");
tutorial_text.setString(text);
}
sf::Vector2f bg_pos;
bg_pos.x = (window.getView().getSize().x / 2) - (tutorial_text.getGlobalBounds().width / 2) - 25;
bg_pos.y = (window.getView().getSize().y / 2) - 170;
gui_background_sprite.setPosition(bg_pos);
gui_background_sprite.setScale(tutorial_text.getGlobalBounds().width * 0.00075, tutorial_text.getGlobalBounds().height * 0.006);
window.draw(gui_background_sprite);
tutorial_text.setFont(tutorial_font);
tutorial_text.setCharacterSize(18);
tutorial_text.setFillColor(sf::Color::White);
sf::Vector2f text_pos;
text_pos.x = (window.getView().getSize().x / 2) - (tutorial_text.getGlobalBounds().width / 2);
text_pos.y = (window.getView().getSize().y / 2) - 150;
tutorial_text.setPosition(text_pos);
window.draw(tutorial_text);
}