lotu 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +33 -17
- data/VERSION +1 -1
- data/examples/hello_world/hello_world.rb +18 -9
- data/examples/media/animations/missile.png +0 -0
- data/examples/media/animations/missile.txt +18 -0
- data/examples/media/images/cohete-big.png +0 -0
- data/examples/media/images/cohete-medium.png +0 -0
- data/examples/media/images/cohete-small.png +0 -0
- data/examples/media/images/crosshair-1.png +0 -0
- data/examples/media/images/crosshair-2.png +0 -0
- data/examples/media/images/crosshair-3.png +0 -0
- data/examples/media/images/missile-med.png +0 -0
- data/examples/media/images/silo.png +0 -0
- data/examples/mouse_pointer/mouse_pointer.rb +26 -22
- data/examples/steering_behaviors/steering.rb +9 -5
- data/lib/lotu/actor.rb +61 -18
- data/lib/lotu/behaviors/collidable.rb +1 -1
- data/lib/lotu/cursor.rb +0 -1
- data/lib/lotu/game.rb +25 -12
- data/lib/lotu/system.rb +15 -0
- data/lib/lotu/systems/animation_system.rb +55 -0
- data/lib/lotu/systems/fps_system.rb +4 -4
- data/lib/lotu/systems/stalker_system.rb +10 -3
- data/lib/lotu/systems/steering_system.rb +6 -2
- data/lib/lotu.rb +2 -2
- data/lotu.gemspec +15 -20
- data/test/actor_test.rb +30 -16
- metadata +16 -21
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Gem.png +0 -0
- data/examples/media/CptnRuby Map.txt +0 -25
- data/examples/media/CptnRuby Tileset.png +0 -0
- data/examples/media/CptnRuby.png +0 -0
- data/examples/media/Cursor.png +0 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Smoke.png +0 -0
- data/examples/media/Soldier.png +0 -0
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/examples/media/amenoske.png +0 -0
- data/examples/media/crosshair.png +0 -0
- data/examples/media/title.png +0 -0
- /data/examples/media/{lobo_tuerto.png → images/lobo_tuerto.png} +0 -0
data/README.rdoc
CHANGED
@@ -25,32 +25,48 @@ So, what can you do if you spot some patters here, a few more there? well, you d
|
|
25
25
|
|
26
26
|
If you have any questions of suggestions don't hesitate and send me a message!
|
27
27
|
|
28
|
+
#--
|
29
|
+
== So you want to make a game with *lotu*?
|
28
30
|
|
29
|
-
|
30
|
-
* Easy way to manage input, rendering, updating, etc.
|
31
|
-
* Simple access to game resources (images, sounds, songs, etc).
|
32
|
-
* Steering behaviors
|
31
|
+
Ok, then you need to know a bit about the facilities it provides. Let's start with the main classes:
|
33
32
|
|
33
|
+
=== Main classes
|
34
34
|
|
35
|
-
|
36
|
-
* Utility classes for viewports, game states, etc.
|
37
|
-
* Pathfinding and more AI stuff
|
35
|
+
==== Game
|
38
36
|
|
37
|
+
==== Actor
|
38
|
+
|
39
|
+
==== Cursor
|
40
|
+
|
41
|
+
==== TextBox
|
42
|
+
|
43
|
+
=== Systems
|
44
|
+
|
45
|
+
==== Collision
|
46
|
+
|
47
|
+
==== Fps
|
48
|
+
|
49
|
+
==== Input
|
50
|
+
|
51
|
+
==== Stalker
|
52
|
+
|
53
|
+
==== Steering
|
54
|
+
#++
|
39
55
|
|
40
56
|
== Game frameworks
|
41
57
|
Here are some other Gosu based frameworks:
|
42
|
-
* [
|
43
|
-
* [
|
44
|
-
* [
|
45
|
-
* [
|
46
|
-
* [
|
47
|
-
* [
|
48
|
-
*
|
49
|
-
* [
|
58
|
+
* Chingu[http://github.com/ippa/chingu]
|
59
|
+
* Exuberant[http://github.com/adamsanderson/lexery/tree/master/lib/exuberant]
|
60
|
+
* FWD[http://github.com/walski/FWD]
|
61
|
+
* Nimo[http://github.com/moonpxi/nimo]
|
62
|
+
* PuitUniverse[http://github.com/oneup/puituniverse]
|
63
|
+
* Ramverk[http://github.com/deps/Ramverk]
|
64
|
+
* {Space Shooter Engine}[http://github.com/belen-albeza/space-shooter/tree/master/engine/]
|
65
|
+
* SpriteJam[http://github.com/richardeden/spritejam]
|
50
66
|
|
51
67
|
There are others not base on Gosu you might like to check out:
|
52
|
-
* [
|
53
|
-
* [
|
68
|
+
* gamebox[http://github.com/shawn42/gamebox]
|
69
|
+
* jemini[http://github.com/jemini/jemini-core]
|
54
70
|
|
55
71
|
Be sure I will take inspiration from them. ;)
|
56
72
|
Nevertheless I'm doing this because I want to become better at architecturing software. And this seems like fitting practice. :D
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
@@ -10,12 +10,7 @@ class MovingRuby < Actor
|
|
10
10
|
def initialize(opts={})
|
11
11
|
super
|
12
12
|
# Use the image which filename is CptnRuby Gem.png
|
13
|
-
set_image '
|
14
|
-
# Map keys to some methods
|
15
|
-
set_keys(KbRight => :move_right,
|
16
|
-
KbLeft => :move_left,
|
17
|
-
KbUp => :move_up,
|
18
|
-
KbDown => :move_down)
|
13
|
+
set_image 'lobo_tuerto.png', :factor_x => 0.5, :factor_y => 0.5
|
19
14
|
end
|
20
15
|
|
21
16
|
# Let's define some basic movement methods
|
@@ -45,22 +40,36 @@ class Example < Game
|
|
45
40
|
# declared in the parent class
|
46
41
|
super
|
47
42
|
# When the Escape key is pressed, call the close method on class Example
|
48
|
-
set_keys(KbEscape => :close
|
43
|
+
set_keys(KbEscape => :close,
|
44
|
+
KbD => [:debug!, false])
|
49
45
|
end
|
50
46
|
|
51
47
|
def load_resources
|
52
48
|
# From this file,
|
53
49
|
with_path_from_file(__FILE__) do
|
54
50
|
# go back one dir and search inside media/
|
55
|
-
load_images '../media/'
|
51
|
+
load_images '../media/images'
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
59
55
|
def setup_actors
|
56
|
+
# Create a ruby in the middle of the screen
|
60
57
|
@ruby = MovingRuby.new(:x => width/2, :y => height/2)
|
58
|
+
# Map keys to some methods
|
59
|
+
@ruby.set_keys(KbRight => :move_right,
|
60
|
+
KbLeft => :move_left,
|
61
|
+
KbUp => :move_up,
|
62
|
+
KbDown => :move_down)
|
63
|
+
@ruby2 = MovingRuby.new(:x => width/2, :y => height/2)
|
64
|
+
# Map keys to some methods
|
65
|
+
@ruby2.set_keys(KbRight => :move_left,
|
66
|
+
KbLeft => :move_right,
|
67
|
+
KbUp => :move_up,
|
68
|
+
KbDown => :move_down)
|
61
69
|
# Create a TextBox so we can display a message on screen
|
62
70
|
@info = TextBox.new
|
63
|
-
@info.text("
|
71
|
+
@info.text("Hello world!")
|
72
|
+
@info.text("Move around with arrow keys", :size => 16, :color => 0xff33ccff)
|
64
73
|
end
|
65
74
|
|
66
75
|
end
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
miss0000 = 380 0 75 75
|
2
|
+
miss0001 = 380 76 75 75
|
3
|
+
miss0002 = 304 76 75 75
|
4
|
+
miss0003 = 304 0 75 75
|
5
|
+
miss0004 = 228 152 75 75
|
6
|
+
miss0005 = 76 228 75 75
|
7
|
+
miss0006 = 152 228 75 75
|
8
|
+
miss0007 = 0 228 75 75
|
9
|
+
miss0008 = 304 152 75 75
|
10
|
+
miss0009 = 380 152 75 75
|
11
|
+
miss0010 = 228 76 75 75
|
12
|
+
miss0011 = 0 76 75 75
|
13
|
+
miss0012 = 76 76 75 75
|
14
|
+
miss0013 = 152 0 75 75
|
15
|
+
miss0014 = 0 0 75 75
|
16
|
+
miss0015 = 76 0 75 75
|
17
|
+
miss0016 = 152 152 75 75
|
18
|
+
miss0017 = 228 0 75 75
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -8,7 +8,7 @@ include Lotu
|
|
8
8
|
class WarpingRuby < Actor
|
9
9
|
def initialize(opts={})
|
10
10
|
super
|
11
|
-
set_image '
|
11
|
+
set_image 'lobo_tuerto.png', :factor_x => 0.3, :factor_y => 0.3
|
12
12
|
end
|
13
13
|
|
14
14
|
def warp(x, y)
|
@@ -23,13 +23,12 @@ class Example < Game
|
|
23
23
|
# declared in the parent class
|
24
24
|
super
|
25
25
|
# Custom setup methods for this class
|
26
|
-
setup_input
|
27
26
|
setup_events
|
28
27
|
end
|
29
28
|
|
30
29
|
def load_resources
|
31
30
|
with_path_from_file(__FILE__) do
|
32
|
-
load_images '../media'
|
31
|
+
load_images '../media/images'
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
@@ -37,15 +36,31 @@ class Example < Game
|
|
37
36
|
# It's important to call super here to setup the InputSystem
|
38
37
|
super
|
39
38
|
use(FpsSystem)
|
40
|
-
use(StalkerSystem, :stalk => [Actor, Cursor,
|
39
|
+
use(StalkerSystem, :stalk => [Actor, Cursor, TextBox, WarpingRuby, Object])
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup_input
|
43
|
+
set_keys(KbEscape => :close,
|
44
|
+
KbD => [:debug!, false])
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_events
|
48
|
+
@cursor1.on(:click) do |x,y|
|
49
|
+
@ruby.warp(x,y)
|
50
|
+
end
|
51
|
+
@cursor2.on(:click) do |x,y|
|
52
|
+
@ruby.warp(x,y)
|
53
|
+
end
|
41
54
|
end
|
42
55
|
|
43
56
|
def setup_actors
|
44
57
|
@ruby = WarpingRuby.new(:x => width/2, :y => height/2)
|
45
|
-
@cursor1 = Cursor.new(:image => 'crosshair.png',
|
58
|
+
@cursor1 = Cursor.new(:image => 'crosshair-1.png',
|
46
59
|
:keys => {MsLeft => [:click, false]},
|
47
|
-
:color => 0xff0099ff
|
48
|
-
|
60
|
+
:color => 0xff0099ff,
|
61
|
+
:width => 100,
|
62
|
+
:height => 100)
|
63
|
+
@cursor2 = Cursor.new(:image => 'crosshair-2.png',
|
49
64
|
:use_mouse => false,
|
50
65
|
:keys => {
|
51
66
|
KbSpace => [:click, false],
|
@@ -53,14 +68,16 @@ class Example < Game
|
|
53
68
|
KbDown => :down,
|
54
69
|
KbLeft => :left,
|
55
70
|
KbRight => :right},
|
56
|
-
:color => 0xff99ff00
|
71
|
+
:color => 0xff99ff00,
|
72
|
+
:factor_x => 0.5,
|
73
|
+
:factor_y => 0.5)
|
57
74
|
@cursor2.x = width*3/4
|
58
75
|
@cursor2.y = height/2
|
59
76
|
|
60
77
|
# Create a TextBox with default option :size => 15
|
61
78
|
@info = TextBox.new(:size => 15)
|
62
79
|
@info.watch(@systems[FpsSystem])
|
63
|
-
@info.watch(@systems[StalkerSystem])
|
80
|
+
@info.watch(@systems[StalkerSystem], :color => 0xff3ffccf)
|
64
81
|
# We can change the size for a specific line of text
|
65
82
|
@info.watch("@cursor1 data:", :size => 20)
|
66
83
|
# Color too
|
@@ -70,19 +87,6 @@ class Example < Game
|
|
70
87
|
@info.text("Move @cursor1 with mouse and @cursor2 with arrow keys (click with space!)")
|
71
88
|
end
|
72
89
|
|
73
|
-
def setup_input
|
74
|
-
set_keys KbEscape => :close
|
75
|
-
end
|
76
|
-
|
77
|
-
def setup_events
|
78
|
-
@cursor1.on(:click) do |x,y|
|
79
|
-
@ruby.warp(x,y)
|
80
|
-
end
|
81
|
-
@cursor2.on(:click) do |x,y|
|
82
|
-
@ruby.warp(x,y)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
90
|
end
|
87
91
|
|
88
92
|
Example.new.show
|
@@ -8,7 +8,6 @@ include Lotu
|
|
8
8
|
class SteeringRuby < Actor
|
9
9
|
def initialize(opts={})
|
10
10
|
super
|
11
|
-
set_image 'CptnRuby Gem.png'
|
12
11
|
use(SteeringSystem, opts)
|
13
12
|
end
|
14
13
|
|
@@ -24,40 +23,45 @@ class Example < Game
|
|
24
23
|
# declared in the parent class
|
25
24
|
super
|
26
25
|
# Custom setup methods for this class
|
27
|
-
setup_input
|
28
26
|
setup_events
|
29
27
|
end
|
30
28
|
|
31
29
|
def load_resources
|
32
30
|
with_path_from_file(__FILE__) do
|
33
|
-
load_images '../media'
|
31
|
+
load_images '../media/images'
|
32
|
+
load_animations '../media/animations'
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
36
|
def setup_input
|
38
37
|
set_keys(KbEscape => :close,
|
39
|
-
MsRight => :reset_ruby
|
38
|
+
MsRight => :reset_ruby,
|
39
|
+
KbD => [:debug!, false])
|
40
40
|
end
|
41
41
|
|
42
42
|
def setup_systems
|
43
43
|
# It's important to call super here to setup the InputSystem
|
44
44
|
super
|
45
45
|
use(FpsSystem)
|
46
|
+
use(StalkerSystem, :stalk => [Actor, Vector2d, Object])
|
46
47
|
end
|
47
48
|
|
48
49
|
def setup_actors
|
49
50
|
@ruby = SteeringRuby.new(:mass => 0.3, :max_speed => 100, :max_turn_rate => 140)
|
50
51
|
@ruby.warp(width/2, height/2)
|
51
52
|
@ruby.activate(:evade)
|
53
|
+
@ruby.play_animation('missile.png')
|
52
54
|
|
53
55
|
@ruby2 = SteeringRuby.new
|
54
56
|
@ruby2.activate(:pursuit)
|
57
|
+
@ruby2.play_animation('missile.png', :factor_x => 0.5, :factor_y => 0.5, :fps => 60)
|
55
58
|
|
56
|
-
@cursor = Cursor.new(:image => 'crosshair.png',
|
59
|
+
@cursor = Cursor.new(:image => 'crosshair-1.png',
|
57
60
|
:keys => {MsLeft => [:click, false]})
|
58
61
|
|
59
62
|
@window_info = TextBox.new(:size => 15)
|
60
63
|
@window_info.watch(@systems[FpsSystem])
|
64
|
+
@window_info.watch(@systems[StalkerSystem])
|
61
65
|
@window_info.watch(@cursor, :color => 0xffff0000)
|
62
66
|
@window_info.text("Click to start the simulation")
|
63
67
|
@window_info.text("One will pursuit while the other evades, right click to center evader on screen")
|
data/lib/lotu/actor.rb
CHANGED
@@ -2,7 +2,8 @@ module Lotu
|
|
2
2
|
class Actor
|
3
3
|
attr_accessor :parent, :x, :y, :systems,
|
4
4
|
:z, :angle, :center_x, :center_y,
|
5
|
-
:factor_x, :factor_y, :color, :mode, :image
|
5
|
+
:factor_x, :factor_y, :color, :mode, :image,
|
6
|
+
:width, :height
|
6
7
|
|
7
8
|
include SystemUser
|
8
9
|
include Controllable
|
@@ -21,25 +22,17 @@ module Lotu
|
|
21
22
|
:mode => :default,
|
22
23
|
:parent => $lotu
|
23
24
|
}
|
24
|
-
|
25
|
-
@
|
26
|
-
@x = @opts[:x]
|
27
|
-
@y = @opts[:y]
|
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]
|
25
|
+
opts = default_opts.merge!(opts)
|
26
|
+
@parent = opts[:parent]
|
37
27
|
@parent.manage_me(self)
|
28
|
+
set_image(opts[:image], opts) if opts[:image]
|
29
|
+
parse_options(opts)
|
38
30
|
@systems = {}
|
39
31
|
|
40
32
|
# Add extra functionality
|
41
33
|
self.extend Eventful
|
42
34
|
self.extend Collidable
|
35
|
+
use(AnimationSystem)
|
43
36
|
end
|
44
37
|
|
45
38
|
# Easy access to delta-time
|
@@ -47,12 +40,49 @@ module Lotu
|
|
47
40
|
$lotu.dt
|
48
41
|
end
|
49
42
|
|
50
|
-
def
|
43
|
+
def parse_options(opts)
|
44
|
+
@x = opts[:x] || @x
|
45
|
+
@y = opts[:y] || @y
|
46
|
+
@z = opts[:z] || @z
|
47
|
+
@angle = opts[:angle] || @angle
|
48
|
+
@center_x = opts[:center_x] || @center_x
|
49
|
+
@center_y = opts[:center_y] || @center_y
|
50
|
+
@factor_x = opts[:factor_x] || @factor_x
|
51
|
+
@factor_y = opts[:factor_y] || @factor_y
|
52
|
+
@color = opts[:color] || @color
|
53
|
+
@mode = opts[:mode] || @mode
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_image(image, opts={})
|
51
57
|
@image = @parent.image(image)
|
58
|
+
puts "Image \"#{image}\" not found".red if @image.nil?
|
59
|
+
parse_options(opts)
|
60
|
+
@width = opts[:width] || @image.width
|
61
|
+
@height = opts[:height] || @image.height
|
62
|
+
calc_zoom
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_gosu_image(image, opts={})
|
66
|
+
@image = image
|
67
|
+
parse_options(opts)
|
68
|
+
@width = opts[:width] || @image.width
|
69
|
+
@height = opts[:height] || @image.height
|
70
|
+
calc_zoom
|
71
|
+
end
|
72
|
+
|
73
|
+
def width=(width)
|
74
|
+
@width = width
|
75
|
+
calc_zoom
|
52
76
|
end
|
53
77
|
|
54
|
-
def
|
55
|
-
@
|
78
|
+
def height=(height)
|
79
|
+
@height = height
|
80
|
+
calc_zoom
|
81
|
+
end
|
82
|
+
|
83
|
+
def calc_zoom
|
84
|
+
@zoom_x = Float(@width)/@image.width
|
85
|
+
@zoom_y = Float(@height)/@image.height
|
56
86
|
end
|
57
87
|
|
58
88
|
# Remove ourselves from the update queue
|
@@ -67,7 +97,20 @@ module Lotu
|
|
67
97
|
end
|
68
98
|
|
69
99
|
def draw
|
70
|
-
@image.draw_rot(@x, @y, @z, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode) unless @image.nil?
|
100
|
+
@image.draw_rot(@x, @y, @z, @angle, @center_x, @center_y, @factor_x*@zoom_x, @factor_y*@zoom_y, @color, @mode) unless @image.nil?
|
101
|
+
draw_debug if $lotu.debug? unless @image.nil?
|
102
|
+
end
|
103
|
+
|
104
|
+
def draw_debug
|
105
|
+
draw_box(@x-@image.width/2, @y-@image.height/2, @image.width, @image.height)
|
106
|
+
draw_box(@x-@width/2, @y-@height/2, @width, @height, 0xff00ff00)
|
107
|
+
end
|
108
|
+
|
109
|
+
def draw_box(x, y, w, h, c = 0xffff0000)
|
110
|
+
$lotu.draw_line(x, y, c, x+w, y, c)
|
111
|
+
$lotu.draw_line(x, y, c, x, y+h, c)
|
112
|
+
$lotu.draw_line(x+w, y+h, c, x+w, y, c)
|
113
|
+
$lotu.draw_line(x+w, y+h, c, x, y+h, c)
|
71
114
|
end
|
72
115
|
|
73
116
|
end
|
data/lib/lotu/cursor.rb
CHANGED
data/lib/lotu/game.rb
CHANGED
@@ -12,7 +12,7 @@ module Lotu
|
|
12
12
|
|
13
13
|
# Handy global window variable
|
14
14
|
$lotu = self
|
15
|
-
@debug =
|
15
|
+
@debug = false
|
16
16
|
setup_containers
|
17
17
|
|
18
18
|
# For timer initialization
|
@@ -24,12 +24,21 @@ module Lotu
|
|
24
24
|
load_resources
|
25
25
|
setup_systems
|
26
26
|
setup_actors
|
27
|
+
setup_input
|
27
28
|
end
|
28
29
|
|
30
|
+
def debug!
|
31
|
+
@debug = !@debug
|
32
|
+
end
|
33
|
+
|
34
|
+
def debug?
|
35
|
+
@debug
|
36
|
+
end
|
29
37
|
|
30
38
|
# Hook methods, these are meant to be replaced by subclasses
|
31
39
|
def load_resources;end
|
32
40
|
def setup_actors;end
|
41
|
+
def setup_input;end
|
33
42
|
|
34
43
|
def setup_systems
|
35
44
|
use(InputSystem)
|
@@ -49,7 +58,7 @@ module Lotu
|
|
49
58
|
@images = {}
|
50
59
|
@sounds = {}
|
51
60
|
@songs = {}
|
52
|
-
@animations = {}
|
61
|
+
@animations = Hash.new{|h,k| h[k] = []}
|
53
62
|
end
|
54
63
|
|
55
64
|
# Main update loop
|
@@ -149,19 +158,23 @@ module Lotu
|
|
149
158
|
end
|
150
159
|
|
151
160
|
def load_animations(path)
|
152
|
-
|
153
|
-
|
161
|
+
coords = Hash.new{|h,k| h[k] = []}
|
162
|
+
|
163
|
+
with_files(/\.txt/, path) do |file_name, file_path|
|
164
|
+
name = File.basename(file_name, '.txt')
|
165
|
+
File.open(file_path) do |file|
|
166
|
+
file.lines.each do |line|
|
167
|
+
coords[name] << line.scan(/\d+/).map!(&:to_i)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
154
171
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
@animations[
|
159
|
-
count += 1
|
160
|
-
rescue Exception => e
|
161
|
-
puts e, File.join(path, entry)
|
172
|
+
with_files(/\.png|\.jpg|\.bmp/, path) do |file_name, file_path|
|
173
|
+
name, extension = file_name.split('.')
|
174
|
+
coords[name].each do |index, x, y, width, height|
|
175
|
+
@animations[file_name] << Gosu::Image.new($lotu, file_path, true, x, y, width, height)
|
162
176
|
end
|
163
177
|
end
|
164
|
-
puts "#{count} #{klass} files loaded."
|
165
178
|
end
|
166
179
|
|
167
180
|
def with_path_from_file(path, &blk)
|
data/lib/lotu/system.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Lotu
|
2
|
+
class AnimationSystem < System
|
3
|
+
|
4
|
+
def initialize(user, opts={})
|
5
|
+
super
|
6
|
+
@user.extend(UserMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
def animated?
|
10
|
+
defined?(@length)
|
11
|
+
end
|
12
|
+
|
13
|
+
def play_animation(name, opts={})
|
14
|
+
default_opts = {
|
15
|
+
:fps => 30
|
16
|
+
}
|
17
|
+
opts = default_opts.merge!(opts)
|
18
|
+
@name = name
|
19
|
+
@length = $lotu.animation(@name).length
|
20
|
+
@time_per_frame = 1.0/opts[:fps]
|
21
|
+
@current_frame = 0
|
22
|
+
@accum_time = 0
|
23
|
+
@user.set_gosu_image($lotu.animation(@name)[0], opts)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
if animated?
|
28
|
+
@accum_time += dt
|
29
|
+
if @accum_time >= @time_per_frame
|
30
|
+
frames = @accum_time/@time_per_frame
|
31
|
+
@current_frame += frames
|
32
|
+
@accum_time -= @time_per_frame * frames
|
33
|
+
@current_frame = 0 if @current_frame >= @length
|
34
|
+
image = $lotu.animation(@name)[@current_frame]
|
35
|
+
@user.image = image
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
["Name: #{@name}",
|
42
|
+
"Current frame: #{@current_frame}",
|
43
|
+
"Accumulated time: #{format('%.2f', @accum_time)}",
|
44
|
+
"Time per frame: #{format('%.2f', @time_per_frame)}",
|
45
|
+
"Length: #{@length}"]
|
46
|
+
end
|
47
|
+
|
48
|
+
module UserMethods
|
49
|
+
def play_animation(name, opts={})
|
50
|
+
@systems[AnimationSystem].play_animation(name, opts)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -3,19 +3,19 @@ module Lotu
|
|
3
3
|
|
4
4
|
def initialize(user, opts={})
|
5
5
|
default_opts = {
|
6
|
-
:
|
6
|
+
:ticks_per_update => 10
|
7
7
|
}
|
8
8
|
opts = default_opts.merge!(opts)
|
9
9
|
@accum = 0.0
|
10
10
|
@ticks = 0
|
11
11
|
@fps = 0.0
|
12
|
-
@
|
12
|
+
@ticks_per_update = opts[:ticks_per_update]
|
13
13
|
end
|
14
14
|
|
15
15
|
def update
|
16
16
|
@ticks += 1
|
17
17
|
@accum += $lotu.dt
|
18
|
-
if @ticks >= @
|
18
|
+
if @ticks >= @ticks_per_update
|
19
19
|
@fps = @ticks/@accum
|
20
20
|
@ticks = 0
|
21
21
|
@accum = 0.0
|
@@ -23,7 +23,7 @@ module Lotu
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def to_s
|
26
|
-
"
|
26
|
+
"Ticks per update: #{@ticks_per_update} | FPS: #{format("%.2f",@fps)}"
|
27
27
|
end
|
28
28
|
|
29
29
|
def draw;end
|
@@ -3,9 +3,12 @@ module Lotu
|
|
3
3
|
|
4
4
|
def initialize(user, opts={})
|
5
5
|
default_opts = {
|
6
|
-
:stalk => [Actor]
|
6
|
+
:stalk => [Actor],
|
7
|
+
:ticks_per_update => 30
|
7
8
|
}
|
8
9
|
opts = default_opts.merge!(opts)
|
10
|
+
@ticks = 0
|
11
|
+
@ticks_per_update = opts[:ticks_per_update]
|
9
12
|
@stalked = {}
|
10
13
|
opts[:stalk].each do |type|
|
11
14
|
@stalked[type] = 0
|
@@ -13,8 +16,12 @@ module Lotu
|
|
13
16
|
end
|
14
17
|
|
15
18
|
def update
|
16
|
-
@
|
17
|
-
|
19
|
+
@ticks += 1
|
20
|
+
if @ticks >= @ticks_per_update
|
21
|
+
@stalked.each_key do |type|
|
22
|
+
@stalked[type] = ObjectSpace.each_object(type).count
|
23
|
+
end
|
24
|
+
@ticks = 0
|
18
25
|
end
|
19
26
|
end
|
20
27
|
|
@@ -157,10 +157,10 @@ module Lotu
|
|
157
157
|
module UserMethods
|
158
158
|
|
159
159
|
def self.extended(instance)
|
160
|
-
instance.
|
160
|
+
instance.setup_steering
|
161
161
|
end
|
162
162
|
|
163
|
-
def
|
163
|
+
def setup_steering
|
164
164
|
# Create accessors for the user
|
165
165
|
class << self
|
166
166
|
attr_accessor :mass, :pos, :heading, :vel, :accel,
|
@@ -193,6 +193,10 @@ module Lotu
|
|
193
193
|
|
194
194
|
def draw
|
195
195
|
super
|
196
|
+
draw_debug if $lotu.debug?
|
197
|
+
end
|
198
|
+
|
199
|
+
def draw_debug
|
196
200
|
$lotu.draw_line(0, 0, 0xff999999, @pos.x, @pos.y, 0xff333333)
|
197
201
|
$lotu.draw_line(@pos.x, @pos.y, 0xffffffff, (@pos + @heading*50).x, (@pos+@heading*50).y, 0xffff0000)
|
198
202
|
$lotu.draw_line(@pos.x, @pos.y, 0xffffffff, @target.x, @target.y, 0xff00ff00) if @target
|
data/lib/lotu.rb
CHANGED
@@ -4,5 +4,5 @@ $LOAD_PATH.unshift(LOTU_ROOT)
|
|
4
4
|
require 'gosu'
|
5
5
|
%w{vector2d string}.each{|file| require "misc/#{file}"}
|
6
6
|
%w{system_user collidable controllable eventful}.each{|file| require "behaviors/#{file}"}
|
7
|
-
%w{
|
8
|
-
%w{
|
7
|
+
%w{game system actor cursor text_box}.each{|file| require file}
|
8
|
+
%w{animation_system input_system stalker_system fps_system collision_system steering_system}.each{|file| require "systems/#{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.
|
8
|
+
s.version = "0.1.11"
|
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-
|
12
|
+
s.date = %q{2010-03-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 = [
|
@@ -25,24 +25,17 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"examples/hello_world/hello_world.rb",
|
28
|
-
"examples/media/
|
29
|
-
"examples/media/
|
30
|
-
"examples/media/
|
31
|
-
"examples/media/
|
32
|
-
"examples/media/
|
33
|
-
"examples/media/
|
34
|
-
"examples/media/
|
35
|
-
"examples/media/
|
36
|
-
"examples/media/
|
37
|
-
"examples/media/
|
38
|
-
"examples/media/
|
39
|
-
"examples/media/Space.png",
|
40
|
-
"examples/media/Star.png",
|
41
|
-
"examples/media/Starfighter.bmp",
|
42
|
-
"examples/media/amenoske.png",
|
43
|
-
"examples/media/crosshair.png",
|
44
|
-
"examples/media/lobo_tuerto.png",
|
45
|
-
"examples/media/title.png",
|
28
|
+
"examples/media/animations/missile.png",
|
29
|
+
"examples/media/animations/missile.txt",
|
30
|
+
"examples/media/images/cohete-big.png",
|
31
|
+
"examples/media/images/cohete-medium.png",
|
32
|
+
"examples/media/images/cohete-small.png",
|
33
|
+
"examples/media/images/crosshair-1.png",
|
34
|
+
"examples/media/images/crosshair-2.png",
|
35
|
+
"examples/media/images/crosshair-3.png",
|
36
|
+
"examples/media/images/lobo_tuerto.png",
|
37
|
+
"examples/media/images/missile-med.png",
|
38
|
+
"examples/media/images/silo.png",
|
46
39
|
"examples/mouse_pointer/mouse_pointer.rb",
|
47
40
|
"examples/steering_behaviors/steering.rb",
|
48
41
|
"lib/lotu.rb",
|
@@ -55,6 +48,8 @@ Gem::Specification.new do |s|
|
|
55
48
|
"lib/lotu/game.rb",
|
56
49
|
"lib/lotu/misc/string.rb",
|
57
50
|
"lib/lotu/misc/vector2d.rb",
|
51
|
+
"lib/lotu/system.rb",
|
52
|
+
"lib/lotu/systems/animation_system.rb",
|
58
53
|
"lib/lotu/systems/collision_system.rb",
|
59
54
|
"lib/lotu/systems/fps_system.rb",
|
60
55
|
"lib/lotu/systems/input_system.rb",
|
data/test/actor_test.rb
CHANGED
@@ -3,7 +3,9 @@ require 'rubygems'
|
|
3
3
|
require 'protest'
|
4
4
|
require 'rr'
|
5
5
|
require File.dirname(__FILE__) + '/../lib/lotu'
|
6
|
-
|
6
|
+
|
7
|
+
include Lotu
|
8
|
+
|
7
9
|
class Protest::TestCase
|
8
10
|
include RR::Adapters::TestUnit
|
9
11
|
end
|
@@ -12,34 +14,46 @@ Protest.report_with(:documentation)
|
|
12
14
|
|
13
15
|
Protest.context('An Actor') do
|
14
16
|
setup do
|
15
|
-
|
16
|
-
@actor =
|
17
|
+
@game = Game.new
|
18
|
+
@actor = Actor.new
|
17
19
|
end
|
18
20
|
|
19
|
-
it 'has an x coordinate
|
21
|
+
it 'has an x coordinate (default: 0)' do
|
20
22
|
assert_equal 0, @actor.x
|
21
23
|
end
|
22
24
|
|
23
|
-
it 'has an y coordinate
|
25
|
+
it 'has an y coordinate (default: 0)' do
|
24
26
|
assert_equal 0, @actor.y
|
25
27
|
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
it 'has a color. (default: 0xffffffff)' do
|
30
|
-
pending
|
31
|
-
#assert_equal Gosu::Color::WHITE, @actor.color
|
29
|
+
it 'has a color (default: 0xffffffff)' do
|
30
|
+
assert_equal 0xffffffff, @actor.color
|
32
31
|
end
|
33
32
|
|
34
|
-
it 'has a
|
35
|
-
assert_equal
|
33
|
+
it 'has a parent reference == Game' do
|
34
|
+
assert_equal @game, @actor.parent
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when creating' do
|
38
|
+
it 'asks Game to manage it' do
|
39
|
+
pending
|
40
|
+
#crear método 'init' para poder probar esto?
|
41
|
+
end
|
36
42
|
end
|
37
43
|
|
38
|
-
# some context...
|
39
|
-
#
|
40
44
|
context 'when dying' do
|
41
|
-
it '
|
42
|
-
mock.proxy(
|
45
|
+
it 'asks Game to kill it' do
|
46
|
+
mock.proxy(@game).kill_me(@actor)
|
47
|
+
@actor.die
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'is removed from Game update_queue' do
|
51
|
+
mock.proxy(@game.update_queue).delete(@actor)
|
52
|
+
@actor.die
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'is removed from Game draw_queue' do
|
56
|
+
mock.proxy(@game.update_queue).delete(@actor)
|
43
57
|
@actor.die
|
44
58
|
end
|
45
59
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 11
|
9
|
+
version: 0.1.11
|
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-
|
17
|
+
date: 2010-03-27 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -49,24 +49,17 @@ files:
|
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
51
|
- examples/hello_world/hello_world.rb
|
52
|
-
- examples/media/
|
53
|
-
- examples/media/
|
54
|
-
- examples/media/
|
55
|
-
- examples/media/
|
56
|
-
- examples/media/
|
57
|
-
- examples/media/
|
58
|
-
- examples/media/
|
59
|
-
- examples/media/
|
60
|
-
- examples/media/
|
61
|
-
- examples/media/
|
62
|
-
- examples/media/
|
63
|
-
- examples/media/Space.png
|
64
|
-
- examples/media/Star.png
|
65
|
-
- examples/media/Starfighter.bmp
|
66
|
-
- examples/media/amenoske.png
|
67
|
-
- examples/media/crosshair.png
|
68
|
-
- examples/media/lobo_tuerto.png
|
69
|
-
- examples/media/title.png
|
52
|
+
- examples/media/animations/missile.png
|
53
|
+
- examples/media/animations/missile.txt
|
54
|
+
- examples/media/images/cohete-big.png
|
55
|
+
- examples/media/images/cohete-medium.png
|
56
|
+
- examples/media/images/cohete-small.png
|
57
|
+
- examples/media/images/crosshair-1.png
|
58
|
+
- examples/media/images/crosshair-2.png
|
59
|
+
- examples/media/images/crosshair-3.png
|
60
|
+
- examples/media/images/lobo_tuerto.png
|
61
|
+
- examples/media/images/missile-med.png
|
62
|
+
- examples/media/images/silo.png
|
70
63
|
- examples/mouse_pointer/mouse_pointer.rb
|
71
64
|
- examples/steering_behaviors/steering.rb
|
72
65
|
- lib/lotu.rb
|
@@ -79,6 +72,8 @@ files:
|
|
79
72
|
- lib/lotu/game.rb
|
80
73
|
- lib/lotu/misc/string.rb
|
81
74
|
- lib/lotu/misc/vector2d.rb
|
75
|
+
- lib/lotu/system.rb
|
76
|
+
- lib/lotu/systems/animation_system.rb
|
82
77
|
- lib/lotu/systems/collision_system.rb
|
83
78
|
- lib/lotu/systems/fps_system.rb
|
84
79
|
- lib/lotu/systems/input_system.rb
|
data/examples/media/Beep.wav
DELETED
Binary file
|
Binary file
|
@@ -1,25 +0,0 @@
|
|
1
|
-
#....................................................#
|
2
|
-
#....................................................#
|
3
|
-
#.............xx......x.x............................#
|
4
|
-
#............x..x....................................#
|
5
|
-
#x....x...x..x.......#####..xxx....................x.#
|
6
|
-
#.x.........................xxx.........##.........x.#
|
7
|
-
#...............""..........###...##..........##.....#
|
8
|
-
#..##..###..##..##...................................#
|
9
|
-
#........................................xx........###
|
10
|
-
#.............................###....................#
|
11
|
-
##....##.............................................#
|
12
|
-
#....................##....##......##....##....##....#
|
13
|
-
#.................................................x..#
|
14
|
-
#...x....##....##.......x...x.....................x..#
|
15
|
-
#.....x...............x...x...x...................x..#
|
16
|
-
#......x...##.....##.................................#
|
17
|
-
#.......x.........................................#..#
|
18
|
-
#...........##........#...#...#..#.......x...........#
|
19
|
-
#...#................................................#
|
20
|
-
#....."""".................x.......#..#####...###....#
|
21
|
-
#x....#......................##......................#
|
22
|
-
#"""""#.....#.....x..................#...............#
|
23
|
-
##xxxx......#........................................#
|
24
|
-
##xxxx...#####............."...""""".................#
|
25
|
-
######"""#############################################
|
Binary file
|
data/examples/media/CptnRuby.png
DELETED
Binary file
|
data/examples/media/Cursor.png
DELETED
Binary file
|
data/examples/media/Earth.png
DELETED
Binary file
|
Binary file
|
Binary file
|
data/examples/media/Smoke.png
DELETED
Binary file
|
data/examples/media/Soldier.png
DELETED
Binary file
|
data/examples/media/Space.png
DELETED
Binary file
|
data/examples/media/Star.png
DELETED
Binary file
|
Binary file
|
data/examples/media/amenoske.png
DELETED
Binary file
|
Binary file
|
data/examples/media/title.png
DELETED
Binary file
|
File without changes
|