-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.rb
51 lines (38 loc) · 905 Bytes
/
state.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class State
include Rubygame::EventHandler::HasEventHandler
def initialize(screen, content)
@screen = screen
@graphics = content
make_queue
@keys = []
#@pkeys = []
make_magic_hooks(
KeyPressed => :key_pressed,
KeyReleased => :key_released,
ClockTicked => :update_clock,
QuitRequested => :exit_script )
end
def update(clock)
#@pkeys = @keys
@queue.fetch_sdl_events
@queue << clock.tick
@queue.each do |event|
self.handle( event )
end
end
def draw()
end
def make_queue
@queue = EventQueue.new()
@queue.enable_new_style_events
@queue.ignore = [MouseMoved]
end
# Add it to the list of keys being pressed.
def key_pressed( event )
@keys += [event.key]
end
# Remove it from the list of keys being pressed.
def key_released( event )
@keys -= [event.key]
end
end