Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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: 289

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: 1202

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: 289

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