Class: Physicist::Laboratory::App
- Inherits:
-
Joyce::Application
- Object
- Joyce::Application
- Physicist::Laboratory::App
- Defined in:
- lib/physicist/laboratory/app.rb
Instance Attribute Summary collapse
-
#scientist ⇒ Object
Returns the value of attribute scientist.
Instance Method Summary collapse
- #create_scientist(*args) ⇒ Object
- #jump ⇒ Object
- #move_scientist(direction) ⇒ Object
- #press(key) ⇒ Object
- #scientist_id ⇒ Object
- #scientist_view ⇒ Object
- #setup ⇒ Object
- #tick ⇒ Object
- #workspace_view ⇒ Object
Instance Attribute Details
#scientist ⇒ Object
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 |
#jump ⇒ Object
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_id ⇒ Object
97 98 99 |
# File 'lib/physicist/laboratory/app.rb', line 97 def scientist_id @scientist_id ||= SecureRandom.uuid end |
#scientist_view ⇒ Object
77 78 79 |
# File 'lib/physicist/laboratory/app.rb', line 77 def scientist_view ScientistView.where(scientist_id: scientist_id).first || NullScientistView.new end |
#setup ⇒ Object
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 |
#tick ⇒ Object
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.(Gosu::KbLeft) fire(move_scientist(:left)) elsif window.(Gosu::KbRight) fire(move_scientist(:right)) end # TODO if window.(Gosu::KbUp) fire(jump) end end |
#workspace_view ⇒ Object
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 |