lotu 0.1.9 → 0.1.10

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.9
1
+ 0.1.10
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  LIB_PATH = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'lotu.rb')
3
3
  require File.expand_path(LIB_PATH)
4
+
4
5
  include Gosu::Button
6
+ include Lotu
5
7
 
6
- class MovingRuby < Lotu::Actor
8
+ class MovingRuby < Actor
7
9
 
8
10
  def initialize(opts={})
9
11
  super
@@ -35,7 +37,7 @@ class MovingRuby < Lotu::Actor
35
37
 
36
38
  end
37
39
 
38
- class Example < Lotu::Window
40
+ class Example < Game
39
41
 
40
42
  def initialize
41
43
  # This will call the hooks:
@@ -57,7 +59,7 @@ class Example < Lotu::Window
57
59
  def setup_actors
58
60
  @ruby = MovingRuby.new(:x => width/2, :y => height/2)
59
61
  # Create a TextBox so we can display a message on screen
60
- @info = Lotu::TextBox.new
62
+ @info = TextBox.new
61
63
  @info.text("Move around with arrow keys")
62
64
  end
63
65
 
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  LIB_PATH = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'lotu.rb')
3
3
  require File.expand_path(LIB_PATH)
4
+
4
5
  include Gosu::Button
6
+ include Lotu
5
7
 
6
- class WarpingRuby < Lotu::Actor
8
+ class WarpingRuby < Actor
7
9
  def initialize(opts={})
8
10
  super
9
11
  set_image 'CptnRuby Gem.png'
@@ -14,7 +16,7 @@ class WarpingRuby < Lotu::Actor
14
16
  end
15
17
  end
16
18
 
17
- class Example < Lotu::Window
19
+ class Example < Game
18
20
  def initialize
19
21
  # This will call the hooks:
20
22
  # load_resources, setup_systems and setup_actors
@@ -32,31 +34,33 @@ class Example < Lotu::Window
32
34
  end
33
35
 
34
36
  def setup_systems
35
- use(Lotu::FpsSystem)
36
- use(Lotu::StalkerSystem, :stalk => [Lotu::Actor, Lotu::InputController, Object])
37
+ # It's important to call super here to setup the InputSystem
38
+ super
39
+ use(FpsSystem)
40
+ use(StalkerSystem, :stalk => [Actor, Cursor, WarpingRuby, TextBox, Object])
37
41
  end
38
42
 
39
43
  def setup_actors
40
44
  @ruby = WarpingRuby.new(:x => width/2, :y => height/2)
41
- @cursor1 = Lotu::Cursor.new(:image => 'crosshair.png',
42
- :keys => {MsLeft => [:click, false]},
43
- :color => 0xff0099ff)
44
- @cursor2 = Lotu::Cursor.new(:image => 'crosshair.png',
45
- :use_mouse => false,
46
- :keys => {
47
- KbSpace => [:click, false],
48
- KbUp => :up,
49
- KbDown => :down,
50
- KbLeft => :left,
51
- KbRight => :right},
52
- :color => 0xff99ff00)
45
+ @cursor1 = Cursor.new(:image => 'crosshair.png',
46
+ :keys => {MsLeft => [:click, false]},
47
+ :color => 0xff0099ff)
48
+ @cursor2 = Cursor.new(:image => 'crosshair.png',
49
+ :use_mouse => false,
50
+ :keys => {
51
+ KbSpace => [:click, false],
52
+ KbUp => :up,
53
+ KbDown => :down,
54
+ KbLeft => :left,
55
+ KbRight => :right},
56
+ :color => 0xff99ff00)
53
57
  @cursor2.x = width*3/4
54
58
  @cursor2.y = height/2
55
59
 
56
60
  # Create a TextBox with default option :size => 15
57
- @info = Lotu::TextBox.new(:size => 15)
58
- @info.watch(@systems[Lotu::FpsSystem])
59
- @info.watch(@systems[Lotu::StalkerSystem])
61
+ @info = TextBox.new(:size => 15)
62
+ @info.watch(@systems[FpsSystem])
63
+ @info.watch(@systems[StalkerSystem])
60
64
  # We can change the size for a specific line of text
61
65
  @info.watch("@cursor1 data:", :size => 20)
62
66
  # Color too
@@ -1,13 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  LIB_PATH = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'lotu.rb')
3
3
  require File.expand_path(LIB_PATH)
4
+
4
5
  include Gosu::Button
6
+ include Lotu
5
7
 
6
- class SteeringRuby < Lotu::Actor
8
+ class SteeringRuby < Actor
7
9
  def initialize(opts={})
8
10
  super
9
11
  set_image 'CptnRuby Gem.png'
10
- use(Lotu::SteeringSystem, opts)
12
+ use(SteeringSystem, opts)
11
13
  end
12
14
 
13
15
  def warp(x, y)
@@ -15,7 +17,7 @@ class SteeringRuby < Lotu::Actor
15
17
  end
16
18
  end
17
19
 
18
- class Example < Lotu::Window
20
+ class Example < Game
19
21
  def initialize
20
22
  # This will call the hooks:
21
23
  # load_resources, setup_systems and setup_actors
@@ -38,7 +40,9 @@ class Example < Lotu::Window
38
40
  end
39
41
 
40
42
  def setup_systems
41
- use(Lotu::FpsSystem)
43
+ # It's important to call super here to setup the InputSystem
44
+ super
45
+ use(FpsSystem)
42
46
  end
43
47
 
44
48
  def setup_actors
@@ -49,16 +53,16 @@ class Example < Lotu::Window
49
53
  @ruby2 = SteeringRuby.new
50
54
  @ruby2.activate(:pursuit)
51
55
 
52
- @cursor = Lotu::Cursor.new(:image => 'crosshair.png',
53
- :keys => {MsLeft => [:click, false]})
56
+ @cursor = Cursor.new(:image => 'crosshair.png',
57
+ :keys => {MsLeft => [:click, false]})
54
58
 
55
- @window_info = Lotu::TextBox.new(:size => 15)
56
- @window_info.watch(@systems[Lotu::FpsSystem])
59
+ @window_info = TextBox.new(:size => 15)
60
+ @window_info.watch(@systems[FpsSystem])
57
61
  @window_info.watch(@cursor, :color => 0xffff0000)
58
62
  @window_info.text("Click to start the simulation")
59
63
  @window_info.text("One will pursuit while the other evades, right click to center evader on screen")
60
64
 
61
- @ruby_info = Lotu::TextBox.new(:attach_to => @ruby, :size => 14)
65
+ @ruby_info = TextBox.new(:attach_to => @ruby, :size => 14)
62
66
  @ruby_info.watch(@ruby)
63
67
  end
64
68
 
data/lib/lotu/actor.rb CHANGED
@@ -1,37 +1,63 @@
1
1
  module Lotu
2
2
  class Actor
3
- attr_accessor :parent, :x, :y, :systems
3
+ attr_accessor :parent, :x, :y, :systems,
4
+ :z, :angle, :center_x, :center_y,
5
+ :factor_x, :factor_y, :color, :mode, :image
4
6
 
5
7
  include SystemUser
8
+ include Controllable
6
9
 
7
10
  def initialize(opts={})
8
11
  default_opts = {
9
12
  :x => 0,
10
- :y => 0
13
+ :y => 0,
14
+ :z => 0,
15
+ :angle => 0.0,
16
+ :center_x => 0.5,
17
+ :center_y => 0.5,
18
+ :factor_x => 1.0,
19
+ :factor_y => 1.0,
20
+ :color => 0xffffffff,
21
+ :mode => :default,
22
+ :parent => $lotu
11
23
  }
12
24
  @opts = default_opts.merge!(opts)
