This project has moved and is read-only. For the latest updates, please go here.

Asteroids clone using Farseer. Is it possible?

Topics: User Forum
Apr 8, 2007 at 10:10 PM
Is it possible to make asteroid type of game using Farseer as physics engine? Problem i'm seeing is screen borders because in asteroids type of game objects that go over screen border start to appear in the opposite side of screen.
Apr 9, 2007 at 6:32 AM
Edited Apr 9, 2007 at 6:33 AM
Just check if the object is off the screen and move it accordingly. Just use it instead of the usual collision box around the viewing area.

For example, (pseudocode)

if object.x > screen.width
object.x = object.x - screen.width;


You may have to account for the width of the sprite and other things.

Also, see the discussion(s) on making top-down games.
Apr 9, 2007 at 10:26 AM
That's not what i was asking. I know how to do an asteroid game. In asteroids everything that goes over an border comes out from opposite border. Lets say you have this big sprite and it start going over bottom border then part of it start to appear from top border of screen.
Problem is that i can easily make sprite drawing routine that can handle this so that i draw part of the object to bottom of the screen and part to top, but how do i that in Farseer. Because that part that comes out from from top of the screen need to have physics too.
One possibility might be do four diffrent rigidbodies because sprite drawing can split in four pieces max and somehow position every rigidbody correctly if sprite splits by going over screen borders.
Apr 9, 2007 at 4:10 PM
I don't see why it can't just go off the screen before coming around the other side.
Apr 9, 2007 at 9:11 PM
Well lets say when you sprite goes over right screen border your sprites coordinates and farseer physics coordinates are still at right screen border. But you also need to have physics for part that comes out from left border of screen.
I don't know how can I explain it any simpler than that.
Maybe I can. Let's say your screen is 240 wide and your sprite is 40 wide then your sprite is at x coordinate of 220 and gets clipped then 20 pixels show at x coordinate 0. Because sprite is physically at x coordinate 220 you don't get any physics for part that is at x coordinate 0. Example if you have another physics object at x coordinate 10 and y coordinates match you won't get any collision.
Hope you can understand it now.

Apr 10, 2007 at 5:00 PM
I understood you. I'm saying that it would be a lot simpler if you waited for the sprite to completely leave the screen before wrapping it around the other side. Most Asteroids clones I've played are like this, and it just doesn't make much sense for an asteroid to exist in more than one place at a time. The user might even get the impression that there are more asteroids than there are.
Apr 10, 2007 at 5:47 PM
Well in normal asteroids objects are so small but i want to do bigger objects also. And if the part that can't be seen is too big you might lose asteroid or some enemy there.
Back in the day when i was programming on amiga haven't done much professional programming after that only hobby stuff but i was one programmer for game called Stardust. So i would like to do stardust kind of game with physics for xna.
And that wrapping thing is only thing i have problem with and i really want to have it.
It's pretty easy to in normal collision system but with physics i might somehow need same object in diffrent world coordinates. Maximum in four places if object is splitted in four parts when it goes over two borders.
Maybe it's somehow possible to do it with Farseer allready somehow and that's what i wanted to know.
Apr 11, 2007 at 5:27 PM
There is nothing built in to Farseer to do this. I'll give it some thought and let you know if I have any ideas.
Apr 11, 2007 at 8:47 PM
Thanks :)
Oct 13, 2007 at 4:05 AM
Edited Oct 13, 2007 at 4:07 AM
I'm curious if any ideas/solutions resulted from this discussion?

A number of interesting 2d space-games would benefit from being able to define the limits of a 2d world and having the edges "wrap" around upon itself. Beyond simple games like asteroids, I'm thinking of ones that are more expansive with seemingly "infinite" space, but actually wrap upon itself. Maybe it actually only takes the spaceship at full-speed a minute before this wrap occurs.

Anyway, I'm wondering if some sort of hack could be put into place to handle objects moving over wrap edge boundaries? Maybe as the original poster suggested, the object could be split and each piece handled separately, but then some how the results composited back for the object as a whole?

If anyone has any ideas on how to best handle this, I would be interested in a solution too.

Aug 23, 2008 at 1:44 PM
Edited Aug 23, 2008 at 1:46 PM
How about making clone object and placing it on the other side when asteroid is leaving screen? But they both have to share speed, collisions etc. e.g. when force is applied to original one, copy has to 'take' this force.

PS. I know, old topic, but this might be useful(I have the same problem).