class Physicist::Laboratory::Scientist

user avatars are ‘scientists’

Attributes

name[RW]

attr_accessor :space_id #??

position[RW]
title[RW]

attr_accessor :space_id #??

updated_at[RW]
velocity[RW]

Public Instance Methods

body() click to toggle source
# File lib/physicist/laboratory/models/scientist.rb, line 66
def body
  construct_body
end
construct_body() click to toggle source
# 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() click to toggle source
# File lib/physicist/laboratory/models/scientist.rb, line 62
def current
  body.at(Time.now, obstacles: space.obstacles)
end
ground_speed() click to toggle source
# File lib/physicist/laboratory/models/scientist.rb, line 20
def ground_speed
  5
end
jump() click to toggle source
# 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() click to toggle source
# File lib/physicist/laboratory/models/scientist.rb, line 28
def leg_strength # ??
  -15
end
max_ground_speed() click to toggle source
# File lib/physicist/laboratory/models/scientist.rb, line 24
def max_ground_speed
  10
end
max_jump_velocity() click to toggle source
# File lib/physicist/laboratory/models/scientist.rb, line 32
def max_jump_velocity
  -30
end
move(direction:) click to toggle source
# 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() click to toggle source
# File lib/physicist/laboratory/models/scientist.rb, line 12
def tick
  update(
    position: current.position, 
    velocity: current.velocity, 
    updated_at: Time.now
  )
end