25
+ @image = nil
13
26
  @x = @opts[:x]
14
27
  @y = @opts[:y]
15
- @parent = $window
16
- @parent.update_queue << self
28
+ @z = @opts[:z]
29
+ @angle = @opts[:angle]
30
+ @center_x = @opts[:center_x]
31
+ @center_y = @opts[:center_y]
32
+ @factor_x = @opts[:factor_x]
33
+ @factor_y = @opts[:factor_y]
34
+ @color = @opts[:color]
35
+ @mode = @opts[:mode]
36
+ @parent = @opts[:parent]
37
+ @parent.manage_me(self)
38
+ @systems = {}
17
39
 
18
40
  # Add extra functionality
19
- self.extend Drawable
20
- self.extend Controllable
21
41
  self.extend Eventful
22
42
  self.extend Collidable
23
-
24
- @systems = {}
25
43
  end
26
44
 
27
45
  # Easy access to delta-time
28
46
  def dt
29
- $window.dt
47
+ $lotu.dt
48
+ end
49
+
50
+ def set_image(image)
51
+ @image = @parent.image(image)
52
+ end
53
+
54
+ def unset_image
55
+ @image = nil
30
56
  end
31
57
 
32
58
  # Remove ourselves from the update queue
33
59
  def die
34
- @parent.update_queue.delete(self)
60
+ @parent.kill_me(self)
35
61
  end
36
62
 
37
63
  def update
@@ -40,7 +66,9 @@ module Lotu
40
66
  end
41
67
  end
42
68
 
43
- def draw;end
69
+ def draw
70
+ @image.draw_rot(@x, @y, @z, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode) unless @image.nil?
71
+ end
44
72
 
45
73
  end
46
74
  end
@@ -2,14 +2,6 @@
2
2
  module Lotu
3
3
  module Controllable
4
4
 
5
- def self.extended(instance)
6
- instance.init_behavior
7
- end
8
-
9
- def init_behavior
10
- @input_controller = nil
11
- end
12
-
13
5
  # This will call #go_up every game loop
14
6
  # Gosu::Button::KbUp => :go_up
15
7
  # This is the same as the above
@@ -21,7 +13,7 @@ module Lotu
21
13
  # This will call #go_up every 50ms
22
14
  # Gosu::Button::KbUp => [:go_up, 50]
23
15
  def set_keys(keys)
24
- @input_controller = InputController.new(self, keys)
16
+ @parent.systems[InputSystem].set_keys(self, keys)
25
17
  end
26
18
 
27
19
  end
data/lib/lotu/cursor.rb CHANGED
@@ -8,13 +8,13 @@ module Lotu
8
8
  default_opts = {
9
9
  :use_mouse => true,
10
10
  :speed => 100,
11
- :x => $window.width/2,
12
- :y => $window.height/2
11
+ :x => $lotu.width/2,
12
+ :y => $lotu.height/2
13
13
  }
14
14
  opts = default_opts.merge!(opts)
15
15
  super
16
- $window.mouse_x = opts[:x]
17
- $window.mouse_y = opts[:y]
16
+ $lotu.mouse_x = opts[:x]
17
+ $lotu.mouse_y = opts[:y]
18
18
  @clicked_x = @clicked_y = 0
19
19
  @speed = opts[:speed]
20
20
  @use_mouse = opts[:use_mouse]
@@ -24,8 +24,8 @@ module Lotu
24
24
 
25
25
  def update
26
26
  if @use_mouse
27
- @x = $window.mouse_x
28
- @y = $window.mouse_y
27
+ @x = $lotu.mouse_x
28
+ @y = $lotu.mouse_y
29
29
  end
30
30
  end
31
31
 
@@ -40,8 +40,8 @@ module Lotu
40
40
  end
41
41
 
42
42
  def adjust_mouse
43
- $window.mouse_y = @y
44
- $window.mouse_x = @x
43
+ $lotu.mouse_y = @y
44
+ $lotu.mouse_x = @x
45
45
  end
