flonkerton 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ require 'protest'
2
+ require 'rr'
3
+ require File.dirname(__FILE__) + '/../lib/flonkerton'
4
+
5
+ class Protest::TestCase
6
+ include RR::Adapters::TestUnit
7
+ end
8
+
9
+ Protest.report_with(:documentation)
@@ -0,0 +1,386 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ Protest.describe('Flonkerton') do
4
+ it 'has a CONFIG hash.' do
5
+ config = { :width => 800,
6
+ :height => 600,
7
+ :caption => "Flonkerton Example",
8
+ :fullscreen => false,
9
+ :font_size => 20,
10
+ :initial_screen => "WelcomeScreen",
11
+ :media_path => "media",
12
+ :songs_ext => "*.ogg",
13
+ :images_ext => "*.png",
14
+ :samples_ext => "*.wav",
15
+ :tiles_ext => "*.png",
16
+ :fonts_ext => "*.ttf",
17
+ :image => { :x => 0,
18
+ :y => 0,
19
+ :z => 0,
20
+ :factor_x => 1,
21
+ :factor_y => 1,
22
+ :color => 0xffffffff,
23
+ :mode => :default,
24
+ :order => [:x, :y, :z, :factor_x, :factor_y, :color, :mode] },
25
+ :font => { :text => "",
26
+ :x => 0,
27
+ :y => 0,
28
+ :z => 0,
29
+ :factor_x => 1,
30
+ :factor_y => 1,
31
+ :color => 0xffffffff,
32
+ :mode => :default,
33
+ :order => [:text, :x, :y, :z, :factor_x, :factor_y, :color, :mode] } }
34
+
35
+ assert_equal config, Flonkerton::CONFIG
36
+ end
37
+ end
38
+
39
+ Protest.describe('A Game Window') do
40
+ setup do
41
+ @window = Flonkerton::Window.new
42
+ end
43
+
44
+ it 'has a current screen. (default: WelcomeScreen)' do
45
+ assert_kind_of Flonkerton::WelcomeScreen, @window.screen
46
+ end
47
+
48
+ it 'has a next screen. (default: nil)' do
49
+ assert_nil @window.next_screen
50
+ end
51
+
52
+ it 'updates the current screen.' do
53
+ mock(@window.screen).update
54
+ @window.update
55
+ end
56
+
57
+ it 'draws the current screen.' do
58
+ mock(@window.screen).draw
59
+ @window.draw
60
+ end
61
+
62
+ it 'passes button_down events to the current screen.' do
63
+ mock(@window.screen).button_down(Gosu::KbA)
64
+ @window.button_down(Gosu::KbA)
65
+ end
66
+
67
+ it 'passes button_up events to the current screen.' do
68
+ mock(@window.screen).button_up(Gosu::KbA)
69
+ @window.button_up(Gosu::KbA)
70
+ end
71
+
72
+ context('when working with several screens') do
73
+ module Example
74
+ class LogoScreen < Flonkerton::Screen
75
+ def update
76
+ go_to(GameScreen)
77
+ end
78
+ end
79
+ class GameScreen < Flonkerton::Screen
80
+ def update
81
+ go_to(CreditsScreen)
82
+ end
83
+ end
84
+ class CreditsScreen < Flonkerton::Screen; end
85
+ end
86
+
87
+ it 'can switch between them.' do
88
+ @window = Flonkerton::Window.new(Example::LogoScreen)
89
+ assert_kind_of Example::LogoScreen, @window.screen
90
+ @window.update
91
+ assert_kind_of Example::GameScreen, @window.screen
92
+ @window.update
93
+ assert_kind_of Example::CreditsScreen, @window.screen
94
+ end
95
+ end
96
+
97
+ it 'has a params hash.' do
98
+ assert_equal Hash.new, @window.params
99
+ end
100
+ end
101
+
102
+ Protest.describe('A Screen') do
103
+ setup do
104
+ @game = Flonkerton::Window.new
105
+ @screen = Flonkerton::Screen.new(@game)
106
+ end
107
+
108
+ # Gosu::Window methods
109
+ #
110
+ it 'has a width.' do
111
+ assert_equal 800, @screen.width
112
+ end
113
+
114
+ it 'has a height.' do
115
+ assert_equal 600, @screen.height
116
+ end
117
+
118
+ it 'has mouse coordinates.' do
119
+ assert_kind_of Numeric, @screen.mouse_x
120
+ assert_kind_of Numeric, @screen.mouse_y
121
+ end
122
+
123
+ it 'closes itself when Escape is pressed.' do
124
+ mock(@screen).close
125
+ @screen.button_down(Gosu::KbEscape)
126
+ end
127
+
128
+ it 'knows if a button is down.' do
129
+ stub(@game).button_down?(Gosu::KbA) { true }
130
+ stub(@game).button_down?(Gosu::KbZ) { false }
131
+ assert @screen.button_down?(Gosu::KbA)
132
+ assert !@screen.button_down?(Gosu::KbZ)
133
+ end
134
+
135
+ # Empty methods to override.
136
+ #
137
+ it 'can setup before game loop.' do
138
+ assert_respond_to @screen, :setup
139
+ end
140
+
141
+ it 'check button_up events while in game loop.' do
142
+ assert_respond_to @screen, :button_up
143
+ end
144
+
145
+ it 'updates game logic while in game loop.' do
146
+ assert_respond_to @screen, :update
147
+ end
148
+
149
+ it 'draws while in game loop.' do
150
+ assert_respond_to @screen, :draw
151
+ end
152
+
153
+ it 'can switch to another screen.' do
154
+ module Example
155
+ class LogoScreen < Flonkerton::Screen
156
+ def update
157
+ go_to(GameScreen)
158
+ end
159
+ end
160
+ class GameScreen < Flonkerton::Screen
161
+ def update
162
+ close
163
+ end
164
+ end
165
+ end
166
+
167
+ @game = Flonkerton::Window.new(Example::LogoScreen)
168
+ mock(@game).next_screen=(Example::GameScreen)
169
+ @game.update
170
+ end
171
+
172
+ it 'shares a params hash with other screens.' do
173
+ module Example
174
+ class LogoScreen < Flonkerton::Screen
175
+ def setup
176
+ params[:foo] = 200
177
+ end
178
+ def update
179
+ go_to(GameScreen)
180
+ end
181
+ end
182
+ class GameScreen < Flonkerton::Screen
183
+ def setup
184
+ params[:bar] = 'abc' + params[:foo].to_s
185
+ end
186
+ def update
187
+ close
188
+ end
189
+ end
190
+ end
191
+
192
+ @game = Flonkerton::Window.new(Example::LogoScreen)
193
+ @game.update
194
+ assert_equal 200, @game.params[:foo]
195
+ assert_equal 'abc200', @game.params[:bar]
196
+ end
197
+
198
+ it 'can close itself.' do
199
+ mock(@game).close
200
+ @screen.close
201
+ end
202
+
203
+ it 'can clip an image.' do
204
+ mock(@game).clip_to(10, 20, 200, 300)
205
+ @screen.clip_to(10, 20, 200, 300)
206
+ end
207
+
208
+ it 'calls setup method after initialization.' do
209
+ module Example
210
+ class LogoScreen < Flonkerton::Screen
211
+ attr_reader :value
212
+ def setup
213
+ @value = 100
214
+ end
215
+ end
216
+ end
217
+ assert_equal 100, Example::LogoScreen.new(@game).value
218
+ end
219
+ end
220
+
221
+ Protest.describe('A WelcomeScreen') do
222
+ setup do
223
+ @game = Flonkerton::Window.new
224
+ @welcome_screen = Flonkerton::WelcomeScreen.new(@game)
225
+ end
226
+
227
+ it 'shows a brief explanation about Flonkerton.' do
228
+ mock(Flonkerton::Fonts[:default]).draw(:text => 'Welcome')
229
+ @welcome_screen.draw
230
+ end
231
+ end
232
+
233
+ Protest.describe('A Sample') do
234
+ setup do
235
+ @game = Flonkerton::Window.new
236
+ @sample = Flonkerton::Sample.new(@game, 'media/select.wav')
237
+ end
238
+
239
+ it 'is a Gosu::Sample.' do
240
+ assert_kind_of Gosu::Sample, @sample
241
+ end
242
+ end
243
+
244
+ Protest.describe('A Song') do
245
+ setup do
246
+ @game = Flonkerton::Window.new
247
+ @song = Flonkerton::Song.new(@game, 'media/catch_me_song.ogg')
248
+ end
249
+
250
+ it 'is a Gosu::Song.' do
251
+ assert_kind_of Gosu::Song, @song
252
+ end
253
+
254
+ it 'has a loop method.' do
255
+ mock(@song).play(true)
256
+ @song.loop
257
+ end
258
+ end
259
+
260
+ Protest.describe('A Font') do
261
+ setup do
262
+ @game = Flonkerton::Window.new
263
+ @font = Flonkerton::Font.new(@game, 'media/ArcadeClassic.ttf')
264
+ end
265
+
266
+ it 'is a Gosu::Font.' do
267
+ assert_kind_of Gosu::Font, @font
268
+ end
269
+
270
+ it 'has a draw method that takes an options hash.' do
271
+ assert_nothing_raised do
272
+ @font.draw :text => 'test', :color => Gosu::Color::RED
273
+ end
274
+ end
275
+ end
276
+
277
+ Protest.describe('An Image') do
278
+ setup do
279
+ @game = Flonkerton::Window.new
280
+ @image = Flonkerton::Image.new(@game, 'media/gosu_logo.png')
281
+ end
282
+
283
+ it 'is a Gosu::Image.' do
284
+ assert_kind_of Gosu::Image, @image
285
+ end
286
+
287
+ it 'has a draw method that takes an options hash.' do
288
+ assert_nothing_raised do
289
+ @image.draw :x => 20, :mode => :additive
290
+ end
291
+ end
292
+ end
293
+
294
+ Protest.describe('Resource') do
295
+ it 'returns the content hash' do
296
+ assert_equal Hash.new, Flonkerton::Resource.all
297
+ end
298
+ end
299
+
300
+ Protest.describe('Resource - Fonts') do
301
+ it 'has a :default font.' do
302
+ assert_kind_of Flonkerton::Font, Flonkerton::Fonts[:default]
303
+ end
304
+
305
+ it 'loads all fonts in CONFIG[:media_path].' do
306
+ path = File.join(Flonkerton::CONFIG[:media_path], Flonkerton::CONFIG[:fonts_ext])
307
+ files = Dir[path]
308
+ assert files.any?
309
+ fonts = [Flonkerton::Fonts[:default]]
310
+ files.each do |file|
311
+ fonts << Flonkerton::Fonts[File.label(file)]
312
+ end
313
+ assert_equal fonts.uniq.map {|x| x.class }, Array.new(files.size + 1, Flonkerton::Font)
314
+ end
315
+ end
316
+
317
+ Protest.describe('Resource - Images') do
318
+ it 'loads all images in CONFIG[:media_path].' do
319
+ path = File.join(Flonkerton::CONFIG[:media_path], Flonkerton::CONFIG[:images_ext])
320
+ files = Dir[path]
321
+ assert files.any?
322
+ images = []
323
+ files.each do |file|
324
+ images << Flonkerton::Images[File.label(file)]
325
+ end
326
+ assert_equal images.uniq.map {|x| x.class }, Array.new(files.size, Flonkerton::Image)
327
+ end
328
+ end
329
+
330
+ Protest.describe('Resource - Songs') do
331
+ it 'loads all songs in CONFIG[:media_path].' do
332
+ path = File.join(Flonkerton::CONFIG[:media_path], Flonkerton::CONFIG[:songs_ext])
333
+ files = Dir[path]
334
+ assert files.any?
335
+ songs = []
336
+ files.each do |file|
337
+ songs << Flonkerton::Songs[File.label(file)]
338
+ end
339
+ assert_equal songs.uniq.map {|x| x.class }, Array.new(files.size, Flonkerton::Song)
340
+ end
341
+ end
342
+
343
+ Protest.describe('Resource - Samples') do
344
+ it 'loads all samples in CONFIG[:media_path].' do
345
+ path = File.join(Flonkerton::CONFIG[:media_path], Flonkerton::CONFIG[:samples_ext])
346
+ files = Dir[path]
347
+ assert files.any?
348
+ samples = []
349
+ files.each do |file|
350
+ samples << Flonkerton::Samples[File.label(file)]
351
+ end
352
+ assert_equal samples.uniq.map {|x| x.class }, Array.new(files.size, Flonkerton::Sample)
353
+ end
354
+ end
355
+
356
+ Protest.describe('Resource - Tiles') do
357
+ it 'loads all images in CONFIG[:media_path] that looks like a tileset. (eg. woods_64x64.png)' do
358
+ path = File.join(Flonkerton::CONFIG[:media_path], Flonkerton::CONFIG[:tiles_ext])
359
+ files = Dir[path]
360
+ assert files.any?
361
+ tiles = []
362
+ files.each do |file|
363
+ if File.basename(file) =~ /(\w+)_(\d+)x(\d+)/
364
+ tiles << Flonkerton::Tiles[$1.intern]
365
+ end
366
+ end
367
+ assert_equal tiles.uniq.map {|x| x.class }, Array.new(tiles.size, Array)
368
+
369
+ # returns Gosu::Image
370
+ image = tiles.first.first
371
+ assert_kind_of Gosu::Image, image
372
+
373
+ # ..but draw takes a hash, same as Flonkerton::Image
374
+ assert_nothing_raised do
375
+ image.draw :x => 20, :mode => :additive
376
+ end
377
+ end
378
+ end
379
+
380
+ Protest.describe('File') do
381
+ context('.label') do
382
+ it 'returns a symbol for an specific file' do
383
+ assert_equal :gosu_logo, File.label('media/gosu_logo.png')
384
+ end
385
+ end
386
+ end
@@ -0,0 +1,7 @@
1
+ default_action { system("ruby test/unit_tests.rb") }
2
+ #default_action { system("ruby test/integration_test.rb") }
3
+
4
+ watch( 'lib/flonkerton.rb' )
5
+ watch( 'test/unit_tests.rb' )
6
+ watch( 'test/integration_test.rb' )
7
+ watch( 'config/defaults.yml' )
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flonkerton
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ariel H. Pillet
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-27 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: gosu
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 37
30
+ segments:
31
+ - 0
32
+ - 7
33
+ - 19
34
+ version: 0.7.19
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: protest
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 17
46
+ segments:
47
+ - 0
48
+ - 3
49
+ - 1
50
+ version: 0.3.1
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rr
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 33
62
+ segments:
63
+ - 0
64
+ - 10
65
+ - 11
66
+ version: 0.10.11
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: watchr
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 7
78
+ segments:
79
+ - 0
80
+ - 6
81
+ version: "0.6"
82
+ type: :development
83
+ version_requirements: *id004
84
+ description: A simple framework that aims to improve your Gosu experience.
85
+ email:
86
+ - apillet@gmail.com
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ extra_rdoc_files: []
92
+
93
+ files:
94
+ - TODO
95
+ - README.md
96
+ - media/CREDITS
97
+ - Rakefile
98
+ - watchmen.rb
99
+ - config/defaults.yml
100
+ - examples/clip.rb
101
+ - examples/config/defaults.yml
102
+ - examples/extras/actor.rb
103
+ - examples/extras/fill.rb
104
+ - examples/extras/input_handler.rb
105
+ - examples/extras/mouse_border.rb
106
+ - examples/extras/random_color.rb
107
+ - examples/extras/scrollable.rb
108
+ - examples/font.rb
109
+ - examples/input.rb
110
+ - examples/screen.rb
111
+ - examples/scroll.rb
112
+ - examples/sound.rb
113
+ - examples/tiles.rb
114
+ - games/gosu_demo/config/defaults.yml
115
+ - games/gosu_demo/media/beep.wav
116
+ - games/gosu_demo/media/Space.png
117
+ - games/gosu_demo/media/star_25x25.png
118
+ - games/gosu_demo/media/starfighter.png
119
+ - games/gosu_demo/original.rb
120
+ - games/gosu_demo/play.rb
121
+ - lib/flonkerton.rb
122
+ - flonkerton.gemspec
123
+ - media/ArcadeClassic.ttf
124
+ - media/background.png
125
+ - media/catch_me_song.ogg
126
+ - media/cursor.png
127
+ - media/gosu_logo.png
128
+ - media/select.wav
129
+ - media/tiles_32x32.png
130
+ - test/integration_test.rb
131
+ - test/test_helper.rb
132
+ - test/unit_tests.rb
133
+ has_rdoc: true
134
+ homepage: http://github.com/apillet/flonkerton
135
+ licenses: []
136
+
137
+ post_install_message:
138
+ rdoc_options: []
139
+
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 3
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ requirements: []
161
+
162
+ rubyforge_project: flonkerton
163
+ rubygems_version: 1.3.7
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Gosu toys for the bored rubyist.
167
+ test_files: []
168
+