Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Ruby Chipmunk Integration beginner hacking gosu-example
- - By sylvain303 Date 2017-01-30 06:41
Hi,

I'm testing the physics, notably to have collision detection.

First I read https://github.com/gosu/gosu/wiki/Ruby-Chipmunk-Integration OK.

I just would like to add a border to the window limit (600x600)
in: https://github.com/gosu/gosu-examples/blob/master/examples/chipmunk_integration.rb

So the ship will collide on the border and probably bounce back into the defined area.

I'm thinking about adding a box of that size and add collision with :ship, but for now I don't know about how to set this box.

mass, moment, and how to tell chipmunk that it is a bounding box, the ship is inside the box?

I'm keep reading…

Regards,
Sylvain.
Parent - - By sylvain303 Date 2017-02-01 06:38
I found it, the trick is to define 4 CP::Shap::Segment

I found this old code: https://github.com/PhilCK/Chipmunk-Examples/blob/master/02_slides.rb


class Wall
  attr_reader :a, :b
                                                                               
  def initialize(window, shape, pos)
    # window needs to have a attr_accessor for :space
    @window = window

    @color = Gosu::Color::WHITE

    @a = CP::Vec2.new(shape[0][0], shape[0][1])
    @b = CP::Vec2.new(shape[1][0], shape[1][1])

    @body = CP::Body.new(CP::INFINITY, CP::INFINITY)
    @body.p = CP::Vec2.new(pos[0], pos[1])
    @body.v = CP::Vec2.new(0,0)

    @shape = CP::Shape::Segment.new(@body, @a, @b, 1)
    @shape.e = 0.5
    @shape.u = 1

    @window.space.add_static_shape(@shape)
  end

  def draw
    @window.draw_line(@body.p.x + a.x, @body.p.y + a.y, @color,
                      @body.p.x + b.x, @body.p.y + b.y, @color,
                      ZOrder::Wall)
  end
end


I integrated it here:

https://github.com/Sylvain303/gosu-examples/blob/test_chipmunk/examples/chipmunk_integration.rb#L218
Parent - - By jlnr (dev) Date 2017-02-01 06:44
Thanks for reporting back. I've linked the PhilCK/Chipmunk-Examples repo from the Ruby-Chipmunk-Integration wiki page, so helpfully it will be easier to find for the next developer.
Parent - By sylvain303 Date 2017-02-12 05:41
cool :)

Could you put the URL link, where did you do that?
Parent - By sylvain303 Date 2017-02-12 05:44
Ho, found!

https://github.com/gosu/gosu/wiki/Ruby-Chipmunk-Integration#ruby-chipmunk-integration
At the end of the paragraph.

See also this topic, I posted some links to be merged some where…

ruby and chipmunk <https://www.libgosu.org/cgi-bin/mwf/topic_show.pl?tid=1325>
Up Topic Gosu / Gosu Exchange / Ruby Chipmunk Integration beginner hacking gosu-example

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill