Top Level Namespace
Defined Under Namespace
Modules: Cursor, Disk, Draggable, Fantasy, Global, Gravitier, Jumper, Log, Mouse, MoveByCursor, MoveByDirection, Mover, Music, Sound, Tween, UserInputs, Utils Classes: Actor, Background, Camera, Clock, Color, Coordinates, Game, HudImage, HudText, Image, Shape, Tilemap
Instance Method Summary collapse
-
#on_cursor_down(&block) ⇒ Object
Triggered any time cursor down key is pressed.
-
#on_cursor_left(&block) ⇒ Object
Triggered any time cursor left key is pressed.
-
#on_cursor_right(&block) ⇒ Object
Triggered any time cursor right key is pressed.
-
#on_cursor_up(&block) ⇒ Object
Triggered any time cursor up key is pressed.
-
#on_end(&block) ⇒ Object
Defines the end Scene.
-
#on_game(&block) ⇒ Object
Defines the game Scene.
-
#on_loop(&block) ⇒ Object
Executes on every frame.
-
#on_mouse_button_left(&block) ⇒ Object
Triggered any time mouse left button is pressed.
-
#on_mouse_button_right(&block) ⇒ Object
Triggered any time mouse right button is pressed.
-
#on_presentation(&block) ⇒ Object
Defines the presentation Scene.
-
#on_space_bar(&block) ⇒ Object
Triggered any time space bar key is pressed.
-
#start! ⇒ Object
Starts the game.
Instance Method Details
#on_cursor_down(&block) ⇒ Object
Triggered any time cursor down key is pressed. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
on_cursor_down do
look_down # for example
end
end
106 107 108 |
# File 'lib/fantasy/base.rb', line 106 def on_cursor_down(&block) Global.cursor_down_proc = block end |
#on_cursor_left(&block) ⇒ Object
Triggered any time cursor left key is pressed. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
on_cursor_left do
look_left # for example
end
end
118 119 120 |
# File 'lib/fantasy/base.rb', line 118 def on_cursor_left(&block) Global.cursor_left_proc = block end |
#on_cursor_right(&block) ⇒ Object
Triggered any time cursor right key is pressed. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
on_cursor_right do
look_right # for example
end
end
130 131 132 |
# File 'lib/fantasy/base.rb', line 130 def on_cursor_right(&block) Global.cursor_right_proc = block end |
#on_cursor_up(&block) ⇒ Object
Triggered any time cursor up key is pressed. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
on_cursor_up do
look_ups # for example
end
end
94 95 96 |
# File 'lib/fantasy/base.rb', line 94 def on_cursor_up(&block) Global.cursor_up_proc = block end |
#on_end(&block) ⇒ Object
Defines the end Scene
on_end do
HudText.new(position: Coordinates.new(10, 100), text: "You are dead. Press space to re-tart")
do
Global.go_to_presentation
end
end
48 49 50 |
# File 'lib/fantasy/base.rb', line 48 def on_end(&block) Global.end_proc = block end |
#on_game(&block) ⇒ Object
33 34 35 |
# File 'lib/fantasy/base.rb', line 33 def on_game(&block) Global.game_proc = block end |
#on_loop(&block) ⇒ Object
Executes on every frame. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
on_loop do
Global.references.time = Time.at(Global.seconds_in_scene).utc.strftime("%M:%S")
end
end
65 66 67 |
# File 'lib/fantasy/base.rb', line 65 def on_loop(&block) Global.loop_proc = block end |
#on_mouse_button_left(&block) ⇒ Object
Triggered any time mouse left button is pressed. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
do
# for example
end
end
142 143 144 |
# File 'lib/fantasy/base.rb', line 142 def (&block) Global. = block end |
#on_mouse_button_right(&block) ⇒ Object
Triggered any time mouse right button is pressed. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
do
# for example
end
end
154 155 156 |
# File 'lib/fantasy/base.rb', line 154 def (&block) Global. = block end |
#on_presentation(&block) ⇒ Object
Defines the presentation Scene
on_presentation do
HudText.new(position: Coordinates.new(10, 100), text: "Press space to start")
do
Global.go_to_game
end
end
19 20 21 |
# File 'lib/fantasy/base.rb', line 19 def on_presentation(&block) Global.presentation_proc = block end |
#on_space_bar(&block) ⇒ Object
Triggered any time space bar key is pressed. To be used inside one of the scene blocks (on_presentation
, on_game
, on_end
)
on_game do
do
shoot_gun # for example
end
end
82 83 84 |
# File 'lib/fantasy/base.rb', line 82 def (&block) Global. = block end |
#start! ⇒ Object
Starts the game. This method has to be called when all the desired scene blocks (on_presentation
, on_game
, on_end
) have been declared.
on_game do
# do game stuff
end
start!
166 167 168 169 170 171 172 |
# File 'lib/fantasy/base.rb', line 166 def start! raise "'SCREEN_WIDTH' and 'SCREEN_HEIGHT' both have to be set at the beginning of the program" unless defined?(SCREEN_WIDTH) && defined?(SCREEN_HEIGHT) Global.setup Global.game = Game.new(SCREEN_WIDTH, SCREEN_HEIGHT) Global.game.show end |