Class: Bestguigui::App

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/bestguigui/app.rb

Overview

Sous-classe pour ton jeu, appelle switch_state pour changer d'écran.

Instance Method Summary collapse

Constructor Details

#initialize(width: 800, height: 600, title: "Game") ⇒ App

Returns a new instance of App.



4
5
6
7
8
# File 'lib/bestguigui/app.rb', line 4

def initialize(width: 800, height: 600, title: "Game")
  super(width, height)
  self.caption = title
  @last_update_time = Gosu.milliseconds
end

Instance Method Details

#button_down(id) ⇒ Object



29
30
31
# File 'lib/bestguigui/app.rb', line 29

def button_down(id)
  @state&.button_down(id)
end

#button_up(id) ⇒ Object



33
34
35
# File 'lib/bestguigui/app.rb', line 33

def button_up(id)
  @state&.button_up(id)
end

#drawObject



25
26
27
# File 'lib/bestguigui/app.rb', line 25

def draw
  @state&.draw
end

#switch_state(state) ⇒ Object



10
11
12
13
14
15
# File 'lib/bestguigui/app.rb', line 10

def switch_state(state)
  @state&.exit
  @state = state
  @state.app = self
  @state.enter
end

#updateObject



17
18
19
20
21
22
23
# File 'lib/bestguigui/app.rb', line 17

def update
  now = Gosu.milliseconds
  dt = (now - @last_update_time) / 1000.0
  @last_update_time = now

  @state&.update(dt)
end