forked from maffei2443/TP2_2_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameObject.rb
172 lines (138 loc) · 3.88 KB
/
gameObject.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
require 'gosu'
require './sprite'
require './box'
class GameObject
def initialize(name, x, y, zlist, width, length)
@name = name
@sprite = Sprite.new(name + ".png")
@hitbox = Hitbox.new(x,y,zlist,width,length)
end
def draw()
@sprite.draw(@x, @y, @z)
end
def hit?(obj)
return @hitbox.check_hit(obj.hitbox.x, obj.hitbox.y, obj.hitbox.zlist, obj.hitbox.width, obj.hitbox.length)
end
attr_reader :hitbox
def update_frame()
end
end
class Falcon < GameObject
def initialize(name, x, y, zlist, width, length)
@movCoolDownTimerV = 0
@movCoolDownTimerH = 0
@name = name
@sprites = [Sprite.new(name + "1.png"), Sprite.new(name + "2.png"),Sprite.new(name + "3.png"),Sprite.new(name + "4.png"),Sprite.new(name + "5.png")]
@hitbox = Hitbox.new(x,y,zlist,width,length)
@spritestate = 1
@spriteStateCounter = 0
end
def draw()
@sprites[@spritestate - 1].draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0])
Gosu::Image.new(@name + @spritestate.to_s + ".png").draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0]-1, 1, 1, 0xff_464678, :default)
end
def mov_up()
if (@hitbox.zlist[0] < 35)
5.times do
@hitbox.zlist[0] = @hitbox.zlist[0] + 1
end
@movCoolDownTimerV = 2
end
end
def mov_down()
if (@hitbox.zlist[0] > 9)
5.times do
@hitbox.zlist[0] = @hitbox.zlist[0] - 1
end
@movCoolDownTimerV = 2
end
end
def mov_right()
if (@hitbox.y + @hitbox.length < 480 - 32)
3.times do
@hitbox.y = @hitbox.y + 0.60
@hitbox.x = @hitbox.x + 2
end
@movCoolDownTimerH = 2
end
end
def mov_left()
if (@hitbox.x > 32)
3.times do
@hitbox.y = @hitbox.y - 0.60
@hitbox.x = @hitbox.x - 2
end
@movCoolDownTimerH = 2
end
end
def update_frame()
@spriteStateCounter = @spriteStateCounter + 1
if(@spriteStateCounter == 6)
@spriteStateCounter = 0
@spritestate = @spritestate + 1
if(@spritestate == 6)
@spritestate = 1
end
end
if @movCoolDownTimerV > 0
@movCoolDownTimerV = @movCoolDownTimerV - 1
end
if @movCoolDownTimerH > 0
@movCoolDownTimerH = @movCoolDownTimerH - 1
end
if ((Gosu.button_down? Gosu::KB_UP) and (@movCoolDownTimerV == 0))
self.mov_up
end
if ((Gosu.button_down? Gosu::KB_DOWN) and (@movCoolDownTimerV == 0))
self.mov_down
end
if ((Gosu.button_down? Gosu::KB_RIGHT) and (@movCoolDownTimerH == 0))
self.mov_right
end
if ((Gosu.button_down? Gosu::KB_LEFT) and (@movCoolDownTimerH == 0))
self.mov_left
end
end
end
class Hiero < GameObject
def initialize(name, x, y, zlist, width, length)
@movCoolDownTimer = 0
@name = name
@sprite = Sprite.new(name + ".png")
@hitbox = Hitbox.new(x,y,zlist,width,length)
end
def draw()
@sprite.draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0])
Gosu::Image.new(@name + ".png").draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0] - 1, 1, 1, 0xff_464678, :default)
end
def update_frame()
if @movCoolDownTimer > 0
@movCoolDownTimer = @movCoolDownTimer - 1
elsif(@movCoolDownTimer == 0)
@hitbox.y = @hitbox.y + 1
@hitbox.x = @hitbox.x - 1
@movCoolDownTimerH = 2
end
end
end
class Rock < GameObject
def initialize(name, x, y)
@movCoolDownTimer = 0
@name = name
@sprite = Sprite.new(name + ".png")
@hitbox = Hitbox.new(x,y,[0],0,0)
end
def draw()
@sprite.draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0], 2, 2)
Gosu::Image.new(@name + ".png").draw(@hitbox.x, @hitbox.y, @hitbox.zlist[0] - 1, 1, 1, 0xff_464678, :default)
end
def update_frame()
if @movCoolDownTimer > 0
@movCoolDownTimer = @movCoolDownTimer - 1
elsif(@movCoolDownTimer == 0)
@hitbox.y = @hitbox.y + 1
@hitbox.x = @hitbox.x - 1
@movCoolDownTimerH = 2
end
end
end