gosu 0.7.19-i386-mingw32

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 (57) hide show
  1. data/COPYING.txt +30 -0
  2. data/README.txt +17 -0
  3. data/examples/ChipmunkIntegration.rb +275 -0
  4. data/examples/CptnRuby.rb +231 -0
  5. data/examples/MoreChipmunkAndRMagick.rb +155 -0
  6. data/examples/OpenGLIntegration.rb +232 -0
  7. data/examples/RMagickIntegration.rb +449 -0
  8. data/examples/TextInput.rb +145 -0
  9. data/examples/Tutorial.rb +137 -0
  10. data/examples/media/Beep.wav +0 -0
  11. data/examples/media/CptnRuby Gem.png +0 -0
  12. data/examples/media/CptnRuby Map.txt +25 -0
  13. data/examples/media/CptnRuby Tileset.png +0 -0
  14. data/examples/media/CptnRuby.png +0 -0
  15. data/examples/media/Cursor.png +0 -0
  16. data/examples/media/Earth.png +0 -0
  17. data/examples/media/Explosion.wav +0 -0
  18. data/examples/media/LargeStar.png +0 -0
  19. data/examples/media/Sky.jpg +0 -0
  20. data/examples/media/Smoke.png +0 -0
  21. data/examples/media/Soldier.png +0 -0
  22. data/examples/media/Space.png +0 -0
  23. data/examples/media/Star.png +0 -0
  24. data/examples/media/Starfighter.bmp +0 -0
  25. data/lib/fmod.dll +0 -0
  26. data/lib/gosu.for_1_8.so +0 -0
  27. data/lib/gosu.for_1_9.so +0 -0
  28. data/lib/gosu.rb +19 -0
  29. data/lib/gosu/patches.rb +64 -0
  30. data/lib/gosu/swig_patches.rb +21 -0
  31. data/reference/rdoc/classes/Gosu.html +1546 -0
  32. data/reference/rdoc/classes/Gosu/Color.html +660 -0
  33. data/reference/rdoc/classes/Gosu/Font.html +545 -0
  34. data/reference/rdoc/classes/Gosu/GLTexInfo.html +412 -0
  35. data/reference/rdoc/classes/Gosu/Image.html +706 -0
  36. data/reference/rdoc/classes/Gosu/Sample.html +476 -0
  37. data/reference/rdoc/classes/Gosu/SampleInstance.html +523 -0
  38. data/reference/rdoc/classes/Gosu/Song.html +568 -0
  39. data/reference/rdoc/classes/Gosu/TextInput.html +444 -0
  40. data/reference/rdoc/classes/Gosu/Window.html +911 -0
  41. data/reference/rdoc/classes/Numeric.html +479 -0
  42. data/reference/rdoc/created.rid +1 -0
  43. data/reference/rdoc/files/COPYING_txt.html +391 -0
  44. data/reference/rdoc/files/README_txt.html +387 -0
  45. data/reference/rdoc/files/reference/Deployment on OS X_rdoc.html +381 -0
  46. data/reference/rdoc/files/reference/Deployment on Windows_rdoc.html +385 -0
  47. data/reference/rdoc/files/reference/Drawing with Colors_rdoc.html +363 -0
  48. data/reference/rdoc/files/reference/Order of Corners_rdoc.html +358 -0
  49. data/reference/rdoc/files/reference/Tileability_rdoc.html +374 -0
  50. data/reference/rdoc/files/reference/Z Ordering_rdoc.html +361 -0
  51. data/reference/rdoc/files/reference/gosu_rb.html +348 -0
  52. data/reference/rdoc/fr_class_index.html +12 -0
  53. data/reference/rdoc/fr_file_index.html +10 -0
  54. data/reference/rdoc/fr_method_index.html +66 -0
  55. data/reference/rdoc/index.html +1 -0
  56. data/reference/rdoc/rdoc-style.css +320 -0
  57. metadata +111 -0
@@ -0,0 +1,145 @@
1
+ # This example demonstrates the use of the TextInput functionality.
2
+ # One can tab through, or click into the text fields and change it's contents.
3
+
4
+ # At its most basic form, you only need to create a new TextInput instance and
5
+ # set the text_input attribute of your window to it. Until you set this
6
+ # attribute to nil again, the TextInput object will build a text that can be
7
+ # accessed via TextInput#text.
8
+
9
+ # The TextInput object also maintains the position of the caret as the index
10
+ # of the character that it's left to via the caret_pos attribute. Furthermore,
11
+ # if there is a selection, the selection_start attribute yields its beginning,
12
+ # using the same indexing scheme. If there is no selection, selection_start
13
+ # is equal to caret_pos.
14
+
15
+ # A TextInput object is purely abstract, though; drawing the input field is left
16
+ # to the user. In this case, we are subclassing TextInput to add this code.
17
+ # As with most of Gosu, how this is handled is completely left open; the scheme
18
+ # presented here is not mandatory! Gosu only aims to provide enough code for
19
+ # games (or intermediate UI toolkits) to be built upon it.
20
+
21
+ begin
22
+ # In case you use Gosu via RubyGems.
23
+ require 'rubygems'
24
+ rescue LoadError
25
+ # In case you don't.
26
+ end
27
+
28
+ require 'gosu'
29
+
30
+ class TextField < Gosu::TextInput
31
+ # Some constants that define our appearance.
32
+ INACTIVE_COLOR = 0xcc666666
33
+ ACTIVE_COLOR = 0xccff6666
34
+ SELECTION_COLOR = 0xcc0000ff
35
+ CARET_COLOR = 0xffffffff
36
+ PADDING = 5
37
+
38
+ attr_reader :x, :y
39
+
40
+ def initialize(window, font, x, y)
41
+ # TextInput's constructor doesn't expect any arguments.
42
+ super()
43
+
44
+ @window, @font, @x, @y = window, font, x, y
45
+
46
+ # Start with a self-explanatory text in each field.
47
+ self.text = "Click to change text"
48
+ end
49
+
50
+ # Example filter method. You can truncate the text to employ a length limit (watch out
51
+ # with Ruby 1.8 and UTF-8!), limit the text to certain characters etc.
52
+ def filter text
53
+ text.upcase
54
+ end
55
+
56
+ def draw
57
+ # Depending on whether this is the currently selected input or not, change the
58
+ # background's color.
59
+ if @window.text_input == self then
60
+ background_color = ACTIVE_COLOR
61
+ else
62
+ background_color = INACTIVE_COLOR
63
+ end
64
+ @window.draw_quad(x - PADDING, y - PADDING, background_color,
65
+ x + width + PADDING, y - PADDING, background_color,
66
+ x - PADDING, y + height + PADDING, background_color,
67
+ x + width + PADDING, y + height + PADDING, background_color, 0)
68
+
69
+ # Calculate the position of the caret and the selection start.
70
+ pos_x = x + @font.text_width(self.text[0...self.caret_pos])
71
+ sel_x = x + @font.text_width(self.text[0...self.selection_start])
72
+
73
+ # Draw the selection background, if any; if not, sel_x and pos_x will be
74
+ # the same value, making this quad empty.
75
+ @window.draw_quad(sel_x, y, SELECTION_COLOR,
76
+ pos_x, y, SELECTION_COLOR,
77
+ sel_x, y + height, SELECTION_COLOR,
78
+ pos_x, y + height, SELECTION_COLOR, 0)
79
+
80
+ # Draw the caret; again, only if this is the currently selected field.
81
+ if @window.text_input == self then
82
+ @window.draw_line(pos_x, y, CARET_COLOR,
83
+ pos_x, y + height, CARET_COLOR, 0)
84
+ end
85
+
86
+ # Finally, draw the text itself!
87
+ @font.draw(self.text, x, y, 0)
88
+ end
89
+
90
+ # This text field grows with the text that's being entered.
91
+ # (Usually one would use clip_to and scroll around on the text field.)
92
+ def width
93
+ @font.text_width(self.text)
94
+ end
95
+
96
+ def height
97
+ @font.height
98
+ end
99
+
100
+ # Hit-test for selecting a text field with the mouse.
101
+ def under_point?(mouse_x, mouse_y)
102
+ mouse_x > x - PADDING and mouse_x < x + width + PADDING and
103
+ mouse_y > y - PADDING and mouse_y < y + height + PADDING
104
+ end
105
+ end
106
+
107
+ class TextInputWindow < Gosu::Window
108
+ def initialize
109
+ super(300, 200, false)
110
+ self.caption = "Text Input Example"
111
+
112
+ font = Gosu::Font.new(self, Gosu::default_font_name, 20)
113
+
114
+ # Set up an array of three text fields.
115
+ @text_fields = Array.new(3) { |index| TextField.new(self, font, 50, 30 + index * 50) }
116
+
117
+ @cursor = Gosu::Image.new(self, "media/Cursor.png", false)
118
+ end
119
+
120
+ def draw
121
+ @text_fields.each { |tf| tf.draw }
122
+ @cursor.draw(mouse_x, mouse_y, 0)
123
+ end
124
+
125
+ def button_down(id)
126
+ if id == Gosu::KbTab then
127
+ # Tab key will not be 'eaten' by text fields; use for switching through
128
+ # text fields.
129
+ index = @text_fields.index(self.text_input) || -1
130
+ self.text_input = @text_fields[(index + 1) % @text_fields.size]
131
+ elsif id == Gosu::KbEscape then
132
+ # Escape key will not be 'eaten' by text fields; use for deselecting.
133
+ if self.text_input then
134
+ self.text_input = nil
135
+ else
136
+ close
137
+ end
138
+ elsif id == Gosu::MsLeft then
139
+ # Mouse click: Select text field based on mouse position.
140
+ self.text_input = @text_fields.find { |tf| tf.under_point?(mouse_x, mouse_y) }
141
+ end
142
+ end
143
+ end
144
+
145
+ TextInputWindow.new.show
@@ -0,0 +1,137 @@
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
+ require 'gosu'
9
+
10
+ module ZOrder
11
+ Background, Stars, Player, UI = *0..3
12
+ end
13
+
14
+ class Player
15
+ attr_reader :score
16
+
17
+ def initialize(window)
18
+ @image = Gosu::Image.new(window, "media/Starfighter.bmp", false)
19
+ @beep = Gosu::Sample.new(window, "media/Beep.wav")
20
+ @x = @y = @vel_x = @vel_y = @angle = 0.0
21
+ @score = 0
22
+ end
23
+
24
+ def warp(x, y)
25
+ @x, @y = x, y
26
+ end
27
+
28
+ def turn_left
29
+ @angle -= 4.5
30
+ end
31
+
32
+ def turn_right
33
+ @angle += 4.5
34
+ end
35
+
36
+ def accelerate
37
+ @vel_x += Gosu::offset_x(@angle, 0.5)
38
+ @vel_y += Gosu::offset_y(@angle, 0.5)
39
+ end
40
+
41
+ def move
42
+ @x += @vel_x
43
+ @y += @vel_y
44
+ @x %= 640
45
+ @y %= 480
46
+
47
+ @vel_x *= 0.95
48
+ @vel_y *= 0.95
49
+ end
50
+
51
+ def draw
52
+ @image.draw_rot(@x, @y, ZOrder::Player, @angle)
53
+ end
54
+
55
+ def collect_stars(stars)
56
+ stars.reject! do |star|
57
+ if Gosu::distance(@x, @y, star.x, star.y) < 35 then
58
+ @score += 10
59
+ @beep.play
60
+ true
61
+ else
62
+ false
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ class Star
69
+ attr_reader :x, :y
70
+
71
+ def initialize(animation)
72
+ @animation = animation
73
+ @color = Gosu::Color.new(0xff000000)
74
+ @color.red = rand(255 - 40) + 40
75
+ @color.green = rand(255 - 40) + 40
76
+ @color.blue = rand(255 - 40) + 40
77
+ @x = rand * 640
78
+ @y = rand * 480
79
+ end
80
+
81
+ def draw
82
+ img = @animation[Gosu::milliseconds / 100 % @animation.size]
83
+ img.draw(@x - img.width / 2.0, @y - img.height / 2.0,
84
+ ZOrder::Stars, 1, 1, @color, :additive)
85
+ end
86
+ end
87
+
88
+ class GameWindow < Gosu::Window
89
+ def initialize
90
+ super(640, 480, false)
91
+ self.caption = "Gosu Tutorial Game"
92
+
93
+ @background_image = Gosu::Image.new(self, "media/Space.png", true)
94
+
95
+ @player = Player.new(self)
96
+ @player.warp(320, 240)
97
+
98
+ @star_anim = Gosu::Image::load_tiles(self, "media/Star.png", 25, 25, false)
99
+ @stars = Array.new
100
+
101
+ @font = Gosu::Font.new(self, Gosu::default_font_name, 20)
102
+ end
103
+
104
+ def update
105
+ if button_down? Gosu::KbLeft or button_down? Gosu::GpLeft then
106
+ @player.turn_left
107
+ end
108
+ if button_down? Gosu::KbRight or button_down? Gosu::GpRight then
109
+ @player.turn_right
110
+ end
111
+ if button_down? Gosu::KbUp or button_down? Gosu::GpButton0 then
112
+ @player.accelerate
113
+ end
114
+ @player.move
115
+ @player.collect_stars(@stars)
116
+
117
+ if rand(100) < 4 and @stars.size < 25 then
118
+ @stars.push(Star.new(@star_anim))
119
+ end
120
+ end
121
+
122
+ def draw
123
+ @background_image.draw(0, 0, ZOrder::Background)
124
+ @player.draw
125
+ @stars.each { |star| star.draw }
126
+ @font.draw("Score: #{@player.score}", 10, 10, ZOrder::UI, 1.0, 1.0, 0xffffff00)
127
+ end
128
+
129
+ def button_down(id)
130
+ if id == Gosu::KbEscape then
131
+ close
132
+ end
133
+ end
134
+ end
135
+
136
+ window = GameWindow.new
137
+ window.show
Binary file
@@ -0,0 +1,25 @@
1
+ #....................................................#
2
+ #....................................................#
3
+ #.............xx......x.x............................#
4
+ #............x..x....................................#
5
+ #x....x...x..x.......#####..xxx....................x.#
6
+ #.x.........................xxx.........##.........x.#
7
+ #...............""..........###...##..........##.....#
8
+ #..##..###..##..##...................................#
9
+ #........................................xx........###
10
+ #.............................###....................#
11
+ ##....##.............................................#
12
+ #....................##....##......##....##....##....#
13
+ #.................................................x..#
14
+ #...x....##....##.......x...x.....................x..#
15
+ #.....x...............x...x...x...................x..#
16
+ #......x...##.....##.................................#
17
+ #.......x.........................................#..#
18
+ #...........##........#...#...#..#.......x...........#
19
+ #...#................................................#
20
+ #....."""".................x.......#..#####...###....#
21
+ #x....#......................##......................#
22
+ #"""""#.....#.....x..................#...............#
23
+ ##xxxx......#........................................#
24
+ ##xxxx...#####............."...""""".................#
25
+ ######"""#############################################
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,19 @@
1
+ require 'rbconfig'
2
+
3
+ begin
4
+ if defined? NSObject then
5
+ require "#{File.dirname(__FILE__)}/gosu.for_macruby.bundle"
6
+ require "#{File.dirname(__FILE__)}/hotgosu.rb"
7
+ elsif defined? RUBY_VERSION and RUBY_VERSION[0..2] == '1.9' then
8
+ require "#{File.dirname(__FILE__)}/gosu.for_1_9.#{Config::CONFIG['DLEXT']}"
9
+ require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
10
+ else
11
+ require "#{File.dirname(__FILE__)}/gosu.for_1_8.#{Config::CONFIG['DLEXT']}"
12
+ require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
13
+ end
14
+ rescue LoadError => e
15
+ require "#{File.dirname(__FILE__)}/gosu.custom.#{Config::CONFIG['DLEXT']}"
16
+ require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
17
+ end
18
+
19
+ require "#{File.dirname(__FILE__)}/gosu/patches.rb"
@@ -0,0 +1,64 @@
1
+ # Extend Numeric with simple angle conversion methods.
2
+ class ::Numeric
3
+ def degrees_to_radians
4
+ self * Math::PI / 180.0
5
+ end
6
+ def radians_to_degrees
7
+ self * 180.0 / Math::PI
8
+ end
9
+ def gosu_to_radians
10
+ (self - 90) * Math::PI / 180.0
11
+ end
12
+ def radians_to_gosu
13
+ self * 180.0 / Math::PI + 90
14
+ end
15
+ end
16
+
17
+ # Backwards compatibility: import the constants into Gosu::Button.
18
+ module Gosu::Button
19
+ Gosu.constants.each { |c| const_set(c, Gosu.const_get(c)) }
20
+ end
21
+
22
+ # Backwards compatibility: Window arguments to Sample and Song
23
+ class Gosu::Sample
24
+ alias new_initialize initialize
25
+
26
+ def initialize(*args)
27
+ args.shift if args.first.is_a? Gosu::Window
28
+ new_initialize *args
29
+ end
30
+ end
31
+ class Gosu::Song
32
+ alias new_initialize initialize
33
+
34
+ def initialize(*args)
35
+ args.shift if args.first.is_a? Gosu::Window
36
+ new_initialize *args
37
+ end
38
+ end
39
+
40
+ # Color constants (SWIG messes up constants somehow)
41
+ class Gosu::Color
42
+ NONE = Gosu::Color.new(0x00000000)
43
+ BLACK = Gosu::Color.new(0xff000000)
44
+ GRAY = Gosu::Color.new(0xff808080)
45
+ WHITE = Gosu::Color.new(0xffffffff)
46
+ AQUA = Gosu::Color.new(0xff00ffff)
47
+ RED = Gosu::Color.new(0xffff0000)
48
+ GREEN = Gosu::Color.new(0xff00ff00)
49
+ BLUE = Gosu::Color.new(0xff0000ff)
50
+ YELLOW = Gosu::Color.new(0xffffff00)
51
+ FUCHSIA = Gosu::Color.new(0xffff00ff)
52
+ CYAN = Gosu::Color.new(0xff00ffff)
53
+ end
54
+
55
+ # Instance methods for button_id_to_char and char_to_button_id
56
+ class Gosu::Window
57
+ def button_id_to_char(id)
58
+ self.class.button_id_to_char(id)
59
+ end
60
+
61
+ def char_to_button_id(ch)
62
+ self.class.char_to_button_id(ch)
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ # SWIG workarounds
2
+ # These are offloaded into a separate file because rb_eval_string() is weird on Ruby 1.8.
3
+
4
+ # SWIG doesn't understand the C++ overloading.
5
+ class Gosu::Image
6
+ def self.from_text(*args)
7
+ args.size == 4 ? from_text4(*args) : from_text7(*args)
8
+ end
9
+ end
10
+
11
+ # Linux workaround: instead of declaring a constant, we declare a hidden function and
12
+ # call it when we need to define the constant. Otherwise, we get a weird libGL.so segfault.
13
+ module Gosu
14
+ def self.const_missing sym
15
+ if sym == :MAX_TEXTURE_SIZE then
16
+ const_set sym, __max_texture_size
17
+ else
18
+ super
19
+ end
20
+ end
21
+ end