gosu-examples 1.0.5 → 1.0.7

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/bin/gosu-examples +3 -5
  4. data/examples/chipmunk_and_rmagick.rb +17 -19
  5. data/examples/chipmunk_integration.rb +42 -44
  6. data/examples/cptn_ruby.rb +19 -21
  7. data/examples/opengl_integration.rb +59 -59
  8. data/examples/rmagick_integration.rb +74 -74
  9. data/examples/text_input.rb +26 -27
  10. data/examples/tutorial.rb +21 -23
  11. data/examples/welcome.rb +17 -19
  12. data/lib/gosu-examples/example.rb +18 -18
  13. data/lib/gosu-examples/sidebar.rb +14 -14
  14. metadata +9 -36
  15. data/examples/media/BrokenPNG.png +0 -0
  16. data/examples/media/Cursor.png +0 -0
  17. data/examples/media/JingleBells.mp3 +0 -0
  18. data/examples/media/JingleBells.ogg +0 -0
  19. data/examples/media/Loop.wav +0 -0
  20. data/examples/media/Sample.wav +0 -0
  21. data/examples/media/SquareTexture.png +0 -0
  22. data/examples/media/Wallpaper.png +0 -0
  23. data/examples/media/WallpaperXXL.png +0 -0
  24. data/examples/media/WhiteAlpha.png +0 -0
  25. data/examples/media/audio_formats/aiff_32bit_float.aiff +0 -0
  26. data/examples/media/audio_formats/au_16bit_pcm.au +0 -0
  27. data/examples/media/audio_formats/caf_be_16bit_44khz.caf +0 -0
  28. data/examples/media/audio_formats/caf_le_16bit_44khz.caf +0 -0
  29. data/examples/media/audio_formats/caf_le_8bit_44khz.caf +0 -0
  30. data/examples/media/audio_formats/general_midi.mid +0 -0
  31. data/examples/media/audio_formats/impulse_tracker.it +0 -0
  32. data/examples/media/audio_formats/mp3_128k_stereo.mp3 +0 -0
  33. data/examples/media/audio_formats/mp3_avg_96kbit_jointstereo.mp3 +0 -0
  34. data/examples/media/audio_formats/ogg_vorbis.ogg +0 -0
  35. data/examples/media/audio_formats/wav_16bit_pcm.wav +0 -0
  36. data/examples/media/audio_formats/wav_32bit_pcm.wav +0 -0
  37. data/examples/media/audio_formats/wav_4bit_ms_adpcm.wav +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/vera.ttf +0 -0
@@ -24,31 +24,31 @@ class TextField < Gosu::TextInput
24
24
  WIDTH = 350
25
25
  LENGTH_LIMIT = 20
26
26
  PADDING = 5
27
-
28
- INACTIVE_COLOR = 0xcc_666666
29
- ACTIVE_COLOR = 0xcc_ff6666
27
+
28
+ INACTIVE_COLOR = 0xcc_666666
29
+ ACTIVE_COLOR = 0xcc_ff6666
30
30
  SELECTION_COLOR = 0xcc_0000ff
31
- CARET_COLOR = 0xff_ffffff
32
-
31
+ CARET_COLOR = 0xff_ffffff
32
+
33
33
  attr_reader :x, :y
34
-
34
+
35
35
  def initialize(window, x, y)
36
36
  # It's important to call the inherited constructor.
37
37
  super()
38
-
38
+
39
39
  @window, @x, @y = window, x, y
40
-
40
+
41
41
  # Start with a self-explanatory text in each field.
42
42
  self.text = "Click to edit"
43
43
  end
44
-
44
+
45
45
  # In this example, we use the filter method to prevent the user from entering a text that exceeds
46
46
  # the length limit. However, you can also use this to blacklist certain characters, etc.
47
- def filter new_text
47
+ def filter(new_text)
48
48
  allowed_length = [LENGTH_LIMIT - text.length, 0].max
49
49
  new_text[0, allowed_length]
50
50
  end
51
-
51
+
52
52
  def draw(z)
53
53
  # Change the background colour if this is the currently selected text field.
54
54
  if @window.text_input == self
@@ -57,12 +57,12 @@ class TextField < Gosu::TextInput
57
57
  color = INACTIVE_COLOR
58
58
  end
59
59
  Gosu.draw_rect x - PADDING, y - PADDING, WIDTH + 2 * PADDING, height + 2 * PADDING, color, z
60
-
60
+
61
61
  # Calculate the position of the caret and the selection start.
62
62
  pos_x = x + FONT.text_width(self.text[0...self.caret_pos])
63
63
  sel_x = x + FONT.text_width(self.text[0...self.selection_start])
64
64
  sel_w = pos_x - sel_x
65
-
65
+
66
66
  # Draw the selection background, if any. (If not, sel_x and pos_x will be
67
67
  # the same value, making this a no-op call.)
68
68
  Gosu.draw_rect sel_x, y, sel_w, height, SELECTION_COLOR, z
@@ -73,9 +73,9 @@ class TextField < Gosu::TextInput
73
73
  end
74
74
 
75
75
  # Finally, draw the text itself!
76
- FONT.draw self.text, x, y, z
76
+ FONT.draw_text self.text, x, y, z
77
77
  end
78
-
78
+
79
79
  def height
80
80
  FONT.height
81
81
  end
@@ -85,13 +85,13 @@ class TextField < Gosu::TextInput
85
85
  @window.mouse_x > x - PADDING and @window.mouse_x < x + WIDTH + PADDING and
86
86
  @window.mouse_y > y - PADDING and @window.mouse_y < y + height + PADDING
87
87
  end
88
-
88
+
89
89
  # Tries to move the caret to the position specifies by mouse_x
90
90
  def move_caret_to_mouse
91
91
  # Test character by character
92
92
  1.upto(self.text.length) do |i|
93
93
  if @window.mouse_x < x + FONT.text_width(text[0...i])
94
- self.caret_pos = self.selection_start = i - 1;
94
+ self.caret_pos = self.selection_start = i - 1
95
95
  return
96
96
  end
97
97
  end
@@ -104,24 +104,23 @@ class TextInputDemo < (Example rescue Gosu::Window)
104
104
  def initialize
105
105
  super 640, 480
106
106
  self.caption = "Text Input Demo"
107
-
108
-
107
+
109
108
  text =
110
109
  "This demo explains (in the source code) how to use the Gosu::TextInput API by building a little TextField class around it.
111
-
110
+
112
111
  Each text field can take up to 30 characters, and you can use Tab to switch between them.
113
112
 
114
- As in every example, press <b>S</b> to look at the source code."
115
-
113
+ As in every example, press <b>E</b> to look at the source code."
114
+
116
115
  # Remove all leading spaces so the text is left-aligned
117
116
  text.gsub! /^ +/, ""
118
-
119
- @text = Gosu::Image.from_text text, 20, width: 540
120
-
117
+
118
+ @text = Gosu::Image.from_markup text, 20, width: 540
119
+
121
120
  # Set up an array of three text fields.
122
121
  @text_fields = Array.new(3) { |index| TextField.new(self, 50, 300 + index * 50) }
123
122
  end
124
-
123
+
125
124
  def needs_cursor?
126
125
  true
127
126
  end
@@ -130,7 +129,7 @@ class TextInputDemo < (Example rescue Gosu::Window)
130
129
  @text.draw 50, 50, 0
131
130
  @text_fields.each { |tf| tf.draw(0) }
132
131
  end
133
-
132
+
134
133
  def button_down(id)
135
134
  if id == Gosu::KB_TAB
136
135
  # Tab key will not be 'eaten' by text fields; use for switching through
data/examples/tutorial.rb CHANGED
@@ -1,5 +1,3 @@
1
- # Encoding: UTF-8
2
-
3
1
  require "gosu"
4
2
 
5
3
  module ZOrder
@@ -8,45 +6,45 @@ end
8
6
 
9
7
  class Player
10
8
  attr_reader :score
11
-
9
+
12
10
  def initialize
13
11
  @image = Gosu::Image.new("media/starfighter.bmp")
14
12
  @beep = Gosu::Sample.new("media/beep.wav")
15
13
  @x = @y = @vel_x = @vel_y = @angle = 0.0
16
14
  @score = 0
17
15
  end
18
-
16
+
19
17
  def warp(x, y)
20
18
  @x, @y = x, y
21
19
  end
22
-
20
+
23
21
  def turn_left
24
22
  @angle -= 4.5
25
23
  end
26
-
24
+
27
25
  def turn_right
28
26
  @angle += 4.5
29
27
  end
30
-
28
+
31
29
  def accelerate
32
30
  @vel_x += Gosu.offset_x(@angle, 0.5)
33
31
  @vel_y += Gosu.offset_y(@angle, 0.5)
34
32
  end
35
-
33
+
36
34
  def move
37
35
  @x += @vel_x
38
36
  @y += @vel_y
39
37
  @x %= 640
40
38
  @y %= 480
41
-
39
+
42
40
  @vel_x *= 0.95
43
41
  @vel_y *= 0.95
44
42
  end
45
-
43
+
46
44
  def draw
47
45
  @image.draw_rot(@x, @y, ZOrder::PLAYER, @angle)
48
46
  end
49
-
47
+
50
48
  def collect_stars(stars)
51
49
  stars.reject! do |star|
52
50
  if Gosu.distance(@x, @y, star.x, star.y) < 35
@@ -62,7 +60,7 @@ end
62
60
 
63
61
  class Star
64
62
  attr_reader :x, :y
65
-
63
+
66
64
  def initialize(animation)
67
65
  @animation = animation
68
66
  @color = Gosu::Color::BLACK.dup
@@ -72,11 +70,11 @@ class Star
72
70
  @x = rand * 640
73
71
  @y = rand * 480
74
72
  end
75
-
73
+
76
74
  def draw
77
75
  img = @animation[Gosu.milliseconds / 100 % @animation.size]
78
76
  img.draw(@x - img.width / 2.0, @y - img.height / 2.0,
79
- ZOrder::STARS, 1, 1, @color, :add)
77
+ ZOrder::STARS, 1, 1, @color, :add)
80
78
  end
81
79
  end
82
80
 
@@ -84,18 +82,18 @@ class Tutorial < (Example rescue Gosu::Window)
84
82
  def initialize
85
83
  super 640, 480
86
84
  self.caption = "Tutorial Game"
87
-
85
+
88
86
  @background_image = Gosu::Image.new("media/space.png", tileable: true)
89
-
87
+
90
88
  @player = Player.new
91
89
  @player.warp(320, 240)
92
-
90
+
93
91
  @star_anim = Gosu::Image::load_tiles("media/star.png", 25, 25)
94
92
  @stars = Array.new
95
-
93
+
96
94
  @font = Gosu::Font.new(20)
97
95
  end
98
-
96
+
99
97
  def update
100
98
  if Gosu.button_down? Gosu::KB_LEFT or Gosu.button_down? Gosu::GP_LEFT
101
99
  @player.turn_left
@@ -108,19 +106,19 @@ class Tutorial < (Example rescue Gosu::Window)
108
106
  end
109
107
  @player.move
110
108
  @player.collect_stars(@stars)
111
-
109
+
112
110
  if rand(100) < 4 and @stars.size < 25
113
111
  @stars.push(Star.new(@star_anim))
114
112
  end
115
113
  end
116
-
114
+
117
115
  def draw
118
116
  @background_image.draw(0, 0, ZOrder::BACKGROUND)
119
117
  @player.draw
120
118
  @stars.each { |star| star.draw }
121
- @font.draw("Score: #{@player.score}", 10, 10, ZOrder::UI, 1.0, 1.0, Gosu::Color::YELLOW)
119
+ @font.draw_text("Score: #{@player.score}", 10, 10, ZOrder::UI, 1.0, 1.0, Gosu::Color::YELLOW)
122
120
  end
123
-
121
+
124
122
  def button_down(id)
125
123
  if id == Gosu::KB_ESCAPE
126
124
  close
data/examples/welcome.rb CHANGED
@@ -1,54 +1,52 @@
1
- # Encoding: UTF-8
2
-
3
1
  require "gosu"
4
2
 
5
3
  WIDTH, HEIGHT = 640, 480
6
4
 
7
5
  class Welcome < (Example rescue Gosu::Window)
8
6
  PADDING = 20
9
-
7
+
10
8
  def initialize
11
9
  super WIDTH, HEIGHT
12
-
10
+
13
11
  self.caption = "Welcome!"
14
-
12
+
15
13
  text =
16
14
  "<b>Welcome to the Gosu Example Box!</b>
17
-
15
+
18
16
  This little tool lets you launch any of Gosu’s example games from the list on the right hand side of the screen.
19
-
17
+
20
18
  Every example can be run both from this tool <i>and</i> from the terminal/command line as a stand-alone Ruby script.
21
-
19
+
22
20
  Keyboard shortcuts:
23
-
21
+
24
22
  • To see the source code of an example or feature demo, press <b>E</b>.
25
23
  • To open the ‘examples’ folder, press <b>O</b>.
26
24
  • To quit this tool, press <b>Esc</b>.
27
25
  • To toggle fullscreen mode, press <b>Alt+Enter</b> (Windows, Linux) or <b>cmd+F</b> (macOS).
28
-
26
+
29
27
  Why not take a look at the code for this example right now? Simply press <b>E</b>."
30
-
28
+
31
29
  # Remove all leading spaces so the text is left-aligned
32
30
  text.gsub! /^ +/, ""
33
-
34
- @text = Gosu::Image.from_text text, 20, width: WIDTH - 2 * PADDING
35
-
31
+
32
+ @text = Gosu::Image.from_markup text, 20, width: WIDTH - 2 * PADDING
33
+
36
34
  @background = Gosu::Image.new "media/space.png"
37
35
  end
38
-
36
+
39
37
  def draw
40
38
  draw_rotating_star_backgrounds
41
-
39
+
42
40
  @text.draw PADDING, PADDING, 0
43
41
  end
44
-
42
+
45
43
  def draw_rotating_star_backgrounds
46
44
  # Disregard the math in this method, it doesn't look as good as I thought it
47
45
  # would. =(
48
-
46
+
49
47
  angle = Gosu.milliseconds / 50.0
50
48
  scale = (Gosu.milliseconds % 1000) / 1000.0
51
-
49
+
52
50
  [1, 0].each do |extra_scale|
53
51
  @background.draw_rot WIDTH * 0.5, HEIGHT * 0.75, 0, angle, 0.5, 0.5,
54
52
  scale + extra_scale, scale + extra_scale
@@ -2,23 +2,23 @@ class Example
2
2
  attr_accessor :caption
3
3
  attr_reader :width, :height
4
4
  attr_writer :parent_window
5
-
5
+
6
6
  def initialize(width, height, *options)
7
7
  @width, @height = width, height
8
8
  end
9
-
9
+
10
10
  def draw
11
11
  end
12
-
12
+
13
13
  def update
14
14
  end
15
-
15
+
16
16
  def button_down(id)
17
17
  end
18
-
18
+
19
19
  def button_up(id)
20
20
  end
21
-
21
+
22
22
  def close
23
23
  # no-op, examples cannot close the containing window.
24
24
  end
@@ -26,53 +26,53 @@ class Example
26
26
  def mouse_x
27
27
  @parent_window && @parent_window.mouse_x
28
28
  end
29
-
29
+
30
30
  def mouse_y
31
31
  @parent_window && @parent_window.mouse_y
32
32
  end
33
-
33
+
34
34
  def text_input
35
35
  @parent_window && @parent_window.text_input
36
36
  end
37
-
37
+
38
38
  def text_input=(text_input)
39
39
  @parent_window && @parent_window.text_input = text_input
40
40
  end
41
-
41
+
42
42
  def self.current_source_file
43
43
  @current_source_file
44
44
  end
45
-
45
+
46
46
  def self.current_source_file=(current_source_file)
47
47
  @current_source_file = current_source_file
48
48
  end
49
-
49
+
50
50
  def self.inherited(subclass)
51
51
  @@examples ||= {}
52
52
  @@examples[subclass] = self.current_source_file
53
53
  end
54
-
54
+
55
55
  def self.examples
56
56
  @@examples.keys
57
57
  end
58
-
58
+
59
59
  def self.source_file
60
60
  @@examples[self]
61
61
  end
62
-
62
+
63
63
  def self.initial_example
64
64
  @@examples.keys.find { |cls| cls.name.end_with? "::Welcome" }
65
65
  end
66
-
66
+
67
67
  def self.load_examples(pattern)
68
- Dir.glob(pattern) do |file|
68
+ Dir.glob(pattern) do |file|
69
69
  begin
70
70
  # Remember which file we are loading.
71
71
  Example.current_source_file = File.expand_path(file)
72
72
 
73
73
  # Load the example in a sandbox module (second parameter to load()). This way, examples can
74
74
  # define classes and constants with the same names, and they will not collide.
75
- #
75
+ #
76
76
  # load() does not let us refer to the anonymous module it creates, but we can enumerate all
77
77
  # loaded examples using Example.examples thanks to the "inherited" callback above.
78
78
  load file, true
@@ -3,56 +3,56 @@ class Sidebar
3
3
  HEIGHT = 600
4
4
  FONT = Gosu::Font.new(20)
5
5
  HEADER = Gosu::Image.new("media/header@2x.psd", tileable: true)
6
-
6
+
7
7
  class Button
8
8
  HEIGHT = 25
9
9
  SPACING = 5
10
10
  TOP_Y = HEADER.height / 2 + 15
11
-
11
+
12
12
  attr_reader :filename
13
-
13
+
14
14
  def initialize(top, filename, &handler)
15
15
  @top, @filename, @handler = top, filename, handler
16
16
  end
17
-
17
+
18
18
  def draw(is_current)
19
19
  text_color = Gosu::Color::BLACK
20
-
20
+
21
21
  if is_current
22
22
  Gosu.draw_rect 0, @top, Sidebar::WIDTH, HEIGHT, 0xff_1565e5
23
23
  text_color = Gosu::Color::WHITE
24
24
  end
25
-
26
- FONT.draw File.basename(@filename), 13, @top + 2, 0, 1, 1, text_color
25
+
26
+ FONT.draw_text File.basename(@filename), 13, @top + 2, 0, 1, 1, text_color
27
27
  end
28
-
28
+
29
29
  def click
30
30
  @handler.call
31
31
  end
32
32
  end
33
-
33
+
34
34
  def initialize
35
35
  y = Button::TOP_Y - Button::HEIGHT - Button::SPACING
36
-
36
+
37
37
  @buttons = Example.examples.map do |example|
38
38
  y += (Button::HEIGHT + Button::SPACING)
39
-
39
+
40
40
  Button.new(y, example.source_file) do
41
41
  yield(example)
42
42
  end
43
43
  end
44
44
  end
45
-
45
+
46
46
  def draw(current_filename)
47
47
  Gosu.draw_rect 0, 0, WIDTH, HEIGHT, Gosu::Color::WHITE
48
48
  HEADER.draw 0, 0, 0, 0.5, 0.5
49
-
49
+
50
50
  @buttons.each do |button|
51
51
  is_current = (button.filename == current_filename)
52
52
  button.draw(is_current)
53
53
  end
54
54
  end
55
-
55
+
56
56
  def click(x, y)
57
57
  index = (y - Button::TOP_Y).floor / (Button::HEIGHT + Button::SPACING)
58
58
  @buttons[index].click if @buttons[index]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu-examples
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Raschke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-04 00:00:00.000000000 Z
11
+ date: 2023-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.11.0
19
+ version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.11.0
26
+ version: 1.0.0
27
27
  description: The `gosu-examples` tool provides an easy way to run and inspect example
28
28
  games written for the Gosu game development library.
29
29
  email: julian@raschke.de
@@ -38,29 +38,6 @@ files:
38
38
  - examples/chipmunk_and_rmagick.rb
39
39
  - examples/chipmunk_integration.rb
40
40
  - examples/cptn_ruby.rb
41
- - examples/media/BrokenPNG.png
42
- - examples/media/Cursor.png
43
- - examples/media/JingleBells.mp3
44
- - examples/media/JingleBells.ogg
45
- - examples/media/Loop.wav
46
- - examples/media/Sample.wav
47
- - examples/media/SquareTexture.png
48
- - examples/media/Wallpaper.png
49
- - examples/media/WallpaperXXL.png
50
- - examples/media/WhiteAlpha.png
51
- - examples/media/audio_formats/aiff_32bit_float.aiff
52
- - examples/media/audio_formats/au_16bit_pcm.au
53
- - examples/media/audio_formats/caf_be_16bit_44khz.caf
54
- - examples/media/audio_formats/caf_le_16bit_44khz.caf
55
- - examples/media/audio_formats/caf_le_8bit_44khz.caf
56
- - examples/media/audio_formats/general_midi.mid
57
- - examples/media/audio_formats/impulse_tracker.it
58
- - examples/media/audio_formats/mp3_128k_stereo.mp3
59
- - examples/media/audio_formats/mp3_avg_96kbit_jointstereo.mp3
60
- - examples/media/audio_formats/ogg_vorbis.ogg
61
- - examples/media/audio_formats/wav_16bit_pcm.wav
62
- - examples/media/audio_formats/wav_32bit_pcm.wav
63
- - examples/media/audio_formats/wav_4bit_ms_adpcm.wav
64
41
  - examples/media/beep.wav
65
42
  - examples/media/cptn_ruby.png
66
43
  - examples/media/cptn_ruby_map.txt
@@ -68,8 +45,6 @@ files:
68
45
  - examples/media/explosion.wav
69
46
  - examples/media/gem.png
70
47
  - examples/media/header@2x.psd
71
- - examples/media/image_formats/test.jpg
72
- - examples/media/image_formats/test.psd
73
48
  - examples/media/landscape.svg
74
49
  - examples/media/large_star.png
75
50
  - examples/media/smoke.png
@@ -78,7 +53,6 @@ files:
78
53
  - examples/media/star.png
79
54
  - examples/media/starfighter.bmp
80
55
  - examples/media/tileset.png
81
- - examples/media/vera.ttf
82
56
  - examples/opengl_integration.rb
83
57
  - examples/rmagick_integration.rb
84
58
  - examples/text_input.rb
@@ -89,7 +63,7 @@ files:
89
63
  homepage: http://www.libgosu.org/
90
64
  licenses: []
91
65
  metadata: {}
92
- post_install_message:
66
+ post_install_message:
93
67
  rdoc_options: []
94
68
  require_paths:
95
69
  - lib
@@ -97,16 +71,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
71
  requirements:
98
72
  - - ">="
99
73
  - !ruby/object:Gem::Version
100
- version: 1.8.2
74
+ version: '0'
101
75
  required_rubygems_version: !ruby/object:Gem::Requirement
102
76
  requirements:
103
77
  - - ">="
104
78
  - !ruby/object:Gem::Version
105
79
  version: '0'
106
80
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.7.6
109
- signing_key:
81
+ rubygems_version: 3.4.19
82
+ signing_key:
110
83
  specification_version: 4
111
84
  summary: Ruby examples for the Gosu library
112
85
  test_files: []
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file