Class: Physicist::Laboratory::App

Inherits:
Joyce::Application
  • Object
show all
Defined in:
lib/physicist/laboratory/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scientistObject

Returns the value of attribute scientist.



34
35
36
# File 'lib/physicist/laboratory/app.rb', line 34

def scientist
  @scientist
end

Instance Method Details

#create_scientist(*args) ⇒ Object



85
86
87
# File 'lib/physicist/laboratory/app.rb', line 85

def create_scientist(*args)
  CreateScientist.create(*args)
end

#jumpObject



93
94
95
# File 'lib/physicist/laboratory/app.rb', line 93

def jump
  JumpScientist.create(scientist_id: scientist_id)
end

#move_scientist(direction) ⇒ Object



89
90
91
# File 'lib/physicist/laboratory/app.rb', line 89

def move_scientist(direction)
  MoveScientist.create(scientist_id: scientist_id, direction: direction)
end

#press(key) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/physicist/laboratory/app.rb', line 65

def press(key)
  if key == Gosu::KbLeft
    fire(move_scientist(:left))
  elsif key == Gosu::KbRight
    fire(move_scientist(:right))
  end

  if key == Gosu::KbUp
    fire(jump)
  end
end

#scientist_idObject



97
98
99
# File 'lib/physicist/laboratory/app.rb', line 97

def scientist_id
  @scientist_id ||= SecureRandom.uuid
end

#scientist_viewObject



77
78
79
# File 'lib/physicist/laboratory/app.rb', line 77

def scientist_view
  ScientistView.where(scientist_id: scientist_id).first || NullScientistView.new
end

#setupObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/physicist/laboratory/app.rb', line 36

def setup(*)
  fire(
    create_scientist(
      scientist_id: scientist_id,
      name: "Bill Bye",
      title: "Science Guy",
      position: [0,2],
      velocity: [0,0]
    )
  )
end

#tickObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/physicist/laboratory/app.rb', line 48

def tick
  Scientist.all.each(&:tick)


  # poll for movement keys...
  if window.button_down?(Gosu::KbLeft)
    fire(move_scientist(:left))
  elsif window.button_down?(Gosu::KbRight)
    fire(move_scientist(:right))
  end

  # TODO
  if window.button_down?(Gosu::KbUp)
    fire(jump)
  end
end

#workspace_viewObject



81
82
83
# File 'lib/physicist/laboratory/app.rb', line 81

def workspace_view
  WorkspaceView.where(space_id: scientist_view.space_id).first || NullWorkspaceView.new
end