-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.rb
executable file
·77 lines (56 loc) · 1.06 KB
/
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
75
76
77
require 'rubygems'
require 'gosu'
require 'level.rb'
require 'mouse.rb'
require 'car.rb'
require 'goat.rb'
require 'arrow.rb'
class GameWindow < Gosu::Window
attr_accessor(:car, :stuff)
def initialize
super(864, 672, false)
self.caption = "MouseTrap Mania"
@stuff = Array.new
@level = Level.new(self,ARGV[0])
@level.load_holes
@car = Car.new(self,@level,1,1)
@song = Gosu::Song.new(self, "resources/sound/main.ogg")
end
def update
@stuff.each do |thing|
thing.update
end
exit if @car.life == 0
@song.play unless @song.playing?
end
def draw
@level.draw
@stuff.each do |thing|
thing.draw
end
end
def button_down(id)
case id
when Gosu::Button::KbUp
@car.steer(0)
when Gosu::Button::KbRight
@car.steer(1)
when Gosu::Button::KbDown
@car.steer(2)
when Gosu::Button::KbLeft
@car.steer(3)
when Gosu::Button::KbEscape
close
when 13
@car.arrowdir = 0
when 0
@car.arrowdir = 3
when 1
@car.arrowdir = 2
when 2
@car.arrowdir = 1
end
end
end
window = GameWindow.new
window.show