-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.rb
69 lines (53 loc) · 1.31 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
require 'rubygems'
require 'gosu'
class Bulet
attr_reader :image, :x, :y, :speed
def initialize(image, x = 320, y = 240, speed = 5)
@y = y
@x = x
@speed = speed
@image = image
end
def update
@y -= @speed
end
end
class GameWindow < Gosu::Window
@@speed_hor = 5
@@speed_ver = 5
def initialize
super(1600, 1200, false)
self.caption = "Fly"
@fly = Gosu::Image.new(self, "images/ships/main.png", false)
@fire = "images/ships/main.png"
@x = @y = 320
@my_bulets = []
end
def update
if button_down? Gosu::Button::KbLeft or button_down? Gosu::Button::GpLeft
@x -= @@speed_hor
end
if button_down? Gosu::Button::KbRight or button_down? Gosu::Button::GpRight
@x += @@speed_hor
end
if button_down? Gosu::Button::KbDown or button_down? Gosu::Button::GpDown
@y += @@speed_ver
end
if button_down? Gosu::Button::KbUp or button_down? Gosu::Button::GpUp
@y -= @@speed_ver
end
if button_down? Gosu::Button::KbSpace
@my_bulets << Bulet.new(@fire, @x, @y)
end
end
def draw
@my_bulets.each {|bulet|
Gosu::Image.new(self, bulet.image, false).draw_rot(bulet.x, bulet.y, 1, 0.0)
bulet.update
@my_bulets.delete(bulet) if bulet.y < -100
}
@fly.draw_rot(@x, @y, 1, 0.0)
end
window = GameWindow.new
window.show
end