Enemy on target

Talk about making games.

Enemy on target

Postby mcavalcanti » Wed Jun 27, 2012 2:52 am

Hello! Imagine a game like Asteroids (http://www.oldsoftware.com/softimg7/atari2.jpg), where your spaceship moves in circle/rotation. I just did the sprite rotation and the controls. It's ok. What I need to do to calculate that the spaceship is "looking" to an enemy? In other words, how to know the enemy is "on target"?

To move the ship, I'm using something like this:
Key Down >> Right:
ang-=1;
if(ang<0){ang=180;}
animpos=ang;

But I need a way to know the ship is pointing to an enemy.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Enemy on target

Postby skydereign » Wed Jun 27, 2012 5:45 am

If you have the animation setup already, then it is just a matter of getting the animpos code. One thing that will make this easier is if you have the rotation started facing right, and rotate counterclockwise. Then you can just use something like this.
Code: Select all
animpos = angle/360.0*nframes; // you may want to rotate by half a frame here

There are several examples of this on the forums.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest