Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


G4MR

Member Since 06 Jan 2013
Offline Last Active Jan 11 2013 12:46 PM

Topics I've Started

SFML sprite movement (think super meat boy's rocket levels)

06 January 2013 - 10:09 PM

I'm a complete newbie when it comes to game development and I'm catching up on my c++ (would consider myself below average in c++ programming), so I've been messing around with SFML 2.0 (which is amazing compared to my experience with SDL) and I've been playing with some code which takes two rects -> draws them on the screen and one rect is controlled using WASD and the other rect attempts to go in the direction of the other rect's current location on the screen.

Right now I've figured out with a little googling how to get the angle of a line of two points and then send the current rect to the other one eg.:

angle = (atan2(player.y - zombie.y, player.x - zombie.x) * 180) / M_PI; 
x = cos(angle); 
y = sin(angle); 

Then I could properly send the zombie to the player based on it's current position.

The Problem: Every time I move my player around the window, the zombie stops moving in place (im assuming because the angle is constantly being calculated in the game loop) until I stop moving my player on the screen then it proceeds to move towards the player again.

How do I make it so the zombie rect smoothly continues moving towards the player on the screen regardless of where I move the player on my current screen as it's moving on the screen?

 

 

I guess the best way to think of it is my code works when the player sprite isn't moving, but when it's moving it'll stop moving completely.  What I want to do is basically pull off what super meat boy did with their rockets and it'll keep chasing you regardless of the position: http://www.gamespot.com/super-meat-boy/videos/super-meat-boy-unforgiving-rocket-level-gameplay-movie-6282320/


PARTNERS