gosu 0.7.7-universal-darwin9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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::Button::KbLeft or button_down? Gosu::Button::GpLeft then
106
+ @player.turn_left
107
+ end
108
+ if button_down? Gosu::Button::KbRight or button_down? Gosu::Button::GpRight then
109
+ @player.turn_right
110
+ end
111
+ if button_down? Gosu::Button::KbUp or button_down? Gosu::Button::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::Button::KbEscape then
131
+ close
132
+ end
133
+ end
134
+ end
135
+
136
+ window = GameWindow.new
137
+ window.show
data/lib/gosu.bundle ADDED
Binary file
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: gosu
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.7.7
7
+ date: 2007-11-06 00:00:00 +01:00
8
+ summary: 2D game development library.
9
+ require_paths:
10
+ - lib
11
+ email: julian@raschke.de
12
+ homepage: http://code.google.com/p/gosu/
13
+ rubyforge_project:
14
+ description: 2D game development library. The library features easy to use and game-friendly interfaces to 2D graphics and text (accelerated by 3D hardware), sound samples and music as well as keyboard, mouse and gamepad/joystick input. Includes demos for integration with RMagick, Chipmunk and Ruby-OpenGL.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.1
24
+ version:
25
+ platform: universal-darwin9.0
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Julian Raschke
31
+ - Jan Luecker
32
+ files:
33
+ - lib/gosu.bundle
34
+ - README
35
+ - LICENSE
36
+ - examples/ChipmunkIntegration.rb
37
+ - examples/CptnRuby.rb
38
+ - examples/OpenGLIntegration.rb
39
+ - examples/RMagickIntegration.rb
40
+ - examples/Tutorial.rb
41
+ test_files: []
42
+
43
+ rdoc_options: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ requirements: []
52
+
53
+ dependencies: []
54
+