Class: Physicist::Laboratory::Scientist
- Inherits:
-
Metacosm::Model
- Object
- Metacosm::Model
- Physicist::Laboratory::Scientist
- Defined in:
- lib/physicist/laboratory/models/scientist.rb
Overview
user avatars are 'scientists'
Instance Attribute Summary collapse
-
#name ⇒ Object
attr_accessor :space_id #??.
-
#position ⇒ Object
Returns the value of attribute position.
-
#title ⇒ Object
attr_accessor :space_id #??.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#velocity ⇒ Object
Returns the value of attribute velocity.
Instance Method Summary collapse
- #body ⇒ Object
- #construct_body ⇒ Object
- #current ⇒ Object
- #ground_speed ⇒ Object
- #jump ⇒ Object
-
#leg_strength ⇒ Object
??.
- #max_ground_speed ⇒ Object
- #max_jump_velocity ⇒ Object
- #move(direction:) ⇒ Object
- #tick ⇒ Object
Instance Attribute Details
#name ⇒ Object
attr_accessor :space_id #??
8 9 10 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 8 def name @name end |
#position ⇒ Object
Returns the value of attribute position.
9 10 11 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 9 def position @position end |
#title ⇒ Object
attr_accessor :space_id #??
8 9 10 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 8 def title @title end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
10 11 12 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 10 def updated_at @updated_at end |
#velocity ⇒ Object
Returns the value of attribute velocity.
9 10 11 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 9 def velocity @velocity end |
Instance Method Details
#body ⇒ Object
66 67 68 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 66 def body construct_body end |
#construct_body ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 70 def construct_body # ...integrate physicist bodies... Physicist::Body.new( position: position, velocity: velocity, t0: updated_at || Time.now, dimensions: [2,2] ) end |
#current ⇒ Object
62 63 64 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 62 def current body.at(Time.now, obstacles: space.obstacles) end |
#ground_speed ⇒ Object
20 21 22 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 20 def ground_speed 5 end |
#jump ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 50 def jump vx, vy = *current.velocity return if vy.abs > 0.0 dvy = leg_strength update( position: current.position, velocity: [vx, vy + dvy], updated_at: Time.now ) end |
#leg_strength ⇒ Object
??
28 29 30 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 28 def leg_strength # ?? -15 end |
#max_ground_speed ⇒ Object
24 25 26 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 24 def max_ground_speed 10 end |
#max_jump_velocity ⇒ Object
32 33 34 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 32 def max_jump_velocity -30 end |
#move(direction:) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 36 def move(direction:) vx,vy = *current.velocity speed = ground_speed dvx = direction == :left ? -speed : speed vxt = vx + dvx return unless vxt.abs < max_ground_speed update( position: current.position, velocity: [vxt, vy], updated_at: Time.now ) end |
#tick ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/physicist/laboratory/models/scientist.rb', line 12 def tick update( position: current.position, velocity: current.velocity, updated_at: Time.now ) end |