46
46
 
47
47
  def up
@@ -1,5 +1,5 @@
1
1
  module Lotu
2
- class Window < Gosu::Window
2
+ class Game < Gosu::Window
3
3
  # Accessors for time delta, systems and fonts
4
4
  attr_reader :dt, :systems, :fonts
5
5
  # Accessors for queues
@@ -11,7 +11,7 @@ module Lotu
11
11
  super(800, 600, false)
12
12
 
13
13
  # Handy global window variable
14
- $window = self
14
+ $lotu = self
15
15
  @debug = true
16
16
  setup_containers
17
17
 
@@ -20,9 +20,6 @@ module Lotu
20
20
  # Memoize fonts by size
21
21
  @fonts = Hash.new{|h,k| h[k] = Gosu::Font.new(self, Gosu::default_font_name, k)}
22
22
 
23
- # Add extra functionality
24
- extend Controllable
25
-
26
23
  # Call hook methods
27
24
  load_resources
28
25
  setup_systems
@@ -32,9 +29,12 @@ module Lotu
32
29
 
33
30
  # Hook methods, these are meant to be replaced by subclasses
34
31
  def load_resources;end
35
- def setup_systems;end
36
32
  def setup_actors;end
37
33
 
34
+ def setup_systems
35
+ use(InputSystem)
36
+ end
37
+
38
38
  # Setup various containers
39
39
  def setup_containers
40
40
  # For systems
@@ -132,19 +132,19 @@ module Lotu
132
132
 
133
133
  def load_images(path)
134
134
  with_files(/\.png|\.jpg|\.bmp/, path) do |file_name, file_path|
135
- @images[file_name] = Gosu::Image.new($window, file_path)
135
+ @images[file_name] = Gosu::Image.new($lotu, file_path)
136
136
  end
137
137
  end
138
138
 
139
139
  def load_sounds(path)
140
140
  with_files(/\.ogg|\.mp3|\.wav/, path) do |file_name, file_path|
141
- @sounds[file_name] = Gosu::Sample.new($window, file_path)
141
+ @sounds[file_name] = Gosu::Sample.new($lotu, file_path)
142
142
  end
143
143
  end
144
144
 
145
145
  def load_songs(path)
146
146
  with_files(/\.ogg|\.mp3|\.wav/, path) do |file_name, file_path|
147
- @songs[file_name] = Gosu::Song.new($window, file_path)
147
+ @songs[file_name] = Gosu::Song.new($lotu, file_path)
148
148
  end
149
149
  end
150
150
 
@@ -155,7 +155,7 @@ module Lotu
155
155
  count = 0
156
156
  Dir.entries(path).grep(regexp).each do |entry|
157
157
  begin
158
- @animations[entry] = klass.new($window, File.join(path, entry))
158
+ @animations[entry] = klass.new($lotu, File.join(path, entry))
159
159
  count += 1
160
160
  rescue Exception => e
161
161
  puts e, File.join(path, entry)
@@ -14,7 +14,7 @@ module Lotu
14
14
 
15
15
  def update
16
16
  @ticks += 1
17
- @accum += $window.dt
17
+ @accum += $lotu.dt
18
18
  if @ticks >= @samples
19
19
  @fps = @ticks/@accum
20
20
  @ticks = 0
