forked from blowmage/ZOMG_GAMES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubyconf_game.rb
74 lines (56 loc) · 1.29 KB
/
rubyconf_game.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'rubygems'
require 'gosu'
require './rubyconf_game/play_level'
require './rubyconf_game/win_level'
require './rubyconf_game/fail_level'
class RubyConfGame < Gosu::Window
attr_reader :time, :sounds
def initialize width=800, height=600, fullscreen=false
super
self.caption = 'ESCAPE TO RUBYCONF!!!'
# So multiple sprites don't create duplicate objects
@sounds = {}
# Levels
@play = PlayLevel.new self
@win = WinLevel.new self
@fail = FailLevel.new self
# @play.on_start { do_something_here! }
@play.on_win { win! }
@play.on_fail { fail! }
@play.on_quit { close }
@fail.on_continue { play! }
@fail.on_quit { close }
@win.on_continue { @play.add_snake!; play!}
@win.on_quit { close }
play!
end
def play!
@level = @play
@play.start!
end
def fail!
@level = @fail
@fail.start!
end
def win!
@level = @win
@win.start!
end
def button_down id
@level.button_down id if @level.respond_to? :button_down
end
def button_up id
@level.button_up id if @level.respond_to? :button_up
end
def snakes_count
@play.snakes_count
end
def update
@time = Time.now.to_f
@level.update
end
def draw
@level.draw
end
end
RubyConfGame.new.show