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!


Get coordinates for a rectangles edges


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 P0jahn   Members   -  Reputation: 272

Like
0Likes
Like

Posted 09 January 2013 - 10:43 AM

I need to implement a laser unit to my game that fire a rotating(360 degree) laser. The laser target coordinate is where I am getting stuck at. Every frame, it need to update its target coordinates so the laser is spinning. So if I have a rectangle that is 800x600, first I get coordinate 1:0, then 2:0, and later 800:0, then 800:1, 800:2, later 800:600, then 799:600. I hope that was clear. I thought it was an easy task, I opened eclipse but got stuck pretty fast smile.png Searched on google but could not find anything.



Sponsor:

#2 Ravnock   Members   -  Reputation: 294

Like
0Likes
Like

Posted 09 January 2013 - 11:09 AM

I need to implement a laser unit to my game that fire a rotating(360 degree) laser. The laser target coordinate is where I am getting stuck at. Every frame, it need to update its target coordinates so the laser is spinning. So if I have a rectangle that is 800x600, first I get coordinate 1:0, then 2:0, and later 800:0, then 800:1, 800:2, later 800:600, then 799:600. I hope that was clear. I thought it was an easy task, I opened eclipse but got stuck pretty fast smile.png Searched on google but could not find anything.

The laser has to follow a path of targets, I would create a class "Follower" with a container with points to follow and a class CircuitFollower that updates the current point until the end and begins again, initialized with  this three points: (0,0) (800,0) (800,600)

 

The class perform an Action every frame and updates the current point every frame (usually to the next).

 

So if you have a class Enemy you should implement this class.

 

Class Follower

{

 Queue pointsToFollow;

 Action();

 Update();

}

 

Class CircuitFollower

{

  ...

}

 

 

Maybe it's too generic for you, I don't know... but it's useful for more stuff

 


#3 P0jahn   Members   -  Reputation: 272

Like
0Likes
Like

Posted 09 January 2013 - 12:56 PM

Actually, that is a fantastic idea and is well compatible with my game. Thanks!



#4 Kwizatz   GDNet+   -  Reputation: 1206

Like
1Likes
Like

Posted 09 January 2013 - 04:51 PM

You may want to consider using polar coordinates or just store the angle of the ray to calculate the line.

If you just sweep the screen borders, the animation will seem to slow down and speed up because of the difference in ratio between width and height.



#5 Ravnock   Members   -  Reputation: 294

Like
0Likes
Like

Posted 11 January 2013 - 05:34 AM

Actually, that is a fantastic idea and is well compatible with my game. Thanks!

You are welcome, it's nice to be useful!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS