gosu_extensions 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
data/bin/gogogosu ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/local/bin/ruby
2
+ # TODO remove
3
+
4
+ Signal.trap("INT") { puts; exit } # CTRL-C
5
+
6
+ File.open(File.join(File.dirname(__FILE__), '../VERSION')) do |f|
7
+ puts "Gosu Extensions #{f.read}"
8
+ end
9
+
10
+ application = ARGV.first
11
+
12
+ puts "Usage: gogogosu <application_name>" and exit(1) unless application
13
+
14
+ require File.dirname(__FILE__) + '/../generator/gogogosu'
15
+
16
+ generator = Generator::Gogogosu.new
17
+
18
+ generator.dir application do
19
+ generator.dir 'lib' do
20
+
21
+ end
22
+ generator.dir 'media' do
23
+
24
+ end
25
+ end
26
+
27
+ puts <<-START
28
+ Great!
29
+
30
+ Now proceed as follows:
31
+ 1. cd #{application}
32
+ 2.
33
+ START
@@ -0,0 +1,47 @@
1
+ #
2
+ #
3
+ class Background
4
+
5
+ #
6
+ #
7
+ attr_reader :window, :draw_function
8
+
9
+ #
10
+ #
11
+ def initialize window
12
+ @window = window
13
+ @draw_function = functionify window.background_options
14
+ end
15
+
16
+ def functionify path_or_color
17
+ Gosu::Color === path_or_color ? color_draw_function(path_or_color) : image_draw_function(path_or_color)
18
+ end
19
+
20
+ #
21
+ #
22
+ def color_draw_function color
23
+ lambda do
24
+ window.draw_quad(0, 0, color,
25
+ window.width, 0, color,
26
+ window.width, window.height, color,
27
+ 0, window.height, color,
28
+ 0, :default)
29
+ end
30
+ end
31
+
32
+ #
33
+ #
34
+ def image_draw_function path
35
+ image = Gosu::Image.new window, File.join(Resources.root, path), true
36
+ lambda do
37
+ image.draw 0, 0, Layer::Background, 1.0, 1.0
38
+ end
39
+ end
40
+
41
+ #
42
+ #
43
+ def draw
44
+ draw_function.call
45
+ end
46
+
47
+ end
@@ -48,15 +48,16 @@ class Collision
48
48
  #
49
49
  def complex_package definition
50
50
  lambda do |this_shape, that_shape|
51
- this_that = Array.new(2)
51
+ this_that = Array.new 2
52
52
  window.moveables.each do |moveable|
53
53
  if moveable.shape == this_shape
54
54
  this_that[0] = moveable
55
+ break if this_that.all?
55
56
  end
56
57
  if moveable.shape == that_shape
57
58
  this_that[1] = moveable
59
+ break if this_that.all?
58
60
  end
59
- break if this_that.all?
60
61
  end
61
62
  definition.call *this_that
62
63
  end
@@ -25,15 +25,14 @@ class GameWindow < Gosu::Window
25
25
  :caption,
26
26
  :screen_width,
27
27
  :screen_height,
28
- :gravity_vector
28
+ :gravity_vector,
29
+ :background_options
29
30
  attr_reader :environment,
30
31
  :moveables,
31
32
  :font,
32
33
  :scheduling,
33
34
  :collisions
34
- attr_accessor :background_path,
35
- :background_hard_borders,
36
- :stop_condition,
35
+ attr_accessor :stop_condition,
37
36
  :proceed_condition
38
37
 
39
38
  def initialize
@@ -117,6 +116,9 @@ class GameWindow < Gosu::Window
117
116
  def gravity_vector
118
117
  @gravity_vector || @gravity_vector = CP::Vec2.new(0, 0.98/SUBSTEPS)
119
118
  end
119
+ def background_options
120
+ Gosu::Color::WHITE
121
+ end
120
122
 
121
123
  class << self