@@ -0,0 +1,76 @@
1
+ module Lotu
2
+ class InputSystem
3
+
4
+ def initialize(user, opts={})
5
+ user.extend UserMethods
6
+ # Current ongoing actions (button is being pushed)
7
+ @actions = []
8
+ @unique_actions = []
9
+
10
+ # Last time an action was executed (so we can implement some
11
+ # rate of fire)
12
+ @last_time_fired = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = 0}}
13
+
14
+ # Think of it like a reverse proxy
15
+ @reverse_register = Hash.new{|h,k| h[k] = []}
16
+ end
17
+
18
+ # If there are some actions currently going on, dispatch them
19
+ def update
20
+ @unique_actions.each do |client, action_name, rate|
21
+ client.send(action_name)
22
+ end.clear
23
+
24
+ @actions.each do |client, action_name, rate|
25
+ # action usually is a [:action_name, rate_of_fire] pair, for
26
+ # example: [:fire, 50] will call #fire every 50ms
27
+ time_now = Gosu.milliseconds
28
+ if @last_time_fired[client][action_name] + (rate || 0) < time_now
29
+ client.send(action_name)
30
+ @last_time_fired[client][action_name] = time_now
31
+ end
32
+ end
33
+ end
34
+
35
+ def set_keys(client, keys)
36
+ keys.each do |key, action|
37
+ @reverse_register[key] << [client, action]
38
+ end
39
+ end
40
+
41
+ def button_down(key)
42
+ @reverse_register[key].each do |client, action|
43
+ action_name, rate = action
44
+ if rate == false
45
+ @unique_actions << [client, action_name, rate]
46
+ else
47
+ @actions << [client, action_name, rate]
48
+ end
49
+ end
50
+ end
51
+
52
+ def button_up(key)
53
+ @reverse_register[key].each do |client, action|
54
+ action_name, rate = action
55
+ @actions.delete [client, action_name, rate]
56
+ end
57
+ end
58
+
59
+ def draw;end
60
+
61
+ module UserMethods
62
+ def set_keys(keys)
63
+ systems[InputSystem].set_keys(self, keys)
64
+ end
65
+
66
+ def button_down(key)
67
+ systems[InputSystem].button_down(key)
68
+ end
69
+
70
+ def button_up(key)
71
+ systems[InputSystem].button_up(key)
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -193,9 +193,9 @@ module Lotu
193
193
 
194
194
  def draw
195
195
  super
196
- $window.draw_line(0, 0, 0xff999999, @pos.x, @pos.y, 0xff333333)
197
- $window.draw_line(@pos.x, @pos.y, 0xffffffff, (@pos + @heading*50).x, (@pos+@heading*50).y, 0xffff0000)
198
- $window.draw_line(@pos.x, @pos.y, 0xffffffff, @target.x, @target.y, 0xff00ff00) if @target
196
+ $lotu.draw_line(0, 0, 0xff999999, @pos.x, @pos.y, 0xff333333)
197
+ $lotu.draw_line(@pos.x, @pos.y, 0xffffffff, (@pos + @heading*50).x, (@pos+@heading*50).y, 0xffff0000)
198
+ $lotu.draw_line(@pos.x, @pos.y, 0xffffffff, @target.x, @target.y, 0xff00ff00) if @target
199
199
  end
200
200
 
201
201
  # to_s utility methods
data/lib/lotu/text_box.rb CHANGED
@@ -13,9 +13,6 @@ module Lotu
13
13
  @watch_list = []
14
14
  @size = opts[:size]
15
15
  @attached_to = opts[:attach_to]
16
- # Since we aren't setting an image for this, we need to specify
17
- # this actor needs to be drawed
18
- draw_me
19
16
  end
20
17
 
21
18
  def text(text, opts={})
@@ -44,11 +41,11 @@ module Lotu
44
41
  my_color = opts[:color] || @color
45
42
  my_text = watched.to_s
46
43
  if my_text.is_a?(String)
