gosu 0.7.5.1-mswin32 → 0.7.6-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/CptnRuby.rb +14 -7
- data/examples/RMagickIntegration.rb +447 -0
- data/examples/Tutorial.rb +1 -1
- data/examples/media/CptnRuby Tileset.png +0 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Sky.jpg +0 -0
- data/examples/media/Smoke.png +0 -0
- data/examples/media/Soldier.png +0 -0
- data/examples/media/Space.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/lib/gosu.so +0 -0
- metadata +39 -27
data/examples/CptnRuby.rb
CHANGED
@@ -24,11 +24,12 @@ end
|
|
24
24
|
# 5) make the player wider, so he doesn't fall off edges as easily
|
25
25
|
# 6) add background music (check if playing in Window#update to implement
|
26
26
|
# looping)
|
27
|
+
# 7) implement parallax scrolling for the star background!
|
27
28
|
# Getting tricky:
|
28
|
-
#
|
29
|
+
# 8) optimize Map#draw so only tiles on screen are drawn (needs modulo, a pen
|
29
30
|
# and paper to figure out)
|
30
|
-
#
|
31
|
-
# Enemies, a more sophisticated object system, weapons, title and credits
|
31
|
+
# 9) add loading of next level when all gems are collected
|
32
|
+
# ...Enemies, a more sophisticated object system, weapons, title and credits
|
32
33
|
# screens...
|
33
34
|
|
34
35
|
require 'gosu'
|
@@ -143,7 +144,8 @@ class Map
|
|
143
144
|
attr_reader :width, :height, :gems
|
144
145
|
|
145
146
|
def initialize(window, filename)
|
146
|
-
|
147
|
+
# Load 60x60 tiles, 5px overlap in all four directions.
|
148
|
+
@tileset = Image.load_tiles(window, "media/CptnRuby Tileset.png", 60, 60, true)
|
147
149
|
@sky = Image.new(window, "media/Space.png", true)
|
148
150
|
|
149
151
|
gem_img = Image.new(window, "media/CptnRuby Gem.png", false)
|
@@ -170,14 +172,19 @@ class Map
|
|
170
172
|
end
|
171
173
|
|
172
174
|
def draw(screen_x, screen_y)
|
175
|
+
# Sigh, stars!
|
176
|
+
@sky.draw(0, 0, 0)
|
177
|
+
|
178
|
+
|
173
179
|
# Very primitive drawing function:
|
174
180
|
# Draws all the tiles, some off-screen, some on-screen.
|
175
|
-
@sky.draw(0, 0, 0)
|
176
181
|
@height.times do |y|
|
177
182
|
@width.times do |x|
|
178
183
|
tile = @tiles[x][y]
|
179
184
|
if tile
|
180
|
-
|
185
|
+
# Draw the tile with an offset (tile images have some overlap)
|
186
|
+
# Scrolling is implemented here just as in the game objects.
|
187
|
+
@tileset[tile].draw(x * 50 - screen_x - 5, y * 50 - screen_y - 5, 0)
|
181
188
|
end
|
182
189
|
end
|
183
190
|
end
|
@@ -194,7 +201,7 @@ class Game < Window
|
|
194
201
|
attr_reader :map
|
195
202
|
|
196
203
|
def initialize
|
197
|
-
super(640, 480, false
|
204
|
+
super(640, 480, false)
|
198
205
|
self.caption = "Cptn. Ruby"
|
199
206
|
@map = Map.new(self, "media/CptnRuby Map.txt")
|
200
207
|
@cptn = CptnRuby.new(self, 400, 100)
|
@@ -0,0 +1,447 @@
|
|
1
|
+
begin
|
2
|
+
# In case you use Gosu via RubyGems.
|
3
|
+
require 'rubygems'
|
4
|
+
rescue LoadError
|
5
|
+
# In case you don't.
|
6
|
+
end
|
7
|
+
|
8
|
+
# A (too) simple Gorilla-style shooter for two players.
|
9
|
+
# Shows how Gosu and RMagick can be used together to generate a map, implement
|
10
|
+
# a dynamic landscape and generally look great.
|
11
|
+
# Also shows a very minimal, yet effective way of designing a game's object system.
|
12
|
+
|
13
|
+
# Doesn't make use of Gosu's Z-ordering. Not many different things to draw, it's
|
14
|
+
# easy to get the order right without it.
|
15
|
+
|
16
|
+
# Known issues:
|
17
|
+
# * Collision detection of the missiles is lazy, allows shooting through thin walls.
|
18
|
+
# * The look of dead soldiers is, err, by accident. Soldier.png needs to be
|
19
|
+
# designed in a less obfuscated way :)
|
20
|
+
|
21
|
+
require 'gosu'
|
22
|
+
require 'rmagick'
|
23
|
+
|
24
|
+
NULL_PIXEL = Magick::Pixel.from_color('none')
|
25
|
+
|
26
|
+
# The class for this game's map.
|
27
|
+
# Design:
|
28
|
+
# * Dynamic map creation at startup, holding it as RMagick Image in @image
|
29
|
+
# * Testing for solidity by testing @image's pixel values
|
30
|
+
# * Drawing by (re)creating an array of Gosu::Image instances, each representing
|
31
|
+
# a part of the large @image
|
32
|
+
# * Blasting holes into the map is implemented by drawing and erasing portions
|
33
|
+
# of @image, then setting the corresponding Gosu::Image instances to nil, so
|
34
|
+
# they will be recreated in Map#draw
|
35
|
+
# Note: The splitting is done because recreating such a large Gosu::Image for
|
36
|
+
# every map change would be a very noticeable delay!
|
37
|
+
|
38
|
+
class Map
|
39
|
+
WIDTH, HEIGHT = 800, 600
|
40
|
+
TILE_SIZE = 100
|
41
|
+
TILES_X = WIDTH / TILE_SIZE
|
42
|
+
TILES_Y = HEIGHT / TILE_SIZE
|
43
|
+
|
44
|
+
def initialize(window)
|
45
|
+
# We'll need the window later for re-creating Gosu images.
|
46
|
+
@window = window
|
47
|
+
|
48
|
+
# Let's start with something simple and load the sky via RMagick.
|
49
|
+
# Loading JPEG files isn't possible with Gosu, so say wow!
|
50
|
+
sky = Magick::Image.read("media/Sky.jpg").first
|
51
|
+
@sky = Gosu::Image.new(window, sky, true)
|
52
|
+
|
53
|
+
# This is the one large RMagick image that represents the map.
|
54
|
+
@image = Magick::Image.new(WIDTH, HEIGHT) { self.background_color = 'none' }
|
55
|
+
|
56
|
+
# Set up a Draw object that fills with an earth texture.
|
57
|
+
earth = Magick::Image.read('media/Earth.png').first.resize(1.5)
|
58
|
+
gc = Magick::Draw.new
|
59
|
+
gc.pattern('earth', 0, 0, earth.columns, earth.rows) { gc.composite(0, 0, 0, 0, earth) }
|
60
|
+
gc.fill('earth')
|
61
|
+
gc.stroke('#603000').stroke_width(1.5)
|
62
|
+
# Draw a smooth bezier island onto the map!
|
63
|
+
polypoints = [0, HEIGHT]
|
64
|
+
0.upto(TILES_X) do |x|
|
65
|
+
polypoints += [x * TILE_SIZE, HEIGHT * 0.2 + rand(HEIGHT * 0.8)]
|
66
|
+
end
|
67
|
+
polypoints += [WIDTH, HEIGHT]
|
68
|
+
gc.bezier(*polypoints)
|
69
|
+
gc.draw(@image)
|
70
|
+
|
71
|
+
# Create a bright-dark gradient fill, an image from it and change the map's
|
72
|
+
# brightness with it.
|
73
|
+
fill = Magick::GradientFill.new(0, HEIGHT * 0.4, WIDTH, HEIGHT * 0.4, '#fff', '#666')
|
74
|
+
gradient = Magick::Image.new(WIDTH, HEIGHT, fill)
|
75
|
+
gradient = @image.composite(gradient, 0, 0, Magick::InCompositeOp)
|
76
|
+
@image.composite!(gradient, 0, 0, Magick::MultiplyCompositeOp)
|
77
|
+
|
78
|
+
# Finally, place the star in the middle of the map, just onto the ground.
|
79
|
+
star = Magick::Image.read('media/LargeStar.png').first
|
80
|
+
star_y = 0
|
81
|
+
star_y += 20 until solid?(WIDTH / 2, star_y)
|
82
|
+
@image.composite!(star, (WIDTH - star.columns) / 2, star_y - star.rows * 0.85,
|
83
|
+
Magick::DstOverCompositeOp)
|
84
|
+
|
85
|
+
# Creates an X*Y array for the Gosu images.
|
86
|
+
# (Initialized to nil automatically).
|
87
|
+
@gosu_images = Array.new(TILES_X) { Array.new(TILES_Y) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def solid?(x, y)
|
91
|
+
# Map is open at the top.
|
92
|
+
return false if y < 0
|
93
|
+
# Map is closed on all other sides.
|
94
|
+
return true if x < 0 or x >= 800 or y >= 600
|
95
|
+
# Inside of the map, determine solidity from the map image.
|
96
|
+
@image.pixel_color(x, y) != NULL_PIXEL
|
97
|
+
end
|
98
|
+
|
99
|
+
def draw
|
100
|
+
# Sky background.
|
101
|
+
@sky.draw(0, 0, 0)
|
102
|
+
# All the tiles.
|
103
|
+
TILES_Y.times do |y|
|
104
|
+
TILES_X.times do |x|
|
105
|
+
# Recreate images that haven't been created yet, or need to be recreated
|
106
|
+
# due to map changes.
|
107
|
+
if @gosu_images[x][y].nil? then
|
108
|
+
part = @image.crop(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE)
|
109
|
+
@gosu_images[x][y] = Gosu::Image.new(@window, part, true)
|
110
|
+
end
|
111
|
+
# At last - draw it!
|
112
|
+
@gosu_images[x][y].draw(x * TILE_SIZE, y * TILE_SIZE, 0)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Radius of a crater.
|
118
|
+
RADIUS = 25
|
119
|
+
# Radius of a crater, SHadow included.
|
120
|
+
SH_RADIUS = 45
|
121
|
+
|
122
|
+
def blast(x, y)
|
123
|
+
# This code assumes at most 2x2 tiles are affected by a blast, so
|
124
|
+
# don't change the RADIUS to 200 or something ;)
|
125
|
+
# Calculate the x/y indices of the two to four affected tiles.
|
126
|
+
# (left/right and top/bottom might be the same).
|
127
|
+
|
128
|
+
left = (x - SH_RADIUS) / TILE_SIZE
|
129
|
+
right = (x + SH_RADIUS) / TILE_SIZE
|
130
|
+
top = (y - SH_RADIUS) / TILE_SIZE
|
131
|
+
bottom = (y + SH_RADIUS) / TILE_SIZE
|
132
|
+
|
133
|
+
# Set affected images to nil. (A 'double-free' doesn't hurt!)
|
134
|
+
|
135
|
+
@gosu_images[left][top] = nil
|
136
|
+
@gosu_images[right][top] = nil
|
137
|
+
@gosu_images[left][bottom] = nil
|
138
|
+
@gosu_images[right][bottom] = nil
|
139
|
+
|
140
|
+
# Create the crater image (basically a circle shape that is used to erase
|
141
|
+
# parts of the map) and the crater shadow image, if they don't exist
|
142
|
+
# already.
|
143
|
+
|
144
|
+
if @crater_image.nil? then
|
145
|
+
@crater_image = Magick::Image.new(2 * RADIUS, 2 * RADIUS) { self.background_color = 'none' }
|
146
|
+
gc = Magick::Draw.new
|
147
|
+
gc.fill('black').circle(RADIUS, RADIUS, RADIUS, 0)
|
148
|
+
gc.draw(@crater_image)
|
149
|
+
@crater_shadow = @crater_image.shadow(0, 0, (SH_RADIUS - RADIUS) / 2, 1)
|
150
|
+
end
|
151
|
+
|
152
|
+
# Draw the shadow (twice for more intensity), then erase a circle from the map.
|
153
|
+
@image.composite!(@crater_shadow, x - SH_RADIUS, y - SH_RADIUS, Magick::AtopCompositeOp)
|
154
|
+
@image.composite!(@crater_shadow, x - SH_RADIUS, y - SH_RADIUS, Magick::AtopCompositeOp)
|
155
|
+
@image.composite!(@crater_image, x - RADIUS, y - RADIUS, Magick::DstOutCompositeOp)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Player class.
|
160
|
+
# Note that applies to the whole game:
|
161
|
+
# All objects implement an informal interface.
|
162
|
+
# draw: Draws the object (obviously)
|
163
|
+
# update: Moves the object etc., returns false if the object is to be deleted
|
164
|
+
# hit_by?(missile): Returns true if an object is hit by the missile, causing
|
165
|
+
# it to explode on this object.
|
166
|
+
|
167
|
+
class Player
|
168
|
+
# Magic numbers considered harmful! This is the height of the
|
169
|
+
# player as used for collision detection.
|
170
|
+
HEIGHT = 14
|
171
|
+
|
172
|
+
attr_reader :x, :y, :dead
|
173
|
+
|
174
|
+
def initialize(window, x, y, color)
|
175
|
+
# Only load the images once for all instances of this class.
|
176
|
+
@@images ||= Gosu::Image.load_tiles(window, "media/Soldier.png", 40, 50, false)
|
177
|
+
|
178
|
+
@window, @x, @y, @color = window, x, y, color
|
179
|
+
@vy = 0
|
180
|
+
|
181
|
+
# -1: left, +1: right
|
182
|
+
@dir = -1
|
183
|
+
|
184
|
+
# Aiming angle.
|
185
|
+
@angle = 90
|
186
|
+
end
|
187
|
+
|
188
|
+
def draw
|
189
|
+
if dead then
|
190
|
+
# Poor, broken soldier.
|
191
|
+
@@images[0].draw_rot(x, y, 0, 290 * @dir, 0.5, 0.65, @dir * 0.5, 0.5, @color)
|
192
|
+
@@images[2].draw_rot(x, y, 0, 160 * @dir, 0.95, 0.5, 0.5, @dir * 0.5, @color)
|
193
|
+
else
|
194
|
+
# Was moved last frame?
|
195
|
+
if @show_walk_anim
|
196
|
+
# Yes: Display walking animation.
|
197
|
+
frame = Gosu::milliseconds / 200 % 2
|
198
|
+
else
|
199
|
+
# No: Stand around (boring).
|
200
|
+
frame = 0
|
201
|
+
end
|
202
|
+
|
203
|
+
# Draw feet, then chest.
|
204
|
+
@@images[frame].draw(x - 10 * @dir, y - 20, 0, @dir * 0.5, 0.5, @color)
|
205
|
+
angle = @angle
|
206
|
+
angle = 180 - angle if @dir == -1
|
207
|
+
@@images[2].draw_rot(x, y - 5, 0, angle, 1, 0.5, 0.5, @dir * 0.5, @color)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def update
|
212
|
+
# First, assume that no walking happened this frame.
|
213
|
+
@show_walk_anim = false
|
214
|
+
|
215
|
+
# Gravity.
|
216
|
+
@vy += 1
|
217
|
+
|
218
|
+
if @vy > 1 then
|
219
|
+
# Move upwards until hitting something.
|
220
|
+
@vy.times do
|
221
|
+
if @window.map.solid?(x, y + 1)
|
222
|
+
@vy = 0
|
223
|
+
break
|
224
|
+
else
|
225
|
+
@y += 1
|
226
|
+
end
|
227
|
+
end
|
228
|
+
else
|
229
|
+
# Move downwards until hitting something.
|
230
|
+
(-@vy).times do
|
231
|
+
if @window.map.solid?(x, y - HEIGHT - 1)
|
232
|
+
@vy = 0
|
233
|
+
break
|
234
|
+
else
|
235
|
+
@y -= 1
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# Soldiers are never deleted (they may die, though, but that is a different
|
241
|
+
# concept).
|
242
|
+
true
|
243
|
+
end
|
244
|
+
|
245
|
+
def aim_up
|
246
|
+
@angle -= 2 unless @angle < 10
|
247
|
+
end
|
248
|
+
|
249
|
+
def aim_down
|
250
|
+
@angle += 2 unless @angle > 170
|
251
|
+
end
|
252
|
+
|
253
|
+
def try_walk(dir)
|
254
|
+
@show_walk_anim = true
|
255
|
+
@dir = dir
|
256
|
+
# First, magically move up (so soldiers can run up hills)
|
257
|
+
2.times { @y -= 1 unless @window.map.solid?(x, y - HEIGHT - 1) }
|
258
|
+
# Now move into the desired direction.
|
259
|
+
@x += dir unless @window.map.solid?(x + dir, y) or
|
260
|
+
@window.map.solid?(x + dir, y - HEIGHT)
|
261
|
+
# To make up for unnecessary movement upwards, sink downward again.
|
262
|
+
2.times { @y += 1 unless @window.map.solid?(x, y + 1) }
|
263
|
+
end
|
264
|
+
|
265
|
+
def try_jump
|
266
|
+
@vy = -12 if @window.map.solid?(x, y + 1)
|
267
|
+
end
|
268
|
+
|
269
|
+
def shoot
|
270
|
+
@window.objects << Missile.new(@window, x + 10 * @dir, y - 10, @angle * @dir)
|
271
|
+
end
|
272
|
+
|
273
|
+
def hit_by?(missile)
|
274
|
+
if Gosu::distance(missile.x, missile.y, x, y) < 30 then
|
275
|
+
# Was hit :(
|
276
|
+
@dead = true
|
277
|
+
return true
|
278
|
+
else
|
279
|
+
return false
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
# Implements the same interface as Player, except it'S a missile!
|
285
|
+
|
286
|
+
class Missile
|
287
|
+
attr_reader :x, :y, :vx, :vy
|
288
|
+
|
289
|
+
def initialize(window, x, y, angle)
|
290
|
+
# All missile instances use the same sound.
|
291
|
+
@@explosion_sound ||= Gosu::Sample.new(window, "media/Explosion.wav")
|
292
|
+
|
293
|
+
# Horizontal/vertical velocity.
|
294
|
+
@vx, @vy = Gosu::offset_x(angle, 20).to_i, Gosu::offset_y(angle, 20).to_i
|
295
|
+
|
296
|
+
@window, @x, @y = window, x + @vx, y + @vy
|
297
|
+
end
|
298
|
+
|
299
|
+
def update
|
300
|
+
# Movement, gravity
|
301
|
+
@x += @vx
|
302
|
+
@y += @vy
|
303
|
+
@vy += 1
|
304
|
+
# Hit anything?
|
305
|
+
if @window.map.solid?(x, y) or @window.objects.any? { |o| o.hit_by?(self) } then
|
306
|
+
# Create great particles.
|
307
|
+
5.times { @window.objects << Particle.new(@window, x - 25 + rand(51), y - 25 + rand(51)) }
|
308
|
+
@window.map.blast(x, y)
|
309
|
+
# Weeee, stereo sound!
|
310
|
+
@@explosion_sound.play_pan((2 * @x - Map::WIDTH) / Map::WIDTH)
|
311
|
+
return false
|
312
|
+
else
|
313
|
+
return true
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def draw
|
318
|
+
# Just draw a small quad.
|
319
|
+
@window.draw_quad(x-2, y-2, 0xff800000, x+2, y-2, 0xff800000,
|
320
|
+
x-2, y+2, 0xff800000, x+2, y+2, 0xff800000, 0)
|
321
|
+
end
|
322
|
+
|
323
|
+
def hit_by?(missile)
|
324
|
+
# Missiles can't be hit by other missiles!
|
325
|
+
false
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
# Very minimal object that just draws a fading particle.
|
330
|
+
|
331
|
+
class Particle
|
332
|
+
def initialize(window, x, y)
|
333
|
+
# All Particle instances use the same image
|
334
|
+
@@image ||= Gosu::Image.new(window, 'media/Smoke.png', false)
|
335
|
+
|
336
|
+
@x, @y = x, y
|
337
|
+
@color = Gosu::Color.new(255, 255, 255, 255)
|
338
|
+
end
|
339
|
+
|
340
|
+
def update
|
341
|
+
@y -= 5
|
342
|
+
@x = @x - 1 + rand(3)
|
343
|
+
@color.alpha -= 5
|
344
|
+
|
345
|
+
# Remove if faded completely.
|
346
|
+
@color.alpha > 0
|
347
|
+
end
|
348
|
+
|
349
|
+
def draw
|
350
|
+
@@image.draw(@x - 25, @y - 25, 0, 1, 1, @color)
|
351
|
+
end
|
352
|
+
|
353
|
+
def hit_by?(missile)
|
354
|
+
# Smoke can't be hit!
|
355
|
+
false
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
# Finally, the class that ties it all together.
|
360
|
+
# Very straightforward implementation.
|
361
|
+
|
362
|
+
class GameWindow < Gosu::Window
|
363
|
+
attr_reader :map, :objects
|
364
|
+
|
365
|
+
def initialize()
|
366
|
+
super(800, 600, false)
|
367
|
+
self.caption = "Medal of Anna - Gosu & RMagick integration demo"
|
368
|
+
|
369
|
+
# Texts to display in the appropriate situations.
|
370
|
+
@player_instructions = []
|
371
|
+
@player_won_messages = []
|
372
|
+
2.times do |plr|
|
373
|
+
@player_instructions << Gosu::Image.from_text(self,
|
374
|
+
"It is the #{ plr == 0 ? 'green' : 'red' } toy soldier's turn.\n" +
|
375
|
+
"(Arrow keys to walk and aim, Return to jump, Space to shoot)",
|
376
|
+
Gosu::default_font_name, 25, 0, width, :center)
|
377
|
+
@player_won_messages << Gosu::Image.from_text(self,
|
378
|
+
"The #{ plr == 0 ? 'green' : 'red' } toy soldier has won!",
|
379
|
+
Gosu::default_font_name, 25, 5, width, :center)
|
380
|
+
end
|
381
|
+
|
382
|
+
# Create everything!
|
383
|
+
@map = Map.new(self)
|
384
|
+
@players = [Player.new(self, 200, 40, 0xff308000), Player.new(self, 600, 40, 0xff803000)]
|
385
|
+
@objects = @players.dup
|
386
|
+
|
387
|
+
# Let any player start.
|
388
|
+
@current_player = rand(2)
|
389
|
+
# Currently not waiting for a missile to hit something.
|
390
|
+
@waiting = false
|
391
|
+
end
|
392
|
+
|
393
|
+
def draw
|
394
|
+
# Draw the main game.
|
395
|
+
@map.draw
|
396
|
+
@objects.each { |o| o.draw }
|
397
|
+
|
398
|
+
# If any text should be displayed, draw it - and add a nice black border around it
|
399
|
+
# by drawing it four times, with a little offset in each direction.
|
400
|
+
|
401
|
+
cur_text = @player_instructions[@current_player] if not @waiting
|
402
|
+
cur_text = @player_won_messages[1 - @current_player] if @players[@current_player].dead
|
403
|
+
|
404
|
+
if cur_text then
|
405
|
+
x, y = 0, 30
|
406
|
+
cur_text.draw(x - 1, y, 0, 1, 1, 0xff000000)
|
407
|
+
cur_text.draw(x + 1, y, 0, 1, 1, 0xff000000)
|
408
|
+
cur_text.draw(x, y - 1, 0, 1, 1, 0xff000000)
|
409
|
+
cur_text.draw(x, y + 1, 0, 1, 1, 0xff000000)
|
410
|
+
cur_text.draw(x, y, 0, 1, 1, 0xffffffff)
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def update
|
415
|
+
# if waiting for the next player's turn, continue to do so until the missile has
|
416
|
+
# hit something.
|
417
|
+
@waiting &&= !@objects.grep(Missile).empty?
|
418
|
+
|
419
|
+
# Remove all objects whose update method returns false.
|
420
|
+
@objects.reject! { |o| o.update == false }
|
421
|
+
|
422
|
+
# If it's a player's turn, forward controls.
|
423
|
+
if not @waiting and not @players[@current_player].dead then
|
424
|
+
player = @players[@current_player]
|
425
|
+
player.aim_up if button_down? Gosu::KbUp
|
426
|
+
player.aim_down if button_down? Gosu::KbDown
|
427
|
+
player.try_walk(-1) if button_down? Gosu::KbLeft
|
428
|
+
player.try_walk(1) if button_down? Gosu::KbRight
|
429
|
+
player.try_jump if button_down? Gosu::KbReturn
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
def button_down(id)
|
434
|
+
if id == Gosu::KbSpace and not @waiting and not @players[@current_player].dead then
|
435
|
+
# Shoot! This is handled in button_down because holding space shouldn't
|
436
|
+
# auto-fire - the shots would come from different players.
|
437
|
+
@players[@current_player].shoot
|
438
|
+
@current_player = 1 - @current_player
|
439
|
+
@waiting = true
|
440
|
+
end
|
441
|
+
# Very important feature! ;)
|
442
|
+
close if id == Gosu::KbEscape
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
# So far we have only defined how everything *should* work - now set it up and run it!
|
447
|
+
GameWindow.new.show
|
data/examples/Tutorial.rb
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/examples/media/Space.png
CHANGED
Binary file
|
Binary file
|
data/lib/gosu.so
CHANGED
Binary file
|
metadata
CHANGED
@@ -3,54 +3,66 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: gosu
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.
|
7
|
-
date: 2007-09-
|
6
|
+
version: 0.7.6
|
7
|
+
date: 2007-09-29 00:00:00 +02:00
|
8
8
|
summary: 2D game development library.
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: julian@raschke.de
|
12
12
|
homepage: http://code.google.com/p/gosu/
|
13
13
|
rubyforge_project:
|
14
|
-
description:
|
15
|
-
interfaces to 2D graphics and text (accelerated by 3D hardware), sound samples
|
16
|
-
and music as well as keyboard, mouse and gamepad/joystick input."
|
14
|
+
description: 2D game development library. The library features easy to use and game-friendly interfaces to 2D graphics and text (accelerated by 3D hardware), sound samples and music as well as keyboard, mouse and gamepad/joystick input. Integrates with RMagick.
|
17
15
|
autorequire:
|
18
16
|
default_executable:
|
19
17
|
bindir: bin
|
20
18
|
has_rdoc: false
|
21
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
22
20
|
requirements:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
version: 1.8.1
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.1
|
27
24
|
version:
|
28
25
|
platform: mswin32
|
29
26
|
signing_key:
|
30
27
|
cert_chain:
|
31
28
|
post_install_message:
|
32
29
|
authors:
|
33
|
-
|
34
|
-
|
30
|
+
- Julian Raschke
|
31
|
+
- Jan Luecker
|
35
32
|
files:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
33
|
+
- examples/media/Beep.wav
|
34
|
+
- examples/media/CptnRuby Gem.png
|
35
|
+
- examples/media/CptnRuby Map.txt
|
36
|
+
- examples/media/CptnRuby Tileset.bmp
|
37
|
+
- examples/media/CptnRuby Tileset.png
|
38
|
+
- examples/media/CptnRuby.png
|
39
|
+
- examples/media/Earth.png
|
40
|
+
- examples/media/Explosion.wav
|
41
|
+
- examples/media/LargeStar.png
|
42
|
+
- examples/media/Sky.jpg
|
43
|
+
- examples/media/Smoke.png
|
44
|
+
- examples/media/Soldier.png
|
45
|
+
- examples/media/Space.png
|
46
|
+
- examples/media/Star.png
|
47
|
+
- examples/media/Starfighter.bmp
|
48
|
+
- examples/Tutorial.rb
|
49
|
+
- examples/CptnRuby.rb
|
50
|
+
- examples/RMagickIntegration.rb
|
51
|
+
- lib/gosu.so
|
52
|
+
- lib/fmod.dll
|
53
|
+
- README
|
54
|
+
- LICENSE
|
50
55
|
test_files: []
|
56
|
+
|
51
57
|
rdoc_options: []
|
58
|
+
|
52
59
|
extra_rdoc_files: []
|
60
|
+
|
53
61
|
executables: []
|
62
|
+
|
54
63
|
extensions: []
|
64
|
+
|
55
65
|
requirements: []
|
56
|
-
|
66
|
+
|
67
|
+
dependencies: []
|
68
|
+
|