Below is a C++ program I wrote for Windows as a proof of concept. I wanted to see if I could render text and images in C++ and be able to control them. Calling the program a game is a large
over-statment. All it actually does is display a few images on the screen, one of which moves along with the mouse, though I like to pretend the little guy that follows the mouse is fixing the robot arm.
This is the image that is static:
I chose a FANUC industrial robot because I was still earning my Associates of Applied Sciences in Robotic Technologies and I was having fun learning about
them.
This is the picture of the little guy that I have following the cursor:
//Mechanicus Run "Game"
#include
#include
#include
#include
#include
//Making the name of the game.
std::string nameOfTheGame = "Mechanicus Run!";
using namespace sf; //THIS IS NEEDED!
//MechanicusBoi.png is 300 X 533.
int main()
{
std::cout << "\n\n\n\n][-----LogOfPotentialErrors-----][\n\n\n\n";
bool broken = false;
//Grabbing a textures
Texture mechanicusBoyTexture;
Texture robotToFixTexture;
//Load it from a file
if (!mechanicusBoyTexture.loadFromFile("MechanicusBoi.png"))
{
std::cout << "\nOh dang! Oh crap! You need to lauch with the launcher or let N8 know if your tried that and still the texture for the \nMechanicus Adept doesn't work!\n";
broken = true;
}
else
{
std::cout << "\nThe Machine Spirits favor the Adept.\n";
}
if (!robotToFixTexture.loadFromFile("robotToFix.png"))
{
std::cout << "\nOh dang! Oh crap! You need to lauch with the launcher or let N8 know if your tried that and still the texture for the \nrobot sprite doesn't work!\n";
broken = true;
}
else
{
std::cout << "\nThe Machine Spirits favor the robot that needs repair.\n";
}
//Grabbing a font
Font font;
// Load it from a file
if (!font.loadFromFile("chintzy.ttf"))
{
std::cout << "\nOh dang! Oh crap! You need to lauch with the launcher or let N8 know if your tried that and still the font doesn't work!\n";
broken = true;
}
else
{
std::cout << "\nThe Machine Spirits favor this most sacred font.\n";
}
if (broken)
{
std::cout << "\nThe Machine Spirits are most displeased! They implore you to only start the program with \n TheOmnissiah'sHolyLauncher.bat.";
std::cout << "\nIf you have already made sure of this you need to contact N8. He can rectify your problems.\n\n\n";
exit(1);
}
Sprite techBoi;
techBoi.setTexture(mechanicusBoyTexture);
Sprite robotThatNeedsFixing;
robotThatNeedsFixing.setTexture(robotToFixTexture);
robotThatNeedsFixing.setOrigin(-1350, -500);
//Make Window
RenderWindow window(VideoMode(1920, 1080), nameOfTheGame, Style::None);
window.setMouseCursorVisible(false);
//Make Text
Text message("Press Backspace to get out of here... \n\nFix the machine...\n\nPraise the Omnissiah...", font);
message.setOutlineColor(Color::Black);
message.setOutlineThickness(5);
message.setFillColor(Color::Green);
message.setPosition(0, 0);
window.isOpen();
while (window.isOpen())
{
Event event;
Keyboard backspaceOnOuttaThere;
while (window.pollEvent(event))
{
if (event.type == Event::Closed || backspaceOnOuttaThere.isKeyPressed(Keyboard::Key::Backspace))
{
//std::this_thread::sleep_for(std::chrono::seconds(1));
window.clear();
//Waits a second...
//std::this_thread::sleep_for(std::chrono::seconds(1));
window.close();
}
}
//MechanicusBoi.png is 300 X 533.
window.draw(message);
int mouseX = sf::Mouse::getPosition(window).x;
int mouseY = sf::Mouse::getPosition(window).y;
techBoi.setOrigin(-mouseX, -mouseY);
window.draw(robotThatNeedsFixing);
window.draw(techBoi);
window.display();
window.clear();
}
return 0;
}