Module: Smalruby
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/smalruby.rb,
lib/smalruby/color.rb,
lib/smalruby/world.rb,
lib/smalruby/canvas.rb,
lib/smalruby/console.rb,
lib/smalruby/version.rb,
lib/smalruby/character.rb,
lib/smalruby/event_handler.rb
Defined Under Namespace
Modules: Color
Classes: Canvas, Character, Console, EventHandler, World
Constant Summary
collapse
- VERSION =
'0.0.2'
Class Method Summary
collapse
Class Method Details
.await ⇒ Object
91
92
93
94
95
|
# File 'lib/smalruby.rb', line 91
def await
@draw_mutex.synchronize do
@draw_cv.wait(@draw_mutex)
end
end
|
.start ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/smalruby.rb', line 20
def start
@started = true
begin
if world.objects.any? { |o| /console/i !~ o.class.name }
Window.caption = File.basename($PROGRAM_NAME)
first = true
Window.fps = 15
Window.loop do
lock do
if first
world.objects.each do |object|
object.start
end
first = false
end
if Input.key_down?(K_ESCAPE)
exit
end
if Input.mouse_push?(M_LBUTTON) || Input.mouse_push?(M_RBUTTON) ||
Input.mouse_push?(M_MBUTTON)
x, y = Input.mouse_pos_x, Input.mouse_pos_y
s = Sprite.new(x, y)
s.collision = [0, 0, 1, 1]
buttons = []
if Input.mouse_down?(M_LBUTTON)
buttons << :left
end
if Input.mouse_down?(M_RBUTTON)
buttons << :right
end
if Input.mouse_down?(M_MBUTTON)
buttons << :center
end
s.check(world.objects).each do |o|
if o.respond_to?(:click)
o.click(buttons)
end
end
end
if (keys = Input.keys).length > 0
key_down_and_push(keys)
end
world.objects.delete_if { |o|
if !o.alive?
o.join
end
o.vanished?
}
Sprite.draw(world.objects)
end
end
else
world.objects.each do |object|
object.start
end
world.objects.each(&:join)
end
rescue SystemExit
end
end
|
.started? ⇒ Boolean
83
84
85
|
# File 'lib/smalruby.rb', line 83
def started?
return @started
end
|
.world ⇒ Object
87
88
89
|
# File 'lib/smalruby.rb', line 87
def world
return World.instance
end
|