122
124
  def gravity amount = 0.98
@@ -150,10 +152,10 @@ class GameWindow < Gosu::Window
150
152
  self.font_size = size
151
153
  end
152
154
  end
153
- def background path, options = {}
155
+ def background path_or_color = Gosu::Color::WHITE
156
+ attr_reader :background_options
154
157
  InitializerHooks.register self do
155
- self.background_path = path
156
- self.background_hard_borders = options[:hard_borders] || false
158
+ self.background_options = path_or_color
157
159
  end
158
160
  end
159
161
  def full_screen
@@ -206,9 +208,7 @@ class GameWindow < Gosu::Window
206
208
  self.caption = self.class.caption || ""
207
209
  end
208
210
  def setup_background
209
- if self.background_path
210
- @background_image = Gosu::Image.new self, File.join(Resources.root, self.background_path), self.background_hard_borders
211
- end
211
+ @background = Background.new self
212
212
  end
213
213
  def setup_moveables
214
214
  @moveables = Moveables.new
@@ -442,7 +442,7 @@ class GameWindow < Gosu::Window
442
442
  # Draws a background image.
443
443
  #
444
444
  def draw_background
445
- @background_image.draw 0, 0, Layer::Background, 1.0, 1.0 if @background_image
445
+ @background.draw
446
446
  end
447
447
  # Draw ambient objects, like asteroids or the like that do not influence the player.
448
448
  #
@@ -460,16 +460,6 @@ class GameWindow < Gosu::Window
460
460
  def draw_ui
461
461
  @uis.each(&:draw_ui)
462
462
  end
463
- #
464
- #
465
- # Example:
466
- # imprint do
467
- # circle x, y, radius, :fill => true, :color => :black
468
- # end
469
- #
470
- def imprint &block
471
- @background_image.paint &block
472
- end
473
463
 
474
464
  # Input handling.
475
465
  #
@@ -0,0 +1,6 @@
1
+ module Rotation
2
+
3
+ Half = Math::HalfPI
4
+ Quarter = Math::QuarterPI
5
+
6
+ end
@@ -0,0 +1,7 @@
1
+ module Math
2
+
3
+ HalfPI = PI/2
4
+ ThirdPI = PI/3
5
+ QuarterPI = PI/4
6
+
7
+ end
@@ -17,17 +17,20 @@ end
17
17
  $:.unshift File.join(File.dirname(__FILE__), '/extensions')
18
18
  require 'module'
19
19
  require 'numeric'
20
+ require 'math'
20
21
 
21
22
  $:.unshift File.join(File.dirname(__FILE__), '/core')
22
23
  require 'resources'
23
24
 
24
25
  require 'vector_utilities'
26
+ require 'rotation'
25
27
  require 'initializer_hooks'
26
28
 
27
29
  require 'trait'
28
30
  require 'traits'
29
31
  require 'it_is_a'
30
32
 
33
+ require 'background'
31
34
  require 'moveables'
32
35
  require 'remove_shapes'
33
36
  require 'wave'
@@ -1,5 +1,32 @@
1
1
  module Shooter extend Trait
2
2
 
3
+ module Position
4
+ def self.front x, y = nil
5
+ # y || (y, x = x, 0)
6
+ y ||= 0
7
+ relative x, y
8
+ end
9
+ def self.relative x, y
10
+ relative_position = CP::Vec2.new x, y
11
+ relative_length = relative_position.length
12
+ relative_rotation = relative_position.to_angle
13
+ lambda { self.position + (self.rotation - relative_rotation).radians_to_vec2*relative_length }
14
+ end
15
+ end
16
+ module Velocity
17
+ def self.front initial_speed
18
+ lambda { |_| self.rotation_vector*initial_speed }
19
+ end
20
+ end
21
+ module Rotation
22
+ def self.custom rotation; lambda { |_| rotation } end
23
+ Frontal = lambda { |_| self.rotation }
24
+ Right = lambda { |_| self.rotation + Rotation::Half }
25
+ Backwards = lambda { |_| -self.rotation }
26
+ Left = lambda { |_| self.rotation - Rotation::Half }
27
+ Default = Frontal
28
+ end
29
+
3
30
  Shoot = :shoot
4
31
 
5
32
  manual <<-MANUAL
@@ -51,17 +78,20 @@ module Shooter extend Trait
51
78
  self.shot_type = type
52
79
  end
53
80
  end
54
- def muzzle_position &block
81
+ def muzzle_position lam = nil, &block
82
+ block ||= lam
55
83
  InitializerHooks.register self do
56
84
  muzzle_position_func &block
57
85
  end
58
86
  end
59
- def muzzle_velocity &block
87
+ def muzzle_velocity lam = nil, &block
88
+ block ||= lam
60
89
  InitializerHooks.register self do
61
90
  muzzle_velocity_func &block
62
91
  end
63
92
  end
64
- def muzzle_rotation &block
93
+ def muzzle_rotation lam = nil, &block
94
+ block ||= lam
65
95
  InitializerHooks.register self do
66
96
  muzzle_rotation_func &block
67
97
  end
data/lib/units/sprite.rb CHANGED
@@ -28,7 +28,7 @@ class Sprite
28
28
  # Default rotation is upwards.
29
29
  #
30
30
  def rotation
31
- @rotation || -Math::PI/2
31
+ @rotation || -Rotation::Half
32
32
  end
33
33
 
34
34
  class << self
@@ -44,11 +44,9 @@ class Sprite
44
44
  #
45
45
  #
46
46
  def rotation amount = nil, &block
47
- # Override default.
48
- #
49
- to_execute = block || lambda { amount }
47
+ block ||= lambda { amount }
50
48
  InitializerHooks.append self do
51
- self.rotation = to_execute[]
49
+ self.rotation = block[]
52
50
  end
53
51
  end
54
52
  def random_rotation
@@ -148,7 +146,7 @@ class Sprite
148
146
  self.rotation.radians_to_vec2
149
147
  end
150
148
  def current_speed
151
- speed.length
149
+ speed.length # Hm, speed should already be the absolute value.
152
150
  end
153
151
 
154
152
  # Movement and Position.
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 7
9
- version: 0.2.7
8
+ - 8
9
+ version: 0.2.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-12 00:00:00 +02:00
19
- default_executable:
18
+ date: 2010-04-13 00:00:00 +02:00
19
+ default_executable: gogogosu
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: gosu
@@ -44,8 +44,8 @@ dependencies:
44
44
  version_requirements: *id002
45
45
  description: ""
46
46
  email: florian.hanke@gmail.com
47
- executables: []
48
-
47
+ executables:
48
+ - gogogosu
49
49
  extensions: []
50
50
 
51
51
  extra_rdoc_files: []
@@ -54,6 +54,7 @@ files:
54
54
  - Rakefile
55
55
  - VERSION
56
56
  - generator/gogogosu.rb
57
+ - lib/core/background.rb
57
58
  - lib/core/collision.rb
58
59
  - lib/core/control.rb
59
60
  - lib/core/controls.rb
@@ -65,12 +66,14 @@ files:
65
66
  - lib/core/moveables.rb
66
67
  - lib/core/remove_shapes.rb
67
68
  - lib/core/resources.rb
69
+ - lib/core/rotation.rb
68
70
  - lib/core/scheduling.rb
69
71
  - lib/core/trait.rb
70
72
  - lib/core/traits.rb
71
73
  - lib/core/vector_utilities.rb
72
74
  - lib/core/wave.rb
73
75
  - lib/core/waves.rb
76
+ - lib/extensions/math.rb
74
77
  - lib/extensions/module.rb
75
78
  - lib/extensions/numeric.rb
76
79
  - lib/gosu_extensions.rb