47
- $window.fonts[my_size].draw(my_text, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
44
+ $lotu.fonts[my_size].draw(my_text, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
48
45
  pos_y += my_size
49
46
  else
50
47
  my_text.each do |line|
51
- $window.fonts[my_size].draw(line, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
48
+ $lotu.fonts[my_size].draw(line, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
52
49
  pos_y += my_size
53
50
  end
54
51
  end
data/lib/lotu.rb CHANGED
@@ -3,6 +3,6 @@ $LOAD_PATH.unshift(LOTU_ROOT)
3
3
 
4
4
  require 'gosu'
5
5
  %w{vector2d string}.each{|file| require "misc/#{file}"}
6
- %w{system_user collidable controllable drawable controllable/input_controller eventful}.each{|file| require "behaviors/#{file}"}
7
- %w{stalker_system fps_system collision_system steering_system}.each{|file| require "systems/#{file}"}
8
- %w{window actor cursor text_box}.each{|file| require file}
6
+ %w{system_user collidable controllable eventful}.each{|file| require "behaviors/#{file}"}
7
+ %w{input_system stalker_system fps_system collision_system steering_system}.each{|file| require "systems/#{file}"}
8
+ %w{game actor cursor text_box}.each{|file| require file}
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.9"
8
+ s.version = "0.1.10"
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{2010-03-25}
12
+ s.date = %q{2010-03-26}
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 = [
@@ -49,19 +49,18 @@ Gem::Specification.new do |s|
49
49
  "lib/lotu/actor.rb",
50
50
  "lib/lotu/behaviors/collidable.rb",
51
51
  "lib/lotu/behaviors/controllable.rb",
52
- "lib/lotu/behaviors/controllable/input_controller.rb",
53
- "lib/lotu/behaviors/drawable.rb",
54
52
  "lib/lotu/behaviors/eventful.rb",
55
53
  "lib/lotu/behaviors/system_user.rb",
56
54
  "lib/lotu/cursor.rb",
55
+ "lib/lotu/game.rb",
57
56
  "lib/lotu/misc/string.rb",
58
57
  "lib/lotu/misc/vector2d.rb",
59
58
  "lib/lotu/systems/collision_system.rb",
60
59
  "lib/lotu/systems/fps_system.rb",
60
+ "lib/lotu/systems/input_system.rb",
61
61
  "lib/lotu/systems/stalker_system.rb",
62
62
  "lib/lotu/systems/steering_system.rb",
63
63
  "lib/lotu/text_box.rb",
64
- "lib/lotu/window.rb",
65
64
  "lotu.gemspec",
66
65
  "test/actor_test.rb"
67
66
  ]
data/test/actor_test.rb CHANGED
@@ -12,7 +12,7 @@ Protest.report_with(:documentation)
12
12
 
13
13
  Protest.context('An Actor') do
14
14
  setup do
15
- $window = Lotu::Window.new
15
+ $lotu = Lotu::Window.new
16
16
  @actor = Lotu::Actor.new
17
17
  end
18
18
 
@@ -32,14 +32,14 @@ Protest.context('An Actor') do
32
32
  end
33
33
 
34
34
  it 'has a window reference.' do
35
- assert_equal $window, @actor.parent
35
+ assert_equal $lotu, @actor.parent
36
36
  end
37
37
 
38
38
  # some context...
39
39
  #
40
40
  context 'when dying' do
41
41
  it 'removes itself from Window update_queue.' do
42
- mock.proxy($window.update_queue).delete(@actor)
42
+ mock.proxy($lotu.update_queue).delete(@actor)
43
43
  @actor.die
44
44
  end
45
45
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 9
9
- version: 0.1.9
8
+ - 10
9
+ version: 0.1.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - lobo_tuerto
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-25 00:00:00 -06:00
17
+ date: 2010-03-26 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -73,19 +73,18 @@ files:
73
73
  - lib/lotu/actor.rb
74
74
  - lib/lotu/behaviors/collidable.rb
75
75
  - lib/lotu/behaviors/controllable.rb
76
- - lib/lotu/behaviors/controllable/input_controller.rb
77
- - lib/lotu/behaviors/drawable.rb
78
76
  - lib/lotu/behaviors/eventful.rb
79
77
  - lib/lotu/behaviors/system_user.rb
80
78
  - lib/lotu/cursor.rb
79
+ - lib/lotu/game.rb
81
80
  - lib/lotu/misc/string.rb
82
81
  - lib/lotu/misc/vector2d.rb
83
82
  - lib/lotu/systems/collision_system.rb
84
83
  - lib/lotu/systems/fps_system.rb
84
+ - lib/lotu/systems/input_system.rb
85
85
  - lib/lotu/systems/stalker_system.rb
86
86
  - lib/lotu/systems/steering_system.rb
87
87
  - lib/lotu/text_box.rb
88
- - lib/lotu/window.rb
89
88
  - lotu.gemspec
90
89
  - test/actor_test.rb
91
90
  - TODO
@@ -1,56 +0,0 @@
1
- module Lotu
2
- class InputController
3
- attr_accessor :subject, :keys
4
-
5
- def initialize(subject, keys)
6
- # The subject being controlled
7
- @subject = subject
8
-
9
- # Key mappings {Gosu::Button::KbEscape => :quit, ...}
10
- @keys = keys
11
-
12
- # Current ongoing actions (button is being pushed)
13
- @actions = []
14
- @once_actions = []
15
-
16
- # Last time an action was executed (so we can implement some
17
- # rate of fire)
18
- @executed_at = {}
19
-
20
- # Register this controller with the main window
21
- $window.register_for_input(self)
22
- end
23
-
24
- # If there are some actions currently going on, dispatch them
25
- def update
26
- @once_actions.each do |action_name, rate|
27
- @subject.send(action_name)
28
- end.clear
29
-
30
- @actions.each do |action_name, rate|
31
- # action usually is a [:action_name, rate_of_fire] pair, for
32
- # example: [:fire, 50] will call #fire every 50ms
33
- time_now = Gosu.milliseconds
34
- if @executed_at[action_name] + (rate || 0) < time_now
35
- @executed_at[action_name] = time_now
36
- @subject.send(action_name)
37
- end
38
- end
39
- end
40
-
41
- def button_down(id)
42
- action_name, rate = @keys[id]
43
- @executed_at[action_name] ||= 0
44
- if rate == false
45
- @once_actions << @keys[id]
46
- else
47
- @actions << @keys[id]
48
- end
49
- end
50
-
51
- def button_up(id)
52
- @actions.delete(@keys[id])
53
- end
54
-
55
- end
56
- end
@@ -1,61 +0,0 @@
1
- module Lotu
2
- module Drawable
3
-
4
- def self.extended(instance)
5
- instance.init_behavior
6
- end
7
-
8
- def init_behavior
9
- class << self
10
- attr_accessor :z, :angle, :center_x, :center_y,
11
- :factor_x, :factor_y, :color, :mode
12
- end
13
-
14
- default_opts = {
15
- :z => 0,
16
- :angle => 0.0,
17
- :center_x => 0.5,
18
- :center_y => 0.5,
19
- :factor_x => 1.0,
20
- :factor_y => 1.0,
21
- :color => 0xffffffff,
22
- :mode => :default
23
- }
24
- @opts = default_opts.merge!(@opts)
25
-
26
- @image = nil
27
- @z = @opts[:z]
28
- @angle = @opts[:angle]
29
- @center_x = @opts[:center_x]
30
- @center_y = @opts[:center_y]
31
- @factor_x = @opts[:factor_x]
32
- @factor_y = @opts[:factor_y]
33
- @color = @opts[:color]
34
- @mode = @opts[:mode]
35
- end
36
-
37
- def draw_me
38
- @parent.draw_queue << self unless @parent.draw_queue.include?(self)
39
- end
40
-
41
- def image
42
- @image
43
- end
44
-
45
- def set_image(image)
46
- @image = @parent.image(image)
47
- draw_me
48
- end
49
-
50
- def draw
51
- super
52
- @image.draw_rot(@x, @y, @z, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode) unless @image.nil?
53
- end
54
-
55
- def die
56
- super
57
- @parent.draw_queue.delete(self)
58
- end
59
-
60
- end
61
- end