Class: Bestguigui::App
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Bestguigui::App
- Defined in:
- lib/bestguigui/app.rb
Overview
Sous-classe pour ton jeu, appelle switch_state pour changer d'écran.
class Game < Bestguigui::App
def initialize
super(width: 800, height: 600, title: "Mon jeu", autoload: __dir__)
switch_state(TitleState.new)
end
end
Instance Method Summary collapse
-
#button_down(id) ⇒ Object
Échap ferme le jeu depuis n'importe quel écran — convention reprise dans (presque) chaque jam.
- #button_up(id) ⇒ Object
- #draw ⇒ Object
-
#initialize(width: 800, height: 600, title: "Game", cursor: false, autoload: nil, close_on_escape: true) ⇒ App
constructor
A new instance of App.
- #needs_cursor? ⇒ Boolean
- #switch_state(state) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(width: 800, height: 600, title: "Game", cursor: false, autoload: nil, close_on_escape: true) ⇒ App
Returns a new instance of App.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bestguigui/app.rb', line 11 def initialize(width: 800, height: 600, title: "Game", cursor: false, autoload: nil, close_on_escape: true) super(width, height) self.caption = title @cursor = cursor @close_on_escape = close_on_escape @last_update_time = Gosu.milliseconds # require automatique de tout lib/**/*.rb du projet — passe # autoload: __dir__ depuis le init.rb du jeu plutôt que de # réécrire le Dir[...].sort.each toi-même. Dir[File.join(autoload, "lib", "**", "*.rb")].sort.each { |file| require file } if autoload end |
Instance Method Details
#button_down(id) ⇒ Object
Échap ferme le jeu depuis n'importe quel écran — convention reprise dans (presque) chaque jam. Si Échap sert à autre chose chez toi (menu pause, confirmation avant de quitter...), passe close_on_escape: false à super et gère KB_ESCAPE toi-même dans tes states.
52 53 54 55 |
# File 'lib/bestguigui/app.rb', line 52 def (id) @state&.(id) close! if @close_on_escape && id == Gosu::KB_ESCAPE end |
#button_up(id) ⇒ Object
57 58 59 |
# File 'lib/bestguigui/app.rb', line 57 def (id) @state&.(id) end |
#draw ⇒ Object
43 44 45 |
# File 'lib/bestguigui/app.rb', line 43 def draw @state&.draw end |
#needs_cursor? ⇒ Boolean
24 25 26 |
# File 'lib/bestguigui/app.rb', line 24 def needs_cursor? @cursor end |
#switch_state(state) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/bestguigui/app.rb', line 28 def switch_state(state) @state&.exit @state = state @state.app = self @state.enter end |
#update ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/bestguigui/app.rb', line 35 def update now = Gosu.milliseconds dt = (now - @last_update_time) / 1000.0 @last_update_time = now @state&.update(dt) end |