Asteroids Triangle spaceship

Official forum for the Chipmunk2D Physics Library.
Post Reply
Puppybasher
Posts: 8
Joined: Tue Jan 12, 2010 5:55 pm
Contact:

Asteroids Triangle spaceship

Post by Puppybasher »

Hey All

So i'm kinda new to chipmunk and I thought I'd make a little asteroids game. But I have litte problem.
Sometimes the collision detection of my spaceship seems a bit weird or my image is rendered incorrectly. I have no idea. So I was wondering if you guys could help me out

My spaceship consists out of a Poly shape with 3 vector coordinates, being:

Code: Select all

[CP::Vec2.new(10, 0), CP::Vec2.new(-10, -10), CP::Vec2.new(-10, 10)]
then I create and Image with RMagick to represent my shape

Code: Select all

height = 20
width = 20
		
rimage = Magick::Image.new(width, height) { self.background_color = 'transparent' }
rbrush = Magick::Draw.new
rbrush.stroke('white')

rbrush.line(20, 10, 0, 0)
rbrush.line(20, 10, 0, 20)
rbrush.line(0, 0, 0, 20)
		
rbrush.draw(rimage)
@image = Gosu::Image.new(screen, rimage, false)
and finaly to render the spaceship I do something like this
(just to be clear, @shape is the spaceship's poly shape :P )

Code: Select all

@image.draw_rot(@shape.body.p.x, @shape.body.p.y, 1, @shape.body.a.to_deg)
The "wrong" collision detection/drawing seems to differ from what angle my spaceship is at. Im confused :cry: :P
(to test this I spawn a little ball i can fly into :P)

Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Asteroids Triangle spaceship

Post by slembcke »

How does image#draw_rot() work? The collision shape you are making is more or less centered around (0,0). Is the point you give telling it where to put the corner of the image or the center? Are you sure the rotation of the collision shape and the image matches?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Puppybasher
Posts: 8
Joined: Tue Jan 12, 2010 5:55 pm
Contact:

Re: Asteroids Triangle spaceship

Post by Puppybasher »

Its something like this:
draw_rot (x, y, z, angle, center_x=0.5, center_y=0.5, factor_x=1, factor_y=1, color=0xffffffff, mode=:default)

the x and y are the top left corner of the image.

center_x: Relative horizontal position of the rotation center on the image. 0 is the left border, 1 is the right border, 0.5 is the center (and default)
center_y: see center_x

So I guess he draws the image at the center. :|
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Asteroids Triangle spaceship

Post by slembcke »

So you just need to move it around a bit to make it line up then?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Puppybasher
Posts: 8
Joined: Tue Jan 12, 2010 5:55 pm
Contact:

Re: Asteroids Triangle spaceship

Post by Puppybasher »

Yes, but like I said before, it depends on what angle the ship's at.

for example:
when it's at 0 degrees (thus facing right) the ball "bumps" of the front too early. So it seems there's an "invisible part" of the ship there. Though when the ship is facing left (180 degrees turned) the front works just fine. But then the sides are a bit off. So it is kinda weird :P
Puppybasher
Posts: 8
Joined: Tue Jan 12, 2010 5:55 pm
Contact:

Re: Asteroids Triangle spaceship

Post by Puppybasher »

No clue what I did wrong but I rewrote it all and now it works just fine :roll:
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Asteroids Triangle spaceship

Post by slembcke »

Heh, that is always fun. I always keep my stuff in version control and it's always frustrating to see that it was a single negative sign that was preventing it from working when you spent hours looking for the problem.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests