gosu 0.7.20-universal-darwin → 0.7.21-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Shows how to
4
4
  # * implement jumping/gravity
5
- # * implement scrolling
5
+ # * implement scrolling using Window#translate
6
6
  # * implement a simple tile-based map
7
7
  # * load levels from primitive text files
8
8
 
@@ -25,14 +25,15 @@
25
25
  # ...Enemies, a more sophisticated object system, weapons, title and credits
26
26
  # screens...
27
27
 
28
- begin
29
- # In case you use Gosu via rubygems.
30
- require 'rubygems'
31
- rescue LoadError
32
- # In case you don't.
33
- end
34
-
35
- require 'gosu'
28
+ require '../lib/gosu'
29
+ # begin
30
+ # # In case you use Gosu via rubygems.
31
+ # require 'rubygems'
32
+ # rescue LoadError
33
+ # # In case you don't.
34
+ # end
35
+ #
36
+ # require 'gosu'
36
37
  include Gosu
37
38
 
38
39
  module Tiles
@@ -48,10 +49,9 @@ class CollectibleGem
48
49
  @x, @y = x, y
49
50
  end
50
51
 
51
- def draw(screen_x, screen_y)
52
+ def draw
52
53
  # Draw, slowly rotating
53
- @image.draw_rot(@x - screen_x, @y - screen_y, 0,
54
- 25 * Math.sin(milliseconds / 133.7))
54
+ @image.draw_rot(@x, @y, 0, 25 * Math.sin(milliseconds / 133.7))
55
55
  end
56
56
  end
57
57
 
@@ -72,7 +72,7 @@ class CptnRuby
72
72
  @cur_image = @standing
73
73
  end
74
74
 
75
- def draw(screen_x, screen_y)
75
+ def draw
76
76
  # Flip vertically when facing to the left.
77
77
  if @dir == :left then
78
78
  offs_x = -25
@@ -81,7 +81,7 @@ class CptnRuby
81
81
  offs_x = 25
82
82
  factor = -1.0
83
83
  end
84
- @cur_image.draw(@x - screen_x + offs_x, @y - screen_y - 49, 0, factor, 1.0)
84
+ @cur_image.draw(@x + offs_x, @y - 49, 0, factor, 1.0)
85
85
  end
86
86
 
87
87
  # Could the object be placed at x + offs_x/y + offs_y without being stuck?
@@ -146,7 +146,6 @@ class Map
146
146
  def initialize(window, filename)
147
147
  # Load 60x60 tiles, 5px overlap in all four directions.
148
148
  @tileset = Image.load_tiles(window, "media/CptnRuby Tileset.png", 60, 60, true)
149
- @sky = Image.new(window, "media/Space.png", true)
150
149
 
151
150
  gem_img = Image.new(window, "media/CptnRuby Gem.png", false)
152
151
  @gems = []
@@ -171,11 +170,7 @@ class Map
171
170
  end
172
171
  end
173
172
 
174
- def draw(screen_x, screen_y)
175
- # Sigh, stars!
176
- @sky.draw(0, 0, 0)
177
-
178
-
173
+ def draw
179
174
  # Very primitive drawing function:
180
175
  # Draws all the tiles, some off-screen, some on-screen.
181
176
  @height.times do |y|
@@ -184,11 +179,11 @@ class Map
184
179
  if tile
185
180
  # Draw the tile with an offset (tile images have some overlap)
186
181
  # Scrolling is implemented here just as in the game objects.
187
- @tileset[tile].draw(x * 50 - screen_x - 5, y * 50 - screen_y - 5, 0)
182
+ @tileset[tile].draw(x * 50 - 5, y * 50 - 5, 0)
188
183
  end
189
184
  end
190
185
  end
191
- @gems.each { |c| c.draw(screen_x, screen_y) }
186
+ @gems.each { |c| c.draw }
192
187
  end
193
188
 
194
189
  # Solid at a given pixel position?
@@ -203,10 +198,11 @@ class Game < Window
203
198
  def initialize
204
199
  super(640, 480, false)
205
200
  self.caption = "Cptn. Ruby"
201
+ @sky = Image.new(self, "media/Space.png", true)
206
202
  @map = Map.new(self, "media/CptnRuby Map.txt")
207
203
  @cptn = CptnRuby.new(self, 400, 100)
208
- # Scrolling is stored as the position of the top left corner of the screen.
209
- @screen_x = @screen_y = 0
204
+ # The scrolling position is stored as top left corner of the screen.
205
+ @camera_x = @camera_y = 0
210
206
  end
211
207
  def update
212
208
  move_x = 0
@@ -215,12 +211,15 @@ class Game < Window
215
211
  @cptn.update(move_x)
216
212
  @cptn.collect_gems(@map.gems)
217
213
  # Scrolling follows player
218
- @screen_x = [[@cptn.x - 320, 0].max, @map.width * 50 - 640].min
219
- @screen_y = [[@cptn.y - 240, 0].max, @map.height * 50 - 480].min
214
+ @camera_x = [[@cptn.x - 320, 0].max, @map.width * 50 - 640].min
215
+ @camera_y = [[@cptn.y - 240, 0].max, @map.height * 50 - 480].min
220
216
  end
221
217
  def draw
222
- @map.draw @screen_x, @screen_y
223
- @cptn.draw @screen_x, @screen_y
218
+ @sky.draw 0, 0, 0
219
+ translate(-@camera_x, -@camera_y) do
220
+ @map.draw
221
+ @cptn.draw
222
+ end
224
223
  end
225
224
  def button_down(id)
226
225
  if id == KbUp then @cptn.try_to_jump end
Binary file
Binary file
@@ -9,7 +9,7 @@ begin
9
9
  require "#{File.dirname(__FILE__)}/gosu.for_#{version}.#{Config::CONFIG['DLEXT']}"
10
10
  require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
11
11
  rescue LoadError => e
12
- require "#{File.dirname(__FILE__)}/gosu.custom.#{Config::CONFIG['DLEXT']}"
12
+ require "#{File.dirname(__FILE__)}/gosu.#{Config::CONFIG['DLEXT']}"
13
13
  require "#{File.dirname(__FILE__)}/gosu/swig_patches.rb"
14
14
  end
15
15
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.20
4
+ hash: 41
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 21
10
+ version: 0.7.21
5
11
  platform: universal-darwin
6
12
  authors:
7
13
  - Julian Raschke
@@ -10,7 +16,7 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2010-05-30 00:00:00 +08:00
19
+ date: 2010-06-13 00:00:00 +08:00
14
20
  default_executable:
15
21
  dependencies: []
16
22
 
@@ -62,21 +68,29 @@ rdoc_options: []
62
68
  require_paths:
63
69
  - lib
64
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
65
72
  requirements:
66
73
  - - ">="
67
74
  - !ruby/object:Gem::Version
75
+ hash: 51
76
+ segments:
77
+ - 1
78
+ - 8
79
+ - 2
68
80
  version: 1.8.2
69
- version:
70
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
71
83
  requirements:
72
84
  - - ">="
73
85
  - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
74
89
  version: "0"
75
- version:
76
90
  requirements: []
77
91
 
78
92
  rubyforge_project:
79
- rubygems_version: 1.3.5
93
+ rubygems_version: 1.3.7
80
94
  signing_key:
81
95
  specification_version: 3
82
96
  summary: 2D game development library.