lotu 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +26 -0
- data/README.rdoc +42 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/examples/hello_world/hello_world.rb +63 -0
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Gem.png +0 -0
- data/examples/media/CptnRuby Map.txt +25 -0
- 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/lobo_tuerto.png +0 -0
- data/examples/media/title.png +0 -0
- data/examples/mouse_pointer/mouse.rb +86 -0
- data/lib/lotu/actor.rb +26 -0
- data/lib/lotu/behaviors/controllable.rb +28 -0
- data/lib/lotu/behaviors/drawable.rb +23 -0
- data/lib/lotu/behaviors/eventful.rb +39 -0
- data/lib/lotu/behaviors/has_behavior.rb +8 -0
- data/lib/lotu/behaviors/input_controller.rb +55 -0
- data/lib/lotu/behaviors/resourceful.rb +64 -0
- data/lib/lotu/cursor.rb +48 -0
- data/lib/lotu/fps.rb +32 -0
- data/lib/lotu/window.rb +72 -0
- data/lib/lotu.rb +16 -0
- data/lotu.gemspec +82 -0
- metadata +114 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Víctor Adrián de la Cruz Serrano
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
23
|
+
Víctor Adrián de la Cruz Serrano
|
24
|
+
dev@lobotuerto.com
|
25
|
+
|
26
|
+
http://github.com/lobo-tuerto/lotu
|
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
== Development just started!
|
2
|
+
So bear with me while this framework is in a primordial state. But fear not, it's shaping up pretty nicely! :D
|
3
|
+
|
4
|
+
= lotu
|
5
|
+
A simple, agile Ruby game development framework.
|
6
|
+
|
7
|
+
== Install
|
8
|
+
gem install lotu
|
9
|
+
|
10
|
+
== Description
|
11
|
+
*lotu* aims to bring an agile and simple game development framework to life.
|
12
|
+
|
13
|
+
It provides useful abstractions so you can concentrate on developing your game.
|
14
|
+
|
15
|
+
It's built on top of Gosu, the excellent Cross-platform 2D game development library.
|
16
|
+
http://code.google.com/p/gosu/
|
17
|
+
|
18
|
+
After making my first game (*Rubytris* http://github.com/lobo-tuerto/rubytris), and been working for a few days in my new project (a Missile Command clone)... I decided I didn't want to type so much code. Thought I could organize my code better too.
|
19
|
+
|
20
|
+
So, what can you do if you spot some patters here, a few more there? well, you do a framework of course! :)
|
21
|
+
(disclaimer: well, you might want to do something else, but I will go with this, since I'm very excited about writing my first framework!)
|
22
|
+
|
23
|
+
If you have any questions of suggestions don't hesitate and send me a message!
|
24
|
+
|
25
|
+
|
26
|
+
== Features (planned)
|
27
|
+
* Easy way to manage input, rendering, updating, etc. (check!)
|
28
|
+
* Utility classes for viewports, game states, etc. (this is comming next!)
|
29
|
+
* Simple access to game resources (images, sounds, songs, etc). (check!)
|
30
|
+
|
31
|
+
|
32
|
+
== Other frameworks
|
33
|
+
I saw another framework around called Chingu,
|
34
|
+
It's been around for a little while and I recommend you take a look at it:
|
35
|
+
http://github.com/ippa/chingu
|
36
|
+
|
37
|
+
I did find many of the ideas I have for my framework already implemented in it. But be sure I will take inspiration from many others. ;)
|
38
|
+
Nevertheless I'm doing this because I want to become better at architecturing software. And this seems like fitting practice. :D
|
39
|
+
|
40
|
+
|
41
|
+
== Copyright
|
42
|
+
Copyright (c) 2010 Víctor Adrián de la Cruz Serrano. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "lotu"
|
8
|
+
gem.summary = %Q{A simple, agile Ruby game development framework.}
|
9
|
+
gem.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.}
|
10
|
+
gem.email = "dev@lobotuerto.com"
|
11
|
+
gem.homepage = "http://github.com/lobo-tuerto/lotu"
|
12
|
+
gem.authors = ["lobo_tuerto"]
|
13
|
+
gem.add_development_dependency "gosu", ">= 0.7.18"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/rdoctask'
|
22
|
+
Rake::RDocTask.new do |rdoc|
|
23
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
24
|
+
|
25
|
+
rdoc.rdoc_dir = 'rdoc'
|
26
|
+
rdoc.title = "lotu #{version}"
|
27
|
+
rdoc.rdoc_files.include('README*')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
LIB_PATH = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'lotu.rb')
|
3
|
+
require File.expand_path(LIB_PATH)
|
4
|
+
include Gosu::Button
|
5
|
+
|
6
|
+
class Player < Lotu::Actor
|
7
|
+
is_drawable
|
8
|
+
is_controllable
|
9
|
+
|
10
|
+
attr_reader :speed
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
set_image 'CptnRuby Gem.png'
|
15
|
+
set_keys(KbRight => :move_right,
|
16
|
+
KbLeft => :move_left,
|
17
|
+
KbUp => :move_up,
|
18
|
+
KbDown => :move_down)
|
19
|
+
end
|
20
|
+
|
21
|
+
def move_right
|
22
|
+
@x += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def move_left
|
26
|
+
@x -= 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def move_up
|
30
|
+
@y -= 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def move_down
|
34
|
+
@y += 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def warp(x, y)
|
38
|
+
@x, @y = x, y
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Example < Lotu::Window
|
43
|
+
is_controllable
|
44
|
+
is_resourceful
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
super
|
48
|
+
set_keys KbEscape => :close
|
49
|
+
with_path(__FILE__) do
|
50
|
+
load_images '../media'
|
51
|
+
load_sounds '../media'
|
52
|
+
end
|
53
|
+
|
54
|
+
@player = Player.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def draw
|
58
|
+
super
|
59
|
+
@fps_counter.draw
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Example.new.show
|
Binary file
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
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
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
LIB_PATH = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'lotu.rb')
|
3
|
+
require File.expand_path(LIB_PATH)
|
4
|
+
include Gosu::Button
|
5
|
+
|
6
|
+
class Cursor < Lotu::Cursor
|
7
|
+
is_eventful
|
8
|
+
is_controllable
|
9
|
+
is_drawable
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
set_keys(Gosu::Button::MsLeft => [:click, false],
|
14
|
+
Gosu::Button::KbSpace => [:click, false],
|
15
|
+
Gosu::Button::KbUp => :up,
|
16
|
+
Gosu::Button::KbDown => :down,
|
17
|
+
Gosu::Button::KbLeft => :left,
|
18
|
+
Gosu::Button::KbRight => :right)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Player < Lotu::Actor
|
23
|
+
is_drawable
|
24
|
+
is_controllable
|
25
|
+
|
26
|
+
attr_reader :speed
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
super
|
30
|
+
set_image 'CptnRuby Gem.png'
|
31
|
+
set_keys(KbRight => :move_right,
|
32
|
+
KbLeft => :move_left,
|
33
|
+
KbUp => :move_up,
|
34
|
+
KbDown => :move_down)
|
35
|
+
end
|
36
|
+
|
37
|
+
def move_right
|
38
|
+
@x += 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def move_left
|
42
|
+
@x -= 1
|
43
|
+
end
|
44
|
+
|
45
|
+
def move_up
|
46
|
+
@y -= 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def move_down
|
50
|
+
@y += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
def warp(x, y)
|
54
|
+
@x, @y = x, y
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Example < Lotu::Window
|
59
|
+
is_controllable
|
60
|
+
is_resourceful
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
super
|
64
|
+
set_keys KbEscape => :close
|
65
|
+
with_path __FILE__ do
|
66
|
+
load_images '../media'
|
67
|
+
load_sounds '../media'
|
68
|
+
end
|
69
|
+
|
70
|
+
@player = Player.new
|
71
|
+
@font = Gosu::Font.new(self, Gosu::default_font_name, 20)
|
72
|
+
@cursor = Cursor.new
|
73
|
+
@cursor.set_image('crosshair.png')
|
74
|
+
@cursor.on(:click) do |x,y|
|
75
|
+
@player.warp(x,y)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def draw
|
80
|
+
super
|
81
|
+
@font.draw("FPS: #{@fps}", 10, 10, 0, 1.0, 1.0, 0xffffff00)
|
82
|
+
@font.draw("Click? #{@cursor.last_click}", 10, 30, 0, 1.0, 1.0, 0xfffff000)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
Example.new.show
|
data/lib/lotu/actor.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Lotu
|
2
|
+
class Actor
|
3
|
+
extend HasBehavior
|
4
|
+
|
5
|
+
attr_accessor :parent, :x, :y
|
6
|
+
|
7
|
+
def initialize(opts={})
|
8
|
+
super()
|
9
|
+
@x = opts[:x] || 0
|
10
|
+
@y = opts[:y] || 0
|
11
|
+
@parent = $window
|
12
|
+
@parent.update_queue << self
|
13
|
+
|
14
|
+
# Initialize the behaviors included in subclasses
|
15
|
+
init_behavior
|
16
|
+
end
|
17
|
+
|
18
|
+
def dt
|
19
|
+
$window.dt
|
20
|
+
end
|
21
|
+
|
22
|
+
# Meant to be overriden by behaviors
|
23
|
+
def init_behavior;end
|
24
|
+
def update;end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Convenience module to set up an InputController
|
2
|
+
module Lotu
|
3
|
+
module Controllable
|
4
|
+
def is_controllable
|
5
|
+
include InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def init_behavior
|
10
|
+
super
|
11
|
+
@_input_controller = nil
|
12
|
+
end
|
13
|
+
# This will call #go_up every game loop
|
14
|
+
# Gosu::Button::KbUp => :go_up
|
15
|
+
# This is the same as the above
|
16
|
+
# Gosu::Button::KbUp => [:go_up, 0]
|
17
|
+
#
|
18
|
+
# This will call #go_up once
|
19
|
+
# Gosu::Button::KbUp => [:go_up, false]
|
20
|
+
#
|
21
|
+
# This will call #go_up every 50ms
|
22
|
+
# Gosu::Button::KbUp => [:go_up, 50]
|
23
|
+
def set_keys(keys)
|
24
|
+
@_input_controller = InputController.new(self, keys)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Lotu
|
2
|
+
module Drawable
|
3
|
+
def is_drawable
|
4
|
+
include InstanceMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
def init_behavior
|
9
|
+
super
|
10
|
+
@_image = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_image(image)
|
14
|
+
@_image = $window.image(image)
|
15
|
+
$window.register_for_draw(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw
|
19
|
+
@_image.draw(@x,@y,0)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# You can define arbitrary events on objects that include this module
|
2
|
+
# It serves as storage for code to be executed later (when fire is
|
3
|
+
# called)
|
4
|
+
# For example:
|
5
|
+
# class Cursor < Lotu::Actor
|
6
|
+
# def initialize
|
7
|
+
# on(:someone_clicked) do
|
8
|
+
# puts 'Someone clicked me!'
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# After that you will be able to call #fire(:someone_clicked) from any
|
14
|
+
# instance of class Cursor.
|
15
|
+
# If you pair this with input handling, you will get a nice event
|
16
|
+
# system. Check out the Cursor class to see it in action.
|
17
|
+
|
18
|
+
module Lotu
|
19
|
+
module Eventful
|
20
|
+
def is_eventful
|
21
|
+
include InstanceMethods
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
def init_behavior
|
26
|
+
super
|
27
|
+
@_events = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def on(event, &blk)
|
31
|
+
@_events[event] = blk
|
32
|
+
end
|
33
|
+
|
34
|
+
def fire(event, *args)
|
35
|
+
@_events[event].call(*args) if @_events[event]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Add methods to load and access images, sounds & songs
|
2
|
+
module Lotu
|
3
|
+
module Resourceful
|
4
|
+
def is_resourceful
|
5
|
+
include InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def init_behavior
|
10
|
+
@_images = {}
|
11
|
+
@_sounds = {}
|
12
|
+
@_songs = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def image(name)
|
16
|
+
@_images[name]
|
17
|
+
end
|
18
|
+
|
19
|
+
def sound(name)
|
20
|
+
@_sounds[name]
|
21
|
+
end
|
22
|
+
|
23
|
+
def song(name)
|
24
|
+
@_songs[name]
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_images(path)
|
28
|
+
load_resources(@_images, /\.png|\.jpg|\.bmp/, path, Gosu::Image)
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_sounds(path)
|
32
|
+
load_resources(@_sounds, /\.ogg|\.mp3|\.wav/, path, Gosu::Sample)
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_songs(path)
|
36
|
+
load_resources(@_sounds, /\.ogg|\.mp3|\.wav/, path, Gosu::Song)
|
37
|
+
end
|
38
|
+
|
39
|
+
def with_path(path, &blk)
|
40
|
+
@_path = File.expand_path(File.dirname path)
|
41
|
+
yield
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def load_resources(container, regexp, path, klass)
|
46
|
+
path = File.expand_path(File.join(@_path, path))
|
47
|
+
puts "Loading from: #{path}"
|
48
|
+
|
49
|
+
count = 0
|
50
|
+
Dir.entries(path).select do |entry|
|
51
|
+
entry =~ regexp
|
52
|
+
end.each do |entry|
|
53
|
+
begin
|
54
|
+
container[entry] = klass.new($window, File.join(path, entry))
|
55
|
+
count += 1
|
56
|
+
rescue Exception => e
|
57
|
+
puts e, File.join(path, entry)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
puts "#{count} #{klass} files loaded."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/lotu/cursor.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Provides a mouse pointer usable through mouse or keyboard
|
2
|
+
module Lotu
|
3
|
+
class Cursor < Actor
|
4
|
+
attr_reader :click_x, :click_y
|
5
|
+
attr_accessor :arrow_speed
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@click_x = @click_y = 0
|
10
|
+
@arrow_speed = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
@x = $window.mouse_x
|
15
|
+
@y = $window.mouse_y
|
16
|
+
end
|
17
|
+
|
18
|
+
# This is the method you want to call when a user press the
|
19
|
+
# "click" key of your preference with something like:
|
20
|
+
# set_keys Gosu::Button::MsLeft => :click
|
21
|
+
# It'll yield the x, y coordinates of the click
|
22
|
+
def click
|
23
|
+
@click_x = $window.mouse_x
|
24
|
+
@click_y = $window.mouse_y
|
25
|
+
fire(:click, @click_x, @click_y)
|
26
|
+
end
|
27
|
+
|
28
|
+
def up
|
29
|
+
$window.mouse_y -= @arrow_speed
|
30
|
+
end
|
31
|
+
|
32
|
+
def down
|
33
|
+
$window.mouse_y += @arrow_speed
|
34
|
+
end
|
35
|
+
|
36
|
+
def left
|
37
|
+
$window.mouse_x -= @arrow_speed
|
38
|
+
end
|
39
|
+
|
40
|
+
def right
|
41
|
+
$window.mouse_x += @arrow_speed
|
42
|
+
end
|
43
|
+
|
44
|
+
def last_click
|
45
|
+
"#{@click_x}, #{@click_y}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/lotu/fps.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
class FpsCounter
|
2
|
+
attr_reader :fps
|
3
|
+
|
4
|
+
def initialize(samples = 10)
|
5
|
+
@accum = 0.0
|
6
|
+
@ticks = 0
|
7
|
+
@fps = 0.0
|
8
|
+
@samples = samples
|
9
|
+
@objs = @actors = @input_controllers = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(dt)
|
13
|
+
@ticks += 1
|
14
|
+
@accum += dt
|
15
|
+
if @ticks >= @samples
|
16
|
+
@fps = @ticks/@accum
|
17
|
+
@ticks = 0
|
18
|
+
@accum = 0.0
|
19
|
+
@objs = ObjectSpace.each_object.count
|
20
|
+
@actors = ObjectSpace.each_object(Lotu::Actor).count
|
21
|
+
@inputs = ObjectSpace.each_object(Lotu::InputController).count
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw
|
26
|
+
$window.font.draw("FPS: #{to_s}", 10, 10, 0, 1.0, 1.0, 0xffffff00)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
"Samples: #{@samples} FPS: #{format("%.2f",@fps)} Objs: #{@objs} Acts: #{@actors} InputsCs: #{@inputs}"
|
31
|
+
end
|
32
|
+
end
|
data/lib/lotu/window.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Lotu
|
2
|
+
class Window < Gosu::Window
|
3
|
+
extend HasBehavior
|
4
|
+
|
5
|
+
# delta time
|
6
|
+
attr_reader :dt
|
7
|
+
attr_accessor :update_queue, :draw_queue, :input_listeners, :font
|
8
|
+
|
9
|
+
def initialize(params={})
|
10
|
+
super(640, 480, false)
|
11
|
+
|
12
|
+
# Handy global window variable
|
13
|
+
$window = self
|
14
|
+
|
15
|
+
# Systems setup
|
16
|
+
@update_queue = []
|
17
|
+
@draw_queue = []
|
18
|
+
@input_register = Hash.new{|hash,key| hash[key] = []}
|
19
|
+
|
20
|
+
@fps_counter = FpsCounter.new
|
21
|
+
@last_time = Gosu::milliseconds
|
22
|
+
@font = Gosu::Font.new(self, Gosu::default_font_name, 14)
|
23
|
+
|
24
|
+
# Initialize the behaviors included in subclasses
|
25
|
+
init_behavior
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
new_time = Gosu::milliseconds
|
30
|
+
@dt = (new_time - @last_time)/1000.0
|
31
|
+
@last_time = new_time
|
32
|
+
@fps_counter.update(@dt)
|
33
|
+
|
34
|
+
@update_queue.each do |item|
|
35
|
+
item.update
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw
|
40
|
+
@draw_queue.each do |item|
|
41
|
+
item.draw
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def button_down(id)
|
46
|
+
@input_register[id].each do |item|
|
47
|
+
item.button_down(id)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def button_up(id)
|
52
|
+
@input_register[id].each do |item|
|
53
|
+
item.button_up(id)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Register controller
|
58
|
+
def register_for_input(controller)
|
59
|
+
controller.keys.each_key do |key|
|
60
|
+
@input_register[key] << controller
|
61
|
+
end
|
62
|
+
@update_queue << controller
|
63
|
+
end
|
64
|
+
|
65
|
+
def register_for_draw(object)
|
66
|
+
@draw_queue << object
|
67
|
+
end
|
68
|
+
|
69
|
+
# Meant to be overriden by behaviors
|
70
|
+
def init_behavior;end
|
71
|
+
end
|
72
|
+
end
|
data/lib/lotu.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
LOTU_ROOT = File.expand_path(File.join(File.dirname(__FILE__), 'lotu'))
|
2
|
+
$LOAD_PATH.unshift(LOTU_ROOT)
|
3
|
+
|
4
|
+
require 'gosu'
|
5
|
+
|
6
|
+
require 'behaviors/controllable'
|
7
|
+
require 'behaviors/resourceful'
|
8
|
+
require 'behaviors/drawable'
|
9
|
+
require 'behaviors/input_controller'
|
10
|
+
require 'behaviors/eventful'
|
11
|
+
require 'behaviors/has_behavior'
|
12
|
+
|
13
|
+
require 'fps'
|
14
|
+
require 'actor'
|
15
|
+
require 'cursor'
|
16
|
+
require 'window'
|
data/lotu.gemspec
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{lotu}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["lobo_tuerto"]
|
12
|
+
s.date = %q{2010-03-12}
|
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
|
+
s.email = %q{dev@lobotuerto.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"examples/hello_world/hello_world.rb",
|
27
|
+
"examples/media/Beep.wav",
|
28
|
+
"examples/media/CptnRuby Gem.png",
|
29
|
+
"examples/media/CptnRuby Map.txt",
|
30
|
+
"examples/media/CptnRuby Tileset.png",
|
31
|
+
"examples/media/CptnRuby.png",
|
32
|
+
"examples/media/Cursor.png",
|
33
|
+
"examples/media/Earth.png",
|
34
|
+
"examples/media/Explosion.wav",
|
35
|
+
"examples/media/LargeStar.png",
|
36
|
+
"examples/media/Smoke.png",
|
37
|
+
"examples/media/Soldier.png",
|
38
|
+
"examples/media/Space.png",
|
39
|
+
"examples/media/Star.png",
|
40
|
+
"examples/media/Starfighter.bmp",
|
41
|
+
"examples/media/amenoske.png",
|
42
|
+
"examples/media/crosshair.png",
|
43
|
+
"examples/media/lobo_tuerto.png",
|
44
|
+
"examples/media/title.png",
|
45
|
+
"examples/mouse_pointer/mouse.rb",
|
46
|
+
"lib/lotu.rb",
|
47
|
+
"lib/lotu/actor.rb",
|
48
|
+
"lib/lotu/behaviors/controllable.rb",
|
49
|
+
"lib/lotu/behaviors/drawable.rb",
|
50
|
+
"lib/lotu/behaviors/eventful.rb",
|
51
|
+
"lib/lotu/behaviors/has_behavior.rb",
|
52
|
+
"lib/lotu/behaviors/input_controller.rb",
|
53
|
+
"lib/lotu/behaviors/resourceful.rb",
|
54
|
+
"lib/lotu/cursor.rb",
|
55
|
+
"lib/lotu/fps.rb",
|
56
|
+
"lib/lotu/window.rb",
|
57
|
+
"lotu.gemspec"
|
58
|
+
]
|
59
|
+
s.homepage = %q{http://github.com/lobo-tuerto/lotu}
|
60
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
61
|
+
s.require_paths = ["lib"]
|
62
|
+
s.rubygems_version = %q{1.3.6}
|
63
|
+
s.summary = %q{A simple, agile Ruby game development framework.}
|
64
|
+
s.test_files = [
|
65
|
+
"examples/hello_world/hello_world.rb",
|
66
|
+
"examples/mouse_pointer/mouse.rb"
|
67
|
+
]
|
68
|
+
|
69
|
+
if s.respond_to? :specification_version then
|
70
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
|
+
s.specification_version = 3
|
72
|
+
|
73
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
74
|
+
s.add_development_dependency(%q<gosu>, [">= 0.7.18"])
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<gosu>, [">= 0.7.18"])
|
77
|
+
end
|
78
|
+
else
|
79
|
+
s.add_dependency(%q<gosu>, [">= 0.7.18"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lotu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- lobo_tuerto
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-12 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: gosu
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 7
|
30
|
+
- 18
|
31
|
+
version: 0.7.18
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: 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.
|
35
|
+
email: dev@lobotuerto.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- LICENSE
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- .document
|
45
|
+
- .gitignore
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- examples/hello_world/hello_world.rb
|
51
|
+
- examples/media/Beep.wav
|
52
|
+
- examples/media/CptnRuby Gem.png
|
53
|
+
- examples/media/CptnRuby Map.txt
|
54
|
+
- examples/media/CptnRuby Tileset.png
|
55
|
+
- examples/media/CptnRuby.png
|
56
|
+
- examples/media/Cursor.png
|
57
|
+
- examples/media/Earth.png
|
58
|
+
- examples/media/Explosion.wav
|
59
|
+
- examples/media/LargeStar.png
|
60
|
+
- examples/media/Smoke.png
|
61
|
+
- examples/media/Soldier.png
|
62
|
+
- examples/media/Space.png
|
63
|
+
- examples/media/Star.png
|
64
|
+
- examples/media/Starfighter.bmp
|
65
|
+
- examples/media/amenoske.png
|
66
|
+
- examples/media/crosshair.png
|
67
|
+
- examples/media/lobo_tuerto.png
|
68
|
+
- examples/media/title.png
|
69
|
+
- examples/mouse_pointer/mouse.rb
|
70
|
+
- lib/lotu.rb
|
71
|
+
- lib/lotu/actor.rb
|
72
|
+
- lib/lotu/behaviors/controllable.rb
|
73
|
+
- lib/lotu/behaviors/drawable.rb
|
74
|
+
- lib/lotu/behaviors/eventful.rb
|
75
|
+
- lib/lotu/behaviors/has_behavior.rb
|
76
|
+
- lib/lotu/behaviors/input_controller.rb
|
77
|
+
- lib/lotu/behaviors/resourceful.rb
|
78
|
+
- lib/lotu/cursor.rb
|
79
|
+
- lib/lotu/fps.rb
|
80
|
+
- lib/lotu/window.rb
|
81
|
+
- lotu.gemspec
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://github.com/lobo-tuerto/lotu
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- --charset=UTF-8
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.6
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: A simple, agile Ruby game development framework.
|
112
|
+
test_files:
|
113
|
+
- examples/hello_world/hello_world.rb
|
114
|
+
- examples/mouse_pointer/mouse.rb
|