lotu 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.18
1
+ 0.1.19
@@ -36,7 +36,7 @@ class Painting < Actor
36
36
  end
37
37
 
38
38
  class Example < Game
39
- use CollisionSystem
39
+ use_systems :collision
40
40
 
41
41
  def initialize
42
42
  super
@@ -14,8 +14,7 @@ include Lotu
14
14
  # Let's define a Missile class that will use a Steering system to
15
15
  # control it's movement
16
16
  class Missile < Actor
17
- use SteeringSystem
18
- use AnimationSystem
17
+ use_systems :steering, :animation
19
18
 
20
19
  def teleport(x, y)
21
20
  @pos.x, @pos.y = x, y
data/lib/lotu.rb CHANGED
@@ -1,10 +1,38 @@
1
+ # Get the path to this file to reference the lotu folder and stuff it
2
+ # in the front of $LOAD_PATH so our relative requires are found
3
+ # quickly without problems
1
4
  LOTU_ROOT = File.expand_path(File.join(File.dirname(__FILE__), 'lotu'))
2
5
  $LOAD_PATH.unshift(LOTU_ROOT)
3
6
 
4
7
  require 'rubygems'
5
8
  require 'gosu'
6
- %w{vector2d string kernel util}.each{|file| require "helpers/#{file}"}
7
- %w{resource_manager system_user collidable controllable eventful}.each{|file| require "behaviors/#{file}"}
8
- %w{base interpolation animation input_manager stalker collision steering}.map{|s| "#{s}_system"}.each{|file| require "systems/#{file}"}
9
- %w{behavior actor cursor text_box game}.each{|file| require file}
9
+
10
+ # Load helper files
11
+ ['vector2d',
12
+ 'string',
13
+ 'kernel',
14
+ 'util'].each{|file| require "helpers/#{file}"}
15
+
16
+ # Load behavior files
17
+ ['resource_manager',
18
+ 'system_user',
19
+ 'collidable',
20
+ 'controllable',
21
+ 'eventful'].each{|file| require "behaviors/#{file}"}
22
+
23
+ # Load system files
24
+ ['base',
25
+ 'interpolation',
26
+ 'animation',
27
+ 'input_manager',
28
+ 'stalker',
29
+ 'collision',
30
+ 'steering'].map{|s| "#{s}_system"}.each{|file| require "systems/#{file}"}
31
+
32
+ # Load core files
33
+ ['behavior',
34
+ 'actor',
35
+ 'cursor',
36
+ 'text_box',
37
+ 'game'].each{|file| require file}
10
38
 
data/lib/lotu/actor.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Lotu
2
- class Actor
2
+ class Actor < GameEntity
3
3
  include Lotu::Helpers::Util
4
4
  extend Lotu::Behavior
5
5
 
@@ -15,7 +15,7 @@ module Lotu
15
15
 
16
16
  def initialize(opts={})
17
17
  # if debug is set, print out class info
18
- class_debug_info
18
+ class_debug_info if $lotu.debug
19
19
 
20
20
  default_opts = {
21
21
  :x => 0,
@@ -43,7 +43,7 @@ module Lotu
43
43
  init_behavior opts
44
44
 
45
45
  # if debug is set, print out instance info
46
- instance_debug_info
46
+ instance_debug_info if $lotu.debug
47
47
  end
48
48
 
49
49
  # Easy access to delta-time
@@ -60,6 +60,7 @@ module Lotu
60
60
  @center_y = opts[:center_y] || @center_y
61
61
  @factor_x = opts[:factor_x] || @factor_x
62
62
  @factor_y = opts[:factor_y] || @factor_y
63
+ @width = opts[:width]
63
64
  @color = opts[:color] || @color
64
65
  if @color.kind_of?(Integer)
65
66
  @color = Gosu::Color.new(opts[:color])
@@ -67,6 +68,10 @@ module Lotu
67
68
  @mode = opts[:mode] || @mode
68
69
  end
69
70
 
71
+ def factor= factor
72
+ @factor_x = @factor_y = factor
73
+ end
74
+
70
75
  def rand_color
71
76
  Gosu::Color.from_hsv(rand(360), 1, 1)
72
77
  end
@@ -12,6 +12,7 @@ module Lotu
12
12
  @default_font = Hash.new{ |h,k| h[k] = Gosu::Font.new( self, Gosu::default_font_name, k ) }
13
13
  end
14
14
 
15
+ # TODO: cambiar a Image['hola.png']
15
16
  def image( name )
16
17
  @images[name]
17
18
  end
@@ -7,6 +7,8 @@ module Lotu
7
7
  base.extend ClassMethods
8
8
  end
9
9
 
10
+ # PONDER: Cambiar por initialize? y controlar el punto de llamado
11
+ # con super?
10
12
  def init_behavior user_opts
11
13
  super if defined? super
12
14
  @systems ||= Hash.new
@@ -40,6 +42,23 @@ module Lotu
40
42
 
41
43
  # Allows to activate a system in the host
42
44
  module ClassMethods
45
+ # specify the systems you want to use, using symbols
46
+ # instead of module names
47
+ def use_systems *system_names
48
+ system_names.each do |system_name|
49
+ if system_name.is_a? Symbol
50
+ use Lotu.const_get("#{system_name.capitalize}System")
51
+ elsif system_name.is_a? Hash
52
+ system_name.each do |key,value|
53
+ use Lotu.const_get("#{key.capitalize}System"), value
54
+ end
55
+ else
56
+ raise "Unsupported system name as #{system_name.class}"
57
+ end
58
+ end
59
+ end
60
+
61
+ # specify the systems you want to use, using module names
43
62
  def use( klass, opts={} )
44
63
  behavior_options[SystemUser] ||= Hash.new
45
64
  behavior_options[SystemUser][klass] = opts
data/lib/lotu/cursor.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Provides a mouse pointer usable through mouse or keyboard
2
2
  module Lotu
3
3
  class Cursor < Actor
4
- use InterpolationSystem
4
+ use_systems :interpolation
5
5
 
6
6
  attr_reader :clicked_x, :clicked_y
7
7
  attr_accessor :speed, :use_mouse
data/lib/lotu/game.rb CHANGED
@@ -40,7 +40,7 @@ module Lotu
40
40
  setup_containers
41
41
 
42
42
  # if debug is set, print out class info
43
- class_debug_info
43
+ class_debug_info if @debug
44
44
 
45
45
  # call the Gosu::Window constructor
46
46
  super(opts[:width], opts[:height], opts[:fullscreen])
@@ -58,7 +58,7 @@ module Lotu
58
58
  setup_events
59
59
 
60
60
  # if debug is set, print out instance info
61
- instance_debug_info
61
+ instance_debug_info if @debug
62
62
  end
63
63
 
64
64
  def fps
@@ -0,0 +1,6 @@
1
+ class GameEntity
2
+
3
+ def draw; end
4
+ def update; end
5
+
6
+ end
@@ -129,11 +129,20 @@ module Lotu
129
129
  dot(vector) > 0
130
130
  end
131
131
 
132
+ def rotate radians
133
+ new_x = @x * Math.cos(radians) - @y * Math.sin(radians)
134
+ new_y = @y * Math.cos(radians) + @x * Math.sin(radians)
135
+ #self.x = new_x
136
+ #self.y = new_y
137
+ #self
138
+ Vector2d.new( new_x, new_y )
139
+ end
140
+
132
141
  def to_s
133
142
  # TODO tratar de reducir la cantidad de vectores creados, al
134
143
  # menos cuando no se está moviendo
135
144
  #format('%d %.2f, %.2f', object_id, @x, @y)
136
- format('%.2f, %.2f', @x, @y)
145
+ format('<%.2f, %.2f>', @x, @y)
137
146
  end
138
147
 
139
148
  end
@@ -2,8 +2,11 @@
2
2
  module Lotu
3
3
  class InterpolationSystem < BaseSystem
4
4
 
5
+ attr_accessor :interpolations
6
+
5
7
  def initialize(user, opts={})
6
8
  super
9
+ # TODO: cambiar esto por un include en la clase mejor
7
10
  user.extend(UserMethods)
8
11
  @interpolations = []
9
12
  @tagged_for_deletion = []
@@ -20,7 +23,10 @@ module Lotu
20
23
  :end => Float(opts[:end]),
21
24
  :duration => opts[:duration] || 1,
22
25
  :start_in => opts[:start_in] || 0,
23
- :on_result => opts[:on_result],
26
+ :on_stop => opts[:on_stop] || :current,
27
+ :every_value => opts[:every_value],
28
+ # TODO: implement callback mechanism
29
+ :callback => opts[:callback],
24
30
  :loop => opts[:loop],
25
31
  :bounce => opts[:bounce],
26
32
  :bouncing_back => false
@@ -29,6 +35,10 @@ module Lotu
29
35
  end
30
36
 
31
37
  # TODO: incluir código para :loop_for => n
38
+ # TODO: incluir soporte para "encimar" varias interpolaciones
39
+ # sobre una misma propiedad, de esa manera podemos "acumular"
40
+ # varias interpolaciones y el resultado se suma y se aplica a la
41
+ # propiedad una vez que todo el grupo ha sido calculado
32
42
  def update
33
43
  @interpolations.each do |t|
34
44
  t[:accum_time] += dt
@@ -49,7 +59,7 @@ module Lotu
49
59
  end
50
60
  end
51
61
  value = t[:init] + t[:calc]
52
- value = value.send(t[:on_result]) if t[:on_result]
62
+ value = value.send(t[:every_value]) if t[:every_value]
53
63
  t[:object].send( t[:property_setter], value )
54
64
  end
55
65
  end
@@ -70,10 +80,28 @@ module Lotu
70
80
  end
71
81
 
72
82
  module UserMethods
83
+ # Clear all interpolations on this object
84
+ def stop_interpolations
85
+ @systems[InterpolationSystem].interpolations.each do |t|
86
+ if t[:on_stop] == :complete
87
+ value = t[:end]
88
+ else
89
+ value = t[:init] + t[:calc]
90
+ end
91
+ value = value.send(t[:every_value]) if t[:every_value]
92
+ t[:object].send( t[:property_setter], value )
93
+ end
94
+ @systems[InterpolationSystem].interpolations.clear
95
+ end
96
+
73
97
  def interpolate(object, property, opts)
74
98
  @systems[InterpolationSystem].interpolate(object, property, opts)
75
99
  end
76
100
 
101
+ def interpolate_my(property, opts)
102
+ interpolate(self, property, opts)
103
+ end
104
+
77
105
  # Image helpers
78
106
  def interpolate_angle(opts)
79
107
  interpolate(self, :angle, opts)
@@ -89,19 +117,19 @@ module Lotu
89
117
 
90
118
  # Color helpers
91
119
  def interpolate_alpha(opts)
92
- interpolate(@color, :alpha, opts.merge!(:on_result => :to_i))
120
+ interpolate(@color, :alpha, opts.merge!(:every_value => :to_i))
93
121
  end
94
122
 
95
123
  def interpolate_red(opts)
96
- interpolate(@color, :red, opts.merge!(:on_result => :to_i))
124
+ interpolate(@color, :red, opts.merge!(:every_value => :to_i))
97
125
  end
98
126
 
99
127
  def interpolate_green(opts)
100
- interpolate(@color, :green, opts.merge!(:on_result => :to_i))
128
+ interpolate(@color, :green, opts.merge!(:every_value => :to_i))
101
129
  end
102
130
 
103
131
  def interpolate_blue(opts)
104
- interpolate(@color, :blue, opts.merge!(:on_result => :to_i))
132
+ interpolate(@color, :blue, opts.merge!(:every_value => :to_i))
105
133
  end
106
134
 
107
135
  def interpolate_hue(opts)
@@ -34,6 +34,9 @@ module Lotu
34
34
  end
35
35
 
36
36
  def update
37
+ @user.pos.x = @user.x
38
+ @user.pos.y = @user.y
39
+
37
40
  @force.zero!
38
41
  @behaviors.each_pair do |behavior, active|
39
42
  @force += send(behavior) if active
data/lotu.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lotu}
8
- s.version = "0.1.18"
8
+ s.version = "0.1.19"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["lobo_tuerto"]
12
- s.date = %q{2011-02-25}
12
+ s.date = %q{2011-02-27}
13
13
  s.description = %q{lotu aims to bring an agile and simple game development framework to life. It provides useful abstractions so you can concentrate on developing your game.}
14
14
  s.email = %q{dev@lobotuerto.com}
15
15
  s.extra_rdoc_files = [
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
50
50
  "lib/lotu/behaviors/system_user.rb",
51
51
  "lib/lotu/cursor.rb",
52
52
  "lib/lotu/game.rb",
53
+ "lib/lotu/game_entity.rb",
53
54
  "lib/lotu/helpers/kernel.rb",
54
55
  "lib/lotu/helpers/string.rb",
55
56
  "lib/lotu/helpers/util.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-02-25 00:00:00.000000000 -06:00
12
+ date: 2011-02-27 00:00:00.000000000 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gosu
17
- requirement: &23259460 !ruby/object:Gem::Requirement
17
+ requirement: &7915280 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.7.27.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *23259460
25
+ version_requirements: *7915280
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &23258660 !ruby/object:Gem::Requirement
28
+ requirement: &7914320 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 2.5.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *23258660
36
+ version_requirements: *7914320
37
37
  description: lotu aims to bring an agile and simple game development framework to
38
38
  life. It provides useful abstractions so you can concentrate on developing your
39
39
  game.
@@ -77,6 +77,7 @@ files:
77
77
  - lib/lotu/behaviors/system_user.rb
78
78
  - lib/lotu/cursor.rb
79
79
  - lib/lotu/game.rb
80
+ - lib/lotu/game_entity.rb
80
81
  - lib/lotu/helpers/kernel.rb
81
82
  - lib/lotu/helpers/string.rb
82
83
  - lib/lotu/helpers/util.rb