here is the code currently:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int direction =0;
class Missile
{
public :
static bool Init(const std::string& ImageFile)
{
return Image.LoadFromFile(ImageFile);
}
Missile()
{
Sprite.SetImage(Image); // every sprite uses the same unique image
}
private :
static sf::Image Image; // shared by every instance
sf::Sprite Sprite; // one per instance
};
sf::Image Missile::Image;
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
App.SetBackgroundColor(sf::Color(255, 255, 255));
// Load the sprite image from a file
sf::Image Image;
if (!Image.LoadFromFile("megaman.png"))
return EXIT_FAILURE;
// sf::Image bullet;
// if (!Image.LoadFromFile("megaman.png"))
// return EXIT_FAILURE;
// Create the sprite
sf::Sprite Sprite(Image);
// Change its properties
Sprite.SetColor(sf::Color(0, 255, 255, 200));
Sprite.SetPosition(500.f, 500.f);
Sprite.SetScale(2.f, 2.f);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Get elapsed time
float ElapsedTime = App.GetFrameTime();
// Move the sprite
if (App.GetInput().IsKeyDown(sf::Key::Left)) {Sprite.Move(-100 * ElapsedTime, 0);
if (direction == 1){
direction =0; Sprite.FlipX(0);
}}
if (App.GetInput().IsKeyDown(sf::Key::Right)) {Sprite.Move( 100 * ElapsedTime, 0);
if (direction == 0){
direction =1; Sprite.FlipX(1);
}}
if (App.GetInput().IsKeyDown(sf::Key::Up)) Sprite.Move(0, -100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down)) Sprite.Move(0, 100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::V))
if(!Missile::Init("megaman.png")){
exit(EXIT_FAILURE);
Missile m;}
}
// Rotate the sprite
if (App.GetInput().IsKeyDown(sf::Key::Z)) Sprite.Rotate(- 100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);
// Display sprite in our window
App.Draw(Sprite);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
(NOTE: 1 or more comments may be wrong)
Here is what I get if I run g++ main.cpp -o main -lsfml-window -lsfml-graphics: main.cpp: In function ‘int main()’:
main.cpp:95: error: ‘ElapsedTime’ was not declared in this scope
main.cpp:96: error: ‘ElapsedTime’ was not declared in this scope
main.cpp: At global scope:
main.cpp:106: error: expected unqualified-id before ‘return’
main.cpp:107: error: expected declaration before ‘}’ token
Like I said, I'm not real good with C++