Class: Chippunk::Object

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/chippunk/object.rb

Direct Known Subclasses

StaticObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#coords_to_verts

Constructor Details

#initialize(*args) ⇒ Object

Returns a new instance of Object.



9
10
11
12
# File 'lib/chippunk/object.rb', line 9

def initialize(*args)
  super
  @is_static = false
end

Instance Attribute Details

#body(mass = 0, inertia = 0) ⇒ Object (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/chippunk/object.rb', line 5

def body
  @body
end

#shapeObject

Returns the value of attribute shape.



6
7
8
# File 'lib/chippunk/object.rb', line 6

def shape
  @shape
end

#viewObject (readonly)

Returns the value of attribute view.



6
7
8
# File 'lib/chippunk/object.rb', line 6

def view
  @view
end

#worldObject

Returns the value of attribute world.



7
8
9
# File 'lib/chippunk/object.rb', line 7

def world
  @world
end

Instance Method Details

#angle=(a) ⇒ Object



33
34
35
# File 'lib/chippunk/object.rb', line 33

def angle=(a)
  body.angle = a
end

#collision_type=(type) ⇒ Object



54
55
56
# File 'lib/chippunk/object.rb', line 54

def collision_type=(type)
  shape.collision_type = type.to_sym
end

#draw(canvas) ⇒ Object



66
67
68
69
70
71
# File 'lib/chippunk/object.rb', line 66

def draw(canvas)
  unless view.respond_to?(:draw)
    @shape.draw(canvas)
  end
  
end

#elasticity=(e) ⇒ Object



46
47
48
# File 'lib/chippunk/object.rb', line 46

def elasticity=(e)
  shape.e = e
end

#friction=(u) ⇒ Object



50
51
52
# File 'lib/chippunk/object.rb', line 50

def friction=(u)
  shape.u = u
end

#inertia=(i) ⇒ Object



37
38
39
# File 'lib/chippunk/object.rb', line 37

def inertia=(i)
  body.i = 0
end

#mass=(m) ⇒ Object



29
30
31
# File 'lib/chippunk/object.rb', line 29

def mass=(m)
  body.mass = m
end

#position=(coords) ⇒ Object



22
23
24
25
26
27
# File 'lib/chippunk/object.rb', line 22

def position=(coords)
  x, y = coords.values_at(0, 1)
  puts x, y
  
  body.pos = CP::Vec2.new(x.to_f,y.to_f)
end

#static!Object



58
59
60
# File 'lib/chippunk/object.rb', line 58

def static!
  @is_static = true
end

#static?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/chippunk/object.rb', line 62

def static?
  @is_static
end

#velocity=(v) ⇒ Object



41
42
43
44
# File 'lib/chippunk/object.rb', line 41

def velocity=(v)
  x_direction, y_direction = v.values_at(0,1)
  body.vel = vec2(x_direction, y_direction)
end