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 - nullGrind

Pages: 1 [2]
16
General / Loading sprites into a vector
« on: February 01, 2010, 03:38:15 pm »
OMG
i was really stupid. Here is the Problem:
Code: [Select]

Shot.SetImage(IRocketP1);

I used the image for my rocket but not the image for my shot.
After fixing that the code just goes fine.
Thanks anyway Laurent![/code]

17
General / Loading sprites into a vector
« on: February 01, 2010, 02:03:45 pm »
its
Code: [Select]
ShotVector.push_back(Shot);


also updated my original post with a marker marking line 166[/quote]

18
General / Loading sprites into a vector
« on: February 01, 2010, 01:48:30 pm »
Hello everyone!

Right now im programming on a little spaceshooter. Every time the player shoots a sprite should be generated from the same image. But my compiler keeps telling me that: main.cpp:166: error: expected primary-expression before "Shot"

Here is part of the code:
Code: [Select]

    sf::Image IShot;
    if (!IShot.LoadFromFile("Shot.png")) {
        // Error...
    }
std::vector<sf::Sprite> ShotVector;

Gameloop:
        // SHOOTING
       
        shotTimer++;
        if (Game.GetInput().IsKeyDown(sf::Key::N) && shotTimer > 60) {
            shotTimer = 0;
            shot = true;
        }
        if (shot) {
            shot = false;
            sf::Sprite Shot;
            Shot.SetImage(IRocketP1);
            Shot.SetColor(sf::Color(255, 255, 255, 255));
            Shot.SetPosition(350.f, 600.f);
            Shot.SetCenter(Shot.GetSize().x / 2, Shot.GetSize().y / 2);
            ShotVector.push_back(Shot);        <--- LINE 166
        }
        int i = 0;
        for (i = 0; i < ShotVector.size(); i++) {
            Game.Draw(ShotVector[i]);
        }

19
General / Radial Controls
« on: January 24, 2010, 12:20:55 pm »
Hello Guys

Right now im coding on a rocket game. The player is supposed to rotate the rocket and press space to accelerate in the chosen direction. Right now the rocket seems to randomly go into random directions. Does anybody know how i can control the rocket?

Here ist the code, interesting lines start at line 42.

The other problem is that the rocket does not fly in smooth curves but when i accelerate and at the same time rotate it starts to stutter and wont move.

Code: [Select]

#include <stdlib.h>
#include <iostream.h>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>


int main(int argc, char** argv) {
    sf::RenderWindow Game(sf::VideoMode(800, 600, 0), "Gravitation");
    sf::WindowSettings::WindowSettings(24, 8, 4);
    sf::Blend::Alpha;


    sf::Image IRocketP1;
    if (!IRocketP1.LoadFromFile("wrocket.png")) {
        // Error...
    }
    sf::Sprite rocketP1;
    rocketP1.SetImage(IRocketP1);
    rocketP1.SetColor(sf::Color(255, 255, 255, 255));
    rocketP1.SetX(0.f);
    rocketP1.SetY(0.f);
    rocketP1.SetPosition(350.f, 500.f);
    rocketP1.SetRotation(0.f);
    rocketP1.SetCenter(rocketP1.GetSize().x / 2 + 20, rocketP1.GetSize().y / 2 + 20);

    double speedR = 100;
    double widthR = rocketP1.GetSize().x;
    double heightR = rocketP1.GetSize().y;
    double speedRocket = 3;
    double direction = 0;
    double speedRotate = 2;
    int resX = 1280;
    int resY = 800;

    while (Game.IsOpened()) {
        Game.UseVerticalSync(true);

        // CONTROL
        float ElapsedTime = Game.GetFrameTime();
        if (Game.GetInput().IsKeyDown(sf::Key::Left) && rocketP1.GetPosition().x > 0)
            direction += speedRotate;
        if (Game.GetInput().IsKeyDown(sf::Key::Right) && rocketP1.GetPosition().x + widthR < resX)
            direction -= speedRotate;
        rocketP1.SetRotation(direction);
        if (Game.GetInput().IsKeyDown(sf::Key::Space)) {
            rocketP1.Move(speedRocket * sin(direction), speedRocket * cos(direction));
        }
        cout << direction;
       


        sf::Event Close;
        while (Game.GetEvent(Close)) {

            if (Close.Type == sf::Event::Closed)
                Game.Close();
            if ((Close.Type == sf::Event::KeyPressed) && (Close.Key.Code == sf::Key::Escape))
                Game.Close();
        }

        Game.Draw(rocketP1);
        Game.Display();
        Game.Clear();

    }
    return (EXIT_SUCCESS);
}

[/quote][/code]

20
General / Using more than one Event in the main function
« on: December 05, 2009, 09:35:51 pm »
oh thanks Laurent

i didnt realise the functionality of events. now i just write my whole event stuff in one event.

21
General / Using more than one Event in the main function
« on: December 05, 2009, 09:21:13 pm »
Hallo

I try to use 2 Events in the main function. The Event for closing down the window does not work when the control event is in front of it. When i disable the control event the closing event works...
Is there a way to have more than one event in the main function?

Code: [Select]

        sf::Event Control;
        while (App.GetEvent(Control)) {
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Left))
                bool left = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Left))
                bool left = false;
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Right))
                bool right = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Right))
                bool right = false;
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Up))
                bool up = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Up))
                bool up = false;
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Down))
                bool down = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Down))
                bool down = false;
        }

        sf::Event Event;
        while (App.GetEvent(Event)) {
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

22
General / SFML in Eclipse
« on: November 16, 2009, 06:08:09 pm »
Ok i will try to google for implenting librarys in general into ecplipse.
But why do you think is Eclipse a hard to use IDE?

23
General / SFML in Eclipse
« on: November 16, 2009, 05:33:30 pm »
Hello everybody.

There is a nice tutorial for including SFML into Code-Blocks.
But i would prefer to use Eclipse but dont know how to implent SFML. Does anybody know about a tutorial explaining Eclipse implentation or does he or she can explain it?

Pages: 1 [2]
anything