gosu 0.8.6-x86-mingw32 → 0.8.7-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gosu/Audio.hpp +171 -171
- data/Gosu/Bitmap.hpp +96 -96
- data/Gosu/Color.hpp +204 -204
- data/Gosu/Directories.hpp +36 -36
- data/Gosu/Font.hpp +83 -83
- data/Gosu/Gosu.hpp +34 -34
- data/Gosu/Graphics.hpp +115 -115
- data/Gosu/GraphicsBase.hpp +110 -110
- data/Gosu/IO.hpp +269 -269
- data/Gosu/Image.hpp +122 -122
- data/Gosu/ImageData.hpp +61 -61
- data/Gosu/Input.hpp +149 -149
- data/Gosu/Inspection.hpp +14 -14
- data/Gosu/Math.hpp +135 -135
- data/Gosu/Platform.hpp +93 -93
- data/Gosu/Sockets.hpp +156 -156
- data/Gosu/TR1.hpp +56 -56
- data/Gosu/Text.hpp +71 -71
- data/Gosu/TextInput.hpp +70 -70
- data/Gosu/Utility.hpp +28 -28
- data/Gosu/Version.hpp +19 -19
- data/Gosu/Window.hpp +145 -145
- data/examples/ChipmunkIntegration.rb +275 -275
- data/examples/CptnRuby.rb +223 -223
- data/examples/GosuZen.rb +68 -68
- data/examples/MoreChipmunkAndRMagick.rb +155 -155
- data/examples/OpenGLIntegration.rb +225 -225
- data/examples/RMagickIntegration.rb +417 -417
- data/examples/TextInput.rb +154 -154
- data/examples/Tutorial.rb +130 -130
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Map.txt b/data/examples/media/CptnRuby → Map.txt +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/Landscape.svg +9 -9
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/lib/1.8/gosu.so +0 -0
- data/lib/1.9/gosu.so +0 -0
- data/lib/2.0/gosu.so +0 -0
- data/lib/2.1/gosu.so +0 -0
- data/lib/FreeImage.dll +0 -0
- data/lib/OpenAL32.dll +0 -0
- data/lib/gosu.rb +19 -16
- data/lib/gosu/patches.rb +81 -81
- data/lib/gosu/preview.rb +143 -139
- data/lib/gosu/run.rb +11 -11
- data/lib/gosu/swig_patches.rb +60 -60
- data/lib/gosu/zen.rb +89 -89
- metadata +5 -5
data/examples/CptnRuby.rb
CHANGED
@@ -1,223 +1,223 @@
|
|
1
|
-
# Basically, the tutorial game taken to a jump'n'run perspective.
|
2
|
-
|
3
|
-
# Shows how to
|
4
|
-
# * implement jumping/gravity
|
5
|
-
# * implement scrolling using Window#translate
|
6
|
-
# * implement a simple tile-based map
|
7
|
-
# * load levels from primitive text files
|
8
|
-
|
9
|
-
# Some exercises, starting at the real basics:
|
10
|
-
# 0) understand the existing code!
|
11
|
-
# As shown in the tutorial:
|
12
|
-
# 1) change it use Gosu's Z-ordering
|
13
|
-
# 2) add gamepad support
|
14
|
-
# 3) add a score as in the tutorial game
|
15
|
-
# 4) similarly, add sound effects for various events
|
16
|
-
# Exploring this game's code and Gosu:
|
17
|
-
# 5) make the player wider, so he doesn't fall off edges as easily
|
18
|
-
# 6) add background music (check if playing in Window#update to implement
|
19
|
-
# looping)
|
20
|
-
# 7) implement parallax scrolling for the star background!
|
21
|
-
# Getting tricky:
|
22
|
-
# 8) optimize Map#draw so only tiles on screen are drawn (needs modulo, a pen
|
23
|
-
# and paper to figure out)
|
24
|
-
# 9) add loading of next level when all gems are collected
|
25
|
-
# ...Enemies, a more sophisticated object system, weapons, title and credits
|
26
|
-
# screens...
|
27
|
-
|
28
|
-
require 'rubygems'
|
29
|
-
require 'gosu'
|
30
|
-
include Gosu
|
31
|
-
|
32
|
-
module Tiles
|
33
|
-
Grass = 0
|
34
|
-
Earth = 1
|
35
|
-
end
|
36
|
-
|
37
|
-
class CollectibleGem
|
38
|
-
attr_reader :x, :y
|
39
|
-
|
40
|
-
def initialize(image, x, y)
|
41
|
-
@image = image
|
42
|
-
@x, @y = x, y
|
43
|
-
end
|
44
|
-
|
45
|
-
def draw
|
46
|
-
# Draw, slowly rotating
|
47
|
-
@image.draw_rot(@x, @y, 0, 25 * Math.sin(milliseconds / 133.7))
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Player class.
|
52
|
-
class CptnRuby
|
53
|
-
attr_reader :x, :y
|
54
|
-
|
55
|
-
def initialize(window, x, y)
|
56
|
-
@x, @y = x, y
|
57
|
-
@dir = :left
|
58
|
-
@vy = 0 # Vertical velocity
|
59
|
-
@map = window.map
|
60
|
-
# Load all animation frames
|
61
|
-
@standing, @walk1, @walk2, @jump =
|
62
|
-
*Image.load_tiles(window, "media/CptnRuby.png", 50, 50, false)
|
63
|
-
# This always points to the frame that is currently drawn.
|
64
|
-
# This is set in update, and used in draw.
|
65
|
-
@cur_image = @standing
|
66
|
-
end
|
67
|
-
|
68
|
-
def draw
|
69
|
-
# Flip vertically when facing to the left.
|
70
|
-
if @dir == :left then
|
71
|
-
offs_x = -25
|
72
|
-
factor = 1.0
|
73
|
-
else
|
74
|
-
offs_x = 25
|
75
|
-
factor = -1.0
|
76
|
-
end
|
77
|
-
@cur_image.draw(@x + offs_x, @y - 49, 0, factor, 1.0)
|
78
|
-
end
|
79
|
-
|
80
|
-
# Could the object be placed at x + offs_x/y + offs_y without being stuck?
|
81
|
-
def would_fit(offs_x, offs_y)
|
82
|
-
# Check at the center/top and center/bottom for map collisions
|
83
|
-
not @map.solid?(@x + offs_x, @y + offs_y) and
|
84
|
-
not @map.solid?(@x + offs_x, @y + offs_y - 45)
|
85
|
-
end
|
86
|
-
|
87
|
-
def update(move_x)
|
88
|
-
# Select image depending on action
|
89
|
-
if (move_x == 0)
|
90
|
-
@cur_image = @standing
|
91
|
-
else
|
92
|
-
@cur_image = (milliseconds / 175 % 2 == 0) ? @walk1 : @walk2
|
93
|
-
end
|
94
|
-
if (@vy < 0)
|
95
|
-
@cur_image = @jump
|
96
|
-
end
|
97
|
-
|
98
|
-
# Directional walking, horizontal movement
|
99
|
-
if move_x > 0 then
|
100
|
-
@dir = :right
|
101
|
-
move_x.times { if would_fit(1, 0) then @x += 1 end }
|
102
|
-
end
|
103
|
-
if move_x < 0 then
|
104
|
-
@dir = :left
|
105
|
-
(-move_x).times { if would_fit(-1, 0) then @x -= 1 end }
|
106
|
-
end
|
107
|
-
|
108
|
-
# Acceleration/gravity
|
109
|
-
# By adding 1 each frame, and (ideally) adding vy to y, the player's
|
110
|
-
# jumping curve will be the parabole we want it to be.
|
111
|
-
@vy += 1
|
112
|
-
# Vertical movement
|
113
|
-
if @vy > 0 then
|
114
|
-
@vy.times { if would_fit(0, 1) then @y += 1 else @vy = 0 end }
|
115
|
-
end
|
116
|
-
if @vy < 0 then
|
117
|
-
(-@vy).times { if would_fit(0, -1) then @y -= 1 else @vy = 0 end }
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def try_to_jump
|
122
|
-
if @map.solid?(@x, @y + 1) then
|
123
|
-
@vy = -20
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def collect_gems(gems)
|
128
|
-
# Same as in the tutorial game.
|
129
|
-
gems.reject! do |c|
|
130
|
-
(c.x - @x).abs < 50 and (c.y - @y).abs < 50
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# Map class holds and draws tiles and gems.
|
136
|
-
class Map
|
137
|
-
attr_reader :width, :height, :gems
|
138
|
-
|
139
|
-
def initialize(window, filename)
|
140
|
-
# Load 60x60 tiles, 5px overlap in all four directions.
|
141
|
-
@tileset = Image.load_tiles(window, "media/CptnRuby Tileset.png", 60, 60, true)
|
142
|
-
|
143
|
-
gem_img = Image.new(window, "media/CptnRuby Gem.png", false)
|
144
|
-
@gems = []
|
145
|
-
|
146
|
-
lines = File.readlines(filename).map { |line| line.chomp }
|
147
|
-
@height = lines.size
|
148
|
-
@width = lines[0].size
|
149
|
-
@tiles = Array.new(@width) do |x|
|
150
|
-
Array.new(@height) do |y|
|
151
|
-
case lines[y][x, 1]
|
152
|
-
when '"'
|
153
|
-
Tiles::Grass
|
154
|
-
when '#'
|
155
|
-
Tiles::Earth
|
156
|
-
when 'x'
|
157
|
-
@gems.push(CollectibleGem.new(gem_img, x * 50 + 25, y * 50 + 25))
|
158
|
-
nil
|
159
|
-
else
|
160
|
-
nil
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def draw
|
167
|
-
# Very primitive drawing function:
|
168
|
-
# Draws all the tiles, some off-screen, some on-screen.
|
169
|
-
@height.times do |y|
|
170
|
-
@width.times do |x|
|
171
|
-
tile = @tiles[x][y]
|
172
|
-
if tile
|
173
|
-
# Draw the tile with an offset (tile images have some overlap)
|
174
|
-
# Scrolling is implemented here just as in the game objects.
|
175
|
-
@tileset[tile].draw(x * 50 - 5, y * 50 - 5, 0)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
@gems.each { |c| c.draw }
|
180
|
-
end
|
181
|
-
|
182
|
-
# Solid at a given pixel position?
|
183
|
-
def solid?(x, y)
|
184
|
-
y < 0 || @tiles[x / 50][y / 50]
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
class Game < Window
|
189
|
-
attr_reader :map
|
190
|
-
|
191
|
-
def initialize
|
192
|
-
super(640, 480, false)
|
193
|
-
self.caption = "Cptn. Ruby"
|
194
|
-
@sky = Image.new(self, "media/Space.png", true)
|
195
|
-
@map = Map.new(self, "media/CptnRuby Map.txt")
|
196
|
-
@cptn = CptnRuby.new(self, 400, 100)
|
197
|
-
# The scrolling position is stored as top left corner of the screen.
|
198
|
-
@camera_x = @camera_y = 0
|
199
|
-
end
|
200
|
-
def update
|
201
|
-
move_x = 0
|
202
|
-
move_x -= 5 if button_down? KbLeft
|
203
|
-
move_x += 5 if button_down? KbRight
|
204
|
-
@cptn.update(move_x)
|
205
|
-
@cptn.collect_gems(@map.gems)
|
206
|
-
# Scrolling follows player
|
207
|
-
@camera_x = [[@cptn.x - 320, 0].max, @map.width * 50 - 640].min
|
208
|
-
@camera_y = [[@cptn.y - 240, 0].max, @map.height * 50 - 480].min
|
209
|
-
end
|
210
|
-
def draw
|
211
|
-
@sky.draw 0, 0, 0
|
212
|
-
translate(-@camera_x, -@camera_y) do
|
213
|
-
@map.draw
|
214
|
-
@cptn.draw
|
215
|
-
end
|
216
|
-
end
|
217
|
-
def button_down(id)
|
218
|
-
if id == KbUp then @cptn.try_to_jump end
|
219
|
-
if id == KbEscape then close end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
Game.new.show
|
1
|
+
# Basically, the tutorial game taken to a jump'n'run perspective.
|
2
|
+
|
3
|
+
# Shows how to
|
4
|
+
# * implement jumping/gravity
|
5
|
+
# * implement scrolling using Window#translate
|
6
|
+
# * implement a simple tile-based map
|
7
|
+
# * load levels from primitive text files
|
8
|
+
|
9
|
+
# Some exercises, starting at the real basics:
|
10
|
+
# 0) understand the existing code!
|
11
|
+
# As shown in the tutorial:
|
12
|
+
# 1) change it use Gosu's Z-ordering
|
13
|
+
# 2) add gamepad support
|
14
|
+
# 3) add a score as in the tutorial game
|
15
|
+
# 4) similarly, add sound effects for various events
|
16
|
+
# Exploring this game's code and Gosu:
|
17
|
+
# 5) make the player wider, so he doesn't fall off edges as easily
|
18
|
+
# 6) add background music (check if playing in Window#update to implement
|
19
|
+
# looping)
|
20
|
+
# 7) implement parallax scrolling for the star background!
|
21
|
+
# Getting tricky:
|
22
|
+
# 8) optimize Map#draw so only tiles on screen are drawn (needs modulo, a pen
|
23
|
+
# and paper to figure out)
|
24
|
+
# 9) add loading of next level when all gems are collected
|
25
|
+
# ...Enemies, a more sophisticated object system, weapons, title and credits
|
26
|
+
# screens...
|
27
|
+
|
28
|
+
require 'rubygems'
|
29
|
+
require 'gosu'
|
30
|
+
include Gosu
|
31
|
+
|
32
|
+
module Tiles
|
33
|
+
Grass = 0
|
34
|
+
Earth = 1
|
35
|
+
end
|
36
|
+
|
37
|
+
class CollectibleGem
|
38
|
+
attr_reader :x, :y
|
39
|
+
|
40
|
+
def initialize(image, x, y)
|
41
|
+
@image = image
|
42
|
+
@x, @y = x, y
|
43
|
+
end
|
44
|
+
|
45
|
+
def draw
|
46
|
+
# Draw, slowly rotating
|
47
|
+
@image.draw_rot(@x, @y, 0, 25 * Math.sin(milliseconds / 133.7))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Player class.
|
52
|
+
class CptnRuby
|
53
|
+
attr_reader :x, :y
|
54
|
+
|
55
|
+
def initialize(window, x, y)
|
56
|
+
@x, @y = x, y
|
57
|
+
@dir = :left
|
58
|
+
@vy = 0 # Vertical velocity
|
59
|
+
@map = window.map
|
60
|
+
# Load all animation frames
|
61
|
+
@standing, @walk1, @walk2, @jump =
|
62
|
+
*Image.load_tiles(window, "media/CptnRuby.png", 50, 50, false)
|
63
|
+
# This always points to the frame that is currently drawn.
|
64
|
+
# This is set in update, and used in draw.
|
65
|
+
@cur_image = @standing
|
66
|
+
end
|
67
|
+
|
68
|
+
def draw
|
69
|
+
# Flip vertically when facing to the left.
|
70
|
+
if @dir == :left then
|
71
|
+
offs_x = -25
|
72
|
+
factor = 1.0
|
73
|
+
else
|
74
|
+
offs_x = 25
|
75
|
+
factor = -1.0
|
76
|
+
end
|
77
|
+
@cur_image.draw(@x + offs_x, @y - 49, 0, factor, 1.0)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Could the object be placed at x + offs_x/y + offs_y without being stuck?
|
81
|
+
def would_fit(offs_x, offs_y)
|
82
|
+
# Check at the center/top and center/bottom for map collisions
|
83
|
+
not @map.solid?(@x + offs_x, @y + offs_y) and
|
84
|
+
not @map.solid?(@x + offs_x, @y + offs_y - 45)
|
85
|
+
end
|
86
|
+
|
87
|
+
def update(move_x)
|
88
|
+
# Select image depending on action
|
89
|
+
if (move_x == 0)
|
90
|
+
@cur_image = @standing
|
91
|
+
else
|
92
|
+
@cur_image = (milliseconds / 175 % 2 == 0) ? @walk1 : @walk2
|
93
|
+
end
|
94
|
+
if (@vy < 0)
|
95
|
+
@cur_image = @jump
|
96
|
+
end
|
97
|
+
|
98
|
+
# Directional walking, horizontal movement
|
99
|
+
if move_x > 0 then
|
100
|
+
@dir = :right
|
101
|
+
move_x.times { if would_fit(1, 0) then @x += 1 end }
|
102
|
+
end
|
103
|
+
if move_x < 0 then
|
104
|
+
@dir = :left
|
105
|
+
(-move_x).times { if would_fit(-1, 0) then @x -= 1 end }
|
106
|
+
end
|
107
|
+
|
108
|
+
# Acceleration/gravity
|
109
|
+
# By adding 1 each frame, and (ideally) adding vy to y, the player's
|
110
|
+
# jumping curve will be the parabole we want it to be.
|
111
|
+
@vy += 1
|
112
|
+
# Vertical movement
|
113
|
+
if @vy > 0 then
|
114
|
+
@vy.times { if would_fit(0, 1) then @y += 1 else @vy = 0 end }
|
115
|
+
end
|
116
|
+
if @vy < 0 then
|
117
|
+
(-@vy).times { if would_fit(0, -1) then @y -= 1 else @vy = 0 end }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def try_to_jump
|
122
|
+
if @map.solid?(@x, @y + 1) then
|
123
|
+
@vy = -20
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def collect_gems(gems)
|
128
|
+
# Same as in the tutorial game.
|
129
|
+
gems.reject! do |c|
|
130
|
+
(c.x - @x).abs < 50 and (c.y - @y).abs < 50
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Map class holds and draws tiles and gems.
|
136
|
+
class Map
|
137
|
+
attr_reader :width, :height, :gems
|
138
|
+
|
139
|
+
def initialize(window, filename)
|
140
|
+
# Load 60x60 tiles, 5px overlap in all four directions.
|
141
|
+
@tileset = Image.load_tiles(window, "media/CptnRuby Tileset.png", 60, 60, true)
|
142
|
+
|
143
|
+
gem_img = Image.new(window, "media/CptnRuby Gem.png", false)
|
144
|
+
@gems = []
|
145
|
+
|
146
|
+
lines = File.readlines(filename).map { |line| line.chomp }
|
147
|
+
@height = lines.size
|
148
|
+
@width = lines[0].size
|
149
|
+
@tiles = Array.new(@width) do |x|
|
150
|
+
Array.new(@height) do |y|
|
151
|
+
case lines[y][x, 1]
|
152
|
+
when '"'
|
153
|
+
Tiles::Grass
|
154
|
+
when '#'
|
155
|
+
Tiles::Earth
|
156
|
+
when 'x'
|
157
|
+
@gems.push(CollectibleGem.new(gem_img, x * 50 + 25, y * 50 + 25))
|
158
|
+
nil
|
159
|
+
else
|
160
|
+
nil
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def draw
|
167
|
+
# Very primitive drawing function:
|
168
|
+
# Draws all the tiles, some off-screen, some on-screen.
|
169
|
+
@height.times do |y|
|
170
|
+
@width.times do |x|
|
171
|
+
tile = @tiles[x][y]
|
172
|
+
if tile
|
173
|
+
# Draw the tile with an offset (tile images have some overlap)
|
174
|
+
# Scrolling is implemented here just as in the game objects.
|
175
|
+
@tileset[tile].draw(x * 50 - 5, y * 50 - 5, 0)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
@gems.each { |c| c.draw }
|
180
|
+
end
|
181
|
+
|
182
|
+
# Solid at a given pixel position?
|
183
|
+
def solid?(x, y)
|
184
|
+
y < 0 || @tiles[x / 50][y / 50]
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
class Game < Window
|
189
|
+
attr_reader :map
|
190
|
+
|
191
|
+
def initialize
|
192
|
+
super(640, 480, false)
|
193
|
+
self.caption = "Cptn. Ruby"
|
194
|
+
@sky = Image.new(self, "media/Space.png", true)
|
195
|
+
@map = Map.new(self, "media/CptnRuby Map.txt")
|
196
|
+
@cptn = CptnRuby.new(self, 400, 100)
|
197
|
+
# The scrolling position is stored as top left corner of the screen.
|
198
|
+
@camera_x = @camera_y = 0
|
199
|
+
end
|
200
|
+
def update
|
201
|
+
move_x = 0
|
202
|
+
move_x -= 5 if button_down? KbLeft
|
203
|
+
move_x += 5 if button_down? KbRight
|
204
|
+
@cptn.update(move_x)
|
205
|
+
@cptn.collect_gems(@map.gems)
|
206
|
+
# Scrolling follows player
|
207
|
+
@camera_x = [[@cptn.x - 320, 0].max, @map.width * 50 - 640].min
|
208
|
+
@camera_y = [[@cptn.y - 240, 0].max, @map.height * 50 - 480].min
|
209
|
+
end
|
210
|
+
def draw
|
211
|
+
@sky.draw 0, 0, 0
|
212
|
+
translate(-@camera_x, -@camera_y) do
|
213
|
+
@map.draw
|
214
|
+
@cptn.draw
|
215
|
+
end
|
216
|
+
end
|
217
|
+
def button_down(id)
|
218
|
+
if id == KbUp then @cptn.try_to_jump end
|
219
|
+
if id == KbEscape then close end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
Game.new.show
|
data/examples/GosuZen.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
# Gosu Zen example based on erisdiscord's comment here:
|
2
|
-
# https://github.com/jlnr/gosu/pull/120
|
3
|
-
|
4
|
-
# Gosu Zen is the (inline) Sinatra of Ruby multimedia programming.
|
5
|
-
# The interface is still in flux. If you want to tune the interface
|
6
|
-
# a little further or provide more examples, please fork Gosu and
|
7
|
-
# send a pull request. Thanks!
|
8
|
-
|
9
|
-
require 'rubygems'
|
10
|
-
require 'gosu/zen'
|
11
|
-
include Gosu::Zen
|
12
|
-
|
13
|
-
window 480, 240, :fullscreen => false
|
14
|
-
|
15
|
-
button_down Gosu::KbEscape do
|
16
|
-
close
|
17
|
-
end
|
18
|
-
|
19
|
-
update do
|
20
|
-
t = Gosu.milliseconds / 1000.0
|
21
|
-
|
22
|
-
@radius = [width, height].min * 0.37
|
23
|
-
@angle = t * Math::PI
|
24
|
-
|
25
|
-
a, b =\
|
26
|
-
(Math.cos(t) + 0.5) * 0xff,
|
27
|
-
(Math.sin(t) + 0.5) * 0xff
|
28
|
-
|
29
|
-
c = (a + b) / 2
|
30
|
-
|
31
|
-
@colors = [
|
32
|
-
Gosu::Color.rgb(a, b, 0xff),
|
33
|
-
Gosu::Color.rgb(a, 0x00, b),
|
34
|
-
Gosu::Color.rgb(0xff, b, a),
|
35
|
-
Gosu::Color.rgb(b, a, 0x00),
|
36
|
-
Gosu::Color.rgb(b, 0xff, a),
|
37
|
-
Gosu::Color.rgb(0x00, a, b) ]
|
38
|
-
|
39
|
-
@background = Gosu::Color.rgb(c, c, c)
|
40
|
-
end
|
41
|
-
|
42
|
-
draw do
|
43
|
-
draw_quad\
|
44
|
-
0, 0, @background,
|
45
|
-
0, height, @background,
|
46
|
-
width, height, @background,
|
47
|
-
width, 0, @background, 0
|
48
|
-
|
49
|
-
translate width / 2, height / 2 do
|
50
|
-
@colors.each.with_index do |color, i|
|
51
|
-
|
52
|
-
angle = @angle + i.to_f / @colors.length * 2.0 * Math::PI
|
53
|
-
x = @radius * Math.sin(angle)
|
54
|
-
y = @radius * Math.cos(angle)
|
55
|
-
w, h = x, y
|
56
|
-
|
57
|
-
translate x, y do
|
58
|
-
rotate Gosu.radians_to_degrees(angle) do
|
59
|
-
draw_quad\
|
60
|
-
-w, +h, color,
|
61
|
-
-w, -h, color,
|
62
|
-
+w, -h, color,
|
63
|
-
+w, +h, color, 0
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
# Gosu Zen example based on erisdiscord's comment here:
|
2
|
+
# https://github.com/jlnr/gosu/pull/120
|
3
|
+
|
4
|
+
# Gosu Zen is the (inline) Sinatra of Ruby multimedia programming.
|
5
|
+
# The interface is still in flux. If you want to tune the interface
|
6
|
+
# a little further or provide more examples, please fork Gosu and
|
7
|
+
# send a pull request. Thanks!
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'gosu/zen'
|
11
|
+
include Gosu::Zen
|
12
|
+
|
13
|
+
window 480, 240, :fullscreen => false
|
14
|
+
|
15
|
+
button_down Gosu::KbEscape do
|
16
|
+
close
|
17
|
+
end
|
18
|
+
|
19
|
+
update do
|
20
|
+
t = Gosu.milliseconds / 1000.0
|
21
|
+
|
22
|
+
@radius = [width, height].min * 0.37
|
23
|
+
@angle = t * Math::PI
|
24
|
+
|
25
|
+
a, b =\
|
26
|
+
(Math.cos(t) + 0.5) * 0xff,
|
27
|
+
(Math.sin(t) + 0.5) * 0xff
|
28
|
+
|
29
|
+
c = (a + b) / 2
|
30
|
+
|
31
|
+
@colors = [
|
32
|
+
Gosu::Color.rgb(a, b, 0xff),
|
33
|
+
Gosu::Color.rgb(a, 0x00, b),
|
34
|
+
Gosu::Color.rgb(0xff, b, a),
|
35
|
+
Gosu::Color.rgb(b, a, 0x00),
|
36
|
+
Gosu::Color.rgb(b, 0xff, a),
|
37
|
+
Gosu::Color.rgb(0x00, a, b) ]
|
38
|
+
|
39
|
+
@background = Gosu::Color.rgb(c, c, c)
|
40
|
+
end
|
41
|
+
|
42
|
+
draw do
|
43
|
+
draw_quad\
|
44
|
+
0, 0, @background,
|
45
|
+
0, height, @background,
|
46
|
+
width, height, @background,
|
47
|
+
width, 0, @background, 0
|
48
|
+
|
49
|
+
translate width / 2, height / 2 do
|
50
|
+
@colors.each.with_index do |color, i|
|
51
|
+
|
52
|
+
angle = @angle + i.to_f / @colors.length * 2.0 * Math::PI
|
53
|
+
x = @radius * Math.sin(angle)
|
54
|
+
y = @radius * Math.cos(angle)
|
55
|
+
w, h = x, y
|
56
|
+
|
57
|
+
translate x, y do
|
58
|
+
rotate Gosu.radians_to_degrees(angle) do
|
59
|
+
draw_quad\
|
60
|
+
-w, +h, color,
|
61
|
+
-w, -h, color,
|
62
|
+
+w, -h, color,
|
63
|
+
+w, +h, color, 0
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|