• Create Account

# Carlows

Member Since 16 Jun 2013
Offline Last Active Dec 15 2013 06:44 PM

### SFML - Acceleration in Space?

28 June 2013 - 10:36 PM

Yeap, me again, lol. The thing is, I'm trying to give my ship an acceleration as if it were moving in space (zero gravity), if a press the Up arrow key, the ship increases its acceleration, change its direction (to the mouse vector), and so forth. There's the code I already have:

```sf::Vector2f Nave::getDirection(sf::Vector2f mousePOS, sf::Vector2f playerPOS, float acceleration, sf::Time& delta)
{
sf::Vector2f direction = mousePOS - playerPOS;

direction = direction / sqrt(direction .x * direction .x + direction .y * direction .y) * aceleration;

return direcion;
}

void Nave::update(sf::Time& delta, sf::Vector2f mousePOS)
{
...

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
acceleration += 0.1f;
shipDir = getDirection( mousePOS, shipSprite.getPosition(), aceleration, delta );
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
acceleration -= 0.1f;
}

if( acceleration > 5.0f )
acceleration = 5.0f;
else if( acceleration < 0.0f )
acceleration = 0.0f;

shipSprite.move( shipDir.x, shipDir.y );
shipSprite.setAngle(angle);

...

}

float Nave::Angle( sf::Vector2f playerPOS, sf::Vector2f mousePOS )
{
float angle = atan2(mousePOS.y - playerPOS.y, mousePOS.x - playerPOS.x );
angle = angle * (180/PI);

if(angle < 0)
{
angle = 360 - (-angle);
}

return angle;
}

```

Of course there's an obvious problem, first, the deceleration, but most important, when I press the Up arrow again, the new vector direction totally f**ks the last direction, there's a video showing the problem:

Since I didn't find solution just looking at google (my poor English makes it harder, I think there aren't too much good gaming forums on Spanish), I'm looking for some help (duh).

Edit1:

there's a really explicit example of what i'm looking for:

### SFML - Is there a way to implement lights?

27 June 2013 - 01:03 PM

Well, this is what I have done:

It's nothing amazing, but ignoring it, I was looking for a way to implement a small light on every bullet, first because the bullets can't be seen very well, but I don't want to use sprites for these... Is there a way to do that? I've been trying the sf::BlendMode::Add, but idk how does that exactly work .

### Help with a 2D Space Shooter!

24 June 2013 - 01:29 PM

I'm wanting to start a little project (I'm a beginner), about a Space Shooter, but, I need help with a few things...

The first thing is implementing the shooting, I mean, the bullets will go at the mouse direction, how can I implement the angles of shooting?

The second is, how to implement a simply mini-map? Just showing where my ship is, some bases, etc...

Lol, I wish I could explain a lot better but, English isn't my first language , anyway, any help, link, tutorial, will be appreciated!

I'm using SFML and C++ btw.

### Where should I start?

16 June 2013 - 04:14 PM

Well, I'm a little bit frustrated with this, I don't know where to start at!

I was looking a few tutorials about DirectX, like DirectXTutorials (I think this is far the best, but it isn't free.), rastertek (I don't know, It's code seems a bit harder for me, I think the first tutorials doesn't explain too much about DX...). I was looking for some OpenGL tutorials too, but, I found it like a pine in the a** to setup OpenGL, even I tried to run some tutorials and i get hundreds of compiling errors, so...

What do you recommend to me to start with? I found programming really exciting and usually I have no trouble understanding new topics, but wow, I really don't know where to start...

Btw, apologies for my English, i'm from Venezuela (yeah, Chavez!) and English is not my fort.

PARTNERS