Class: Physicist::Laboratory::Scientist

Inherits:
Metacosm::Model
  • Object
show all
Defined in:
lib/physicist/laboratory/models/scientist.rb

Overview

user avatars are 'scientists'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

attr_accessor :space_id #??



8
9
10
# File 'lib/physicist/laboratory/models/scientist.rb', line 8

def name
  @name
end

#positionObject

Returns the value of attribute position.



9
10
11
# File 'lib/physicist/laboratory/models/scientist.rb', line 9

def position
  @position
end

#titleObject

attr_accessor :space_id #??



8
9
10
# File 'lib/physicist/laboratory/models/scientist.rb', line 8

def title
  @title
end

#updated_atObject

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

#velocityObject

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

#bodyObject



66
67
68
# File 'lib/physicist/laboratory/models/scientist.rb', line 66

def body
  construct_body
end

#construct_bodyObject



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

#currentObject



62
63
64
# File 'lib/physicist/laboratory/models/scientist.rb', line 62

def current
  body.at(Time.now, obstacles: space.obstacles)
end

#ground_speedObject



20
21
22
# File 'lib/physicist/laboratory/models/scientist.rb', line 20

def ground_speed
  5
end

#jumpObject



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_strengthObject

??



28
29
30
# File 'lib/physicist/laboratory/models/scientist.rb', line 28

def leg_strength # ??
  -15
end

#max_ground_speedObject



24
25
26
# File 'lib/physicist/laboratory/models/scientist.rb', line 24

def max_ground_speed
  10
end

#max_jump_velocityObject



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

#tickObject



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