Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Coondog

Pages: [1]
1
General discussions / How do you use the Missile class?
« on: July 11, 2008, 12:03:35 am »
I should be able to use App.Draw now, right?
also what does Missile m; do ?

2
General discussions / How do you use the Missile class?
« on: July 10, 2008, 11:57:13 pm »
Thanks, it works  :)

3
General discussions / How do you use the Missile class?
« on: July 10, 2008, 11:43:44 pm »
here is the code currently:
Code: [Select]

////////////////////////////////////////////////////////////
// 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++

4
General discussions / How do you use the Missile class?
« on: July 10, 2008, 11:20:11 pm »
hmm, I tried your code, but....
/tmp/ccksi0yc.o: In function `Missile::Init(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
main.cpp:(.text._ZN7Missile4InitERKSs[Missile::Init(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x10): undefined reference to `Missile::Image'
/tmp/ccksi0yc.o: In function `Missile::Missile()':
main.cpp:(.text._ZN7MissileC1Ev[Missile::Missile()]+0x19): undefined reference to `Missile::Image'
collect2: ld returned 1 exit status

5
General discussions / How do you use the Missile class?
« on: July 10, 2008, 10:34:07 pm »
I'm not real good with C++, how do you use the Missile Class?
Code: [Select]
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
};

would I just use something like Missile("imagefile.png"); ?

I'd like to get bullet firing going with taking the x and y(probably modifying the x and y a bit later) of the character and then creating a bullet(sprite?) with that data

Pages: [1]