gosu-examples 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +14 -0
  4. data/bin/gosu-examples +97 -0
  5. data/examples/chipmunk_and_rmagick.rb +152 -0
  6. data/examples/chipmunk_integration.rb +278 -0
  7. data/examples/cptn_ruby.rb +229 -0
  8. data/examples/media/BrokenPNG.png +0 -0
  9. data/examples/media/Cursor.png +0 -0
  10. data/examples/media/JingleBells.mp3 +0 -0
  11. data/examples/media/JingleBells.ogg +0 -0
  12. data/examples/media/Loop.wav +0 -0
  13. data/examples/media/Sample.wav +0 -0
  14. data/examples/media/SquareTexture.png +0 -0
  15. data/examples/media/Wallpaper.png +0 -0
  16. data/examples/media/WallpaperXXL.png +0 -0
  17. data/examples/media/WhiteAlpha.png +0 -0
  18. data/examples/media/audio_formats/aiff_32bit_float.aiff +0 -0
  19. data/examples/media/audio_formats/au_16bit_pcm.au +0 -0
  20. data/examples/media/audio_formats/caf_be_16bit_44khz.caf +0 -0
  21. data/examples/media/audio_formats/caf_le_16bit_44khz.caf +0 -0
  22. data/examples/media/audio_formats/caf_le_8bit_44khz.caf +0 -0
  23. data/examples/media/audio_formats/general_midi.mid +0 -0
  24. data/examples/media/audio_formats/impulse_tracker.it +0 -0
  25. data/examples/media/audio_formats/mp3_128k_stereo.mp3 +0 -0
  26. data/examples/media/audio_formats/mp3_avg_96kbit_jointstereo.mp3 +0 -0
  27. data/examples/media/audio_formats/ogg_vorbis.ogg +0 -0
  28. data/examples/media/audio_formats/wav_16bit_pcm.wav +0 -0
  29. data/examples/media/audio_formats/wav_32bit_pcm.wav +0 -0
  30. data/examples/media/audio_formats/wav_4bit_ms_adpcm.wav +0 -0
  31. data/examples/media/beep.wav +0 -0
  32. data/examples/media/cptn_ruby.png +0 -0
  33. data/examples/media/cptn_ruby_map.txt +25 -0
  34. data/examples/media/earth.png +0 -0
  35. data/examples/media/explosion.wav +0 -0
  36. data/examples/media/gem.png +0 -0
  37. data/examples/media/header.psd +0 -0
  38. data/examples/media/image_formats/test.jpg +0 -0
  39. data/examples/media/image_formats/test.psd +0 -0
  40. data/examples/media/landscape.svg +10 -0
  41. data/examples/media/large_star.png +0 -0
  42. data/examples/media/smoke.png +0 -0
  43. data/examples/media/soldier.png +0 -0
  44. data/examples/media/space.png +0 -0
  45. data/examples/media/star.png +0 -0
  46. data/examples/media/starfighter.bmp +0 -0
  47. data/examples/media/tileset.png +0 -0
  48. data/examples/media/vera.ttf +0 -0
  49. data/examples/opengl_integration.rb +224 -0
  50. data/examples/rmagick_integration.rb +413 -0
  51. data/examples/tutorial.rb +129 -0
  52. data/examples/welcome.rb +59 -0
  53. data/lib/gosu-examples/example.rb +82 -0
  54. data/lib/gosu-examples/sidebar.rb +60 -0
  55. metadata +112 -0
@@ -0,0 +1,59 @@
1
+ # Encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'gosu'
5
+
6
+ WIDTH, HEIGHT = 600, 600
7
+
8
+ class Welcome < (Example rescue Gosu::Window)
9
+ PADDING = 20
10
+
11
+ def initialize
12
+ super WIDTH, HEIGHT
13
+
14
+ self.caption = "Welcome!"
15
+
16
+ text =
17
+ "<b>Welcome to the Gosu Example Box!</b>
18
+
19
+ This little tool lets you launch any of Gosu’s example games from the list on the right hand side of the screen.
20
+
21
+ Every example can be run both from this tool <i>and</i> from the terminal/command line as a stand-alone Ruby script.
22
+
23
+ Shortcuts:
24
+
25
+ • To see the source code of an example or feature demo, press <b>S</b>.
26
+ • To open the ‘examples’ folder, press <b>O</b>.
27
+ • To quit this tool, press <b>Esc</b>. This is useful if you are running in fullscreen mode. ($ gosu-examples --fullscreen)
28
+
29
+ Why not take a look at the code for this example right now? Simply press <b>S</b>."
30
+
31
+ # Remove all leading spaces so the text is left-aligned
32
+ text.gsub! /^ +/, ''
33
+
34
+ @text = Gosu::Image.from_text text, 20, :width => WIDTH - 2 * PADDING
35
+
36
+ @background = Gosu::Image.new "media/space.png"
37
+ end
38
+
39
+ def draw
40
+ draw_rotating_star_backgrounds
41
+
42
+ @text.draw PADDING, PADDING, 0
43
+ end
44
+
45
+ def draw_rotating_star_backgrounds
46
+ # Disregard the math in this method, it doesn't look as good as I thought it
47
+ # would. =(
48
+
49
+ angle = Gosu::milliseconds / 50.0
50
+ scale = (Gosu::milliseconds % 1000) / 1000.0
51
+
52
+ [1, 0].each do |extra_scale|
53
+ @background.draw_rot WIDTH * 0.5, HEIGHT * 0.75, 0, angle, 0.5, 0.5,
54
+ scale + extra_scale, scale + extra_scale
55
+ end
56
+ end
57
+ end
58
+
59
+ Welcome.new.show if __FILE__ == $0
@@ -0,0 +1,82 @@
1
+ class Example
2
+ attr_accessor :caption
3
+ attr_reader :width, :height
4
+
5
+ def initialize(width, height, *options)
6
+ @width, @height = width, height
7
+ end
8
+
9
+ def draw
10
+ end
11
+
12
+ def update
13
+ end
14
+
15
+ def button_down(id)
16
+ end
17
+
18
+ def button_up(id)
19
+ end
20
+ end
21
+
22
+ class Feature < Example
23
+ def self.inherited(subclass)
24
+ @@features ||= {}
25
+ @@features[subclass] = self.current_source_file
26
+ end
27
+
28
+ def self.features
29
+ @@features.keys
30
+ end
31
+
32
+ def self.source_file
33
+ @@examples[self]
34
+ end
35
+ end
36
+
37
+ class Example
38
+ def self.current_source_file
39
+ @current_source_file
40
+ end
41
+
42
+ def self.current_source_file=(current_source_file)
43
+ @current_source_file = current_source_file
44
+ end
45
+
46
+ def self.inherited(subclass)
47
+ @@examples ||= {}
48
+ @@examples[subclass] = self.current_source_file
49
+ end
50
+
51
+ def self.examples
52
+ @@examples.keys - [Feature]
53
+ end
54
+
55
+ def self.source_file
56
+ @@examples[self]
57
+ end
58
+
59
+ def self.load_examples(pattern)
60
+ Dir.glob(pattern) do |file|
61
+ begin
62
+ # Remember that all examples and features being loaded now must come from the
63
+ # next file.
64
+ #
65
+ Example.current_source_file = File.expand_path(file)
66
+
67
+ # Load the example/feature in a sandbox module (second parameter). This way,
68
+ # several examples can define a Player class without colliding.
69
+ #
70
+ # load() does not let us refer to the anonymous module it creates, but we
71
+ # can enumerate all loaded examples and features using Example.examples and
72
+ # Feature.features afterwards.
73
+ #
74
+ load file, true
75
+ rescue Exception => e
76
+ puts "*** Cannot load #{file}:"
77
+ puts e
78
+ puts
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,60 @@
1
+ class Sidebar
2
+ WIDTH = 213
3
+ HEIGHT = 600
4
+ FONT = Gosu::Font.new(20)
5
+ HEADER = Gosu::Image.new("media/header.psd", :tileable => true)
6
+
7
+ class Button
8
+ HEIGHT = 25
9
+ SPACING = 5
10
+ TOP_Y = HEADER.height + 15
11
+
12
+ attr_reader :filename
13
+
14
+ def initialize(top, filename, &handler)
15
+ @top, @filename, @handler = top, filename, handler
16
+ end
17
+
18
+ def draw(is_current)
19
+ text_color = Gosu::Color::BLACK
20
+
21
+ if is_current
22
+ Gosu::draw_rect 0, @top, Sidebar::WIDTH, HEIGHT, 0xff_1565e5 if is_current
23
+ text_color = Gosu::Color::WHITE
24
+ end
25
+
26
+ FONT.draw File.basename(@filename), 13, @top + 2, 0, 1, 1, text_color
27
+ end
28
+
29
+ def click
30
+ @handler.call
31
+ end
32
+ end
33
+
34
+ def initialize
35
+ y = Button::TOP_Y - Button::HEIGHT - Button::SPACING
36
+
37
+ @buttons = Example.examples.map do |example|
38
+ y += (Button::HEIGHT + Button::SPACING)
39
+
40
+ Button.new(y, example.source_file) do
41
+ yield(example)
42
+ end
43
+ end
44
+ end
45
+
46
+ def draw(current_filename)
47
+ Gosu::draw_rect 0, 0, WIDTH, HEIGHT, Gosu::Color::WHITE
48
+ HEADER.draw 0, 0, 0
49
+
50
+ @buttons.each do |button|
51
+ is_current = (button.filename == current_filename)
52
+ button.draw(is_current)
53
+ end
54
+ end
55
+
56
+ def click(x, y)
57
+ index = (y - Button::TOP_Y).floor / (Button::HEIGHT + Button::SPACING)
58
+ @buttons[index].click if @buttons[index]
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gosu-examples
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Julian Raschke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gosu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ description: The `gosu-examples` tool provides an easy way to run and inspect example
28
+ games written for the Gosu game development library.
29
+ email: julian@raschke.de
30
+ executables:
31
+ - gosu-examples
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/gosu-examples
36
+ - LICENSE
37
+ - README.md
38
+ - lib/gosu-examples/example.rb
39
+ - lib/gosu-examples/sidebar.rb
40
+ - examples/chipmunk_and_rmagick.rb
41
+ - examples/chipmunk_integration.rb
42
+ - examples/cptn_ruby.rb
43
+ - examples/opengl_integration.rb
44
+ - examples/rmagick_integration.rb
45
+ - examples/tutorial.rb
46
+ - examples/welcome.rb
47
+ - examples/media/audio_formats/aiff_32bit_float.aiff
48
+ - examples/media/audio_formats/au_16bit_pcm.au
49
+ - examples/media/audio_formats/caf_be_16bit_44khz.caf
50
+ - examples/media/audio_formats/caf_le_16bit_44khz.caf
51
+ - examples/media/audio_formats/caf_le_8bit_44khz.caf
52
+ - examples/media/audio_formats/general_midi.mid
53
+ - examples/media/audio_formats/impulse_tracker.it
54
+ - examples/media/audio_formats/mp3_128k_stereo.mp3
55
+ - examples/media/audio_formats/mp3_avg_96kbit_jointstereo.mp3
56
+ - examples/media/audio_formats/ogg_vorbis.ogg
57
+ - examples/media/audio_formats/wav_16bit_pcm.wav
58
+ - examples/media/audio_formats/wav_32bit_pcm.wav
59
+ - examples/media/audio_formats/wav_4bit_ms_adpcm.wav
60
+ - examples/media/beep.wav
61
+ - examples/media/BrokenPNG.png
62
+ - examples/media/cptn_ruby.png
63
+ - examples/media/cptn_ruby_map.txt
64
+ - examples/media/Cursor.png
65
+ - examples/media/earth.png
66
+ - examples/media/explosion.wav
67
+ - examples/media/gem.png
68
+ - examples/media/header.psd
69
+ - examples/media/image_formats/test.jpg
70
+ - examples/media/image_formats/test.psd
71
+ - examples/media/JingleBells.mp3
72
+ - examples/media/JingleBells.ogg
73
+ - examples/media/landscape.svg
74
+ - examples/media/large_star.png
75
+ - examples/media/Loop.wav
76
+ - examples/media/Sample.wav
77
+ - examples/media/smoke.png
78
+ - examples/media/soldier.png
79
+ - examples/media/space.png
80
+ - examples/media/SquareTexture.png
81
+ - examples/media/star.png
82
+ - examples/media/starfighter.bmp
83
+ - examples/media/tileset.png
84
+ - examples/media/vera.ttf
85
+ - examples/media/Wallpaper.png
86
+ - examples/media/WallpaperXXL.png
87
+ - examples/media/WhiteAlpha.png
88
+ homepage: http://www.libgosu.org/
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 1.8.2
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.14
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ruby examples for the Gosu library
111
+ test_files: []
112
+ has_rdoc: