Get coordinates for a rectangles edges

Started by
3 comments, last by Ravnock 11 years, 3 months ago

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.

Advertisement
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

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

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.

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

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

This topic is closed to new replies.

Advertisement