Module: Chobo
- Defined in:
- lib/chobo.rb,
lib/chobo/vec2.rb,
lib/chobo/entity.rb,
lib/chobo/helpers.rb,
lib/chobo/version.rb,
lib/chobo/behavior.rb,
lib/chobo/commands.rb,
lib/chobo/animation.rb,
lib/chobo/game_object.rb
Defined Under Namespace
Classes: Animation, Behavior, Commands, Entity, GameObject, Vec2
Constant Summary
collapse
- VERSION =
"0.0.2"
Class Method Summary
collapse
-
.clamp(value, min, max) ⇒ Object
-
.color(r = 255, g = 255, b = 255, a = 255) ⇒ Object
-
.hermite(v1, t1, v2, t2, weight) ⇒ Object
value1, tangent1, value2, tangent2.
-
.lerp(x, y, w) ⇒ Object
-
.lerp_angle(from, to, frac) ⇒ Object
-
.load_image(window, name) ⇒ Object
-
.load_sample(window, name) ⇒ Object
-
.load_song(window, name) ⇒ Object
-
.load_tiles(window, name, tile_width, tile_height) ⇒ Object
-
.qlerp(min, max, weight) ⇒ Object
cubic interpolation using a hermite spline, aka smooth step.
-
.wrap_angle(angle) ⇒ Object
Class Method Details
.clamp(value, min, max) ⇒ Object
76
77
78
79
80
|
# File 'lib/chobo/helpers.rb', line 76
def self.clamp(value, min, max)
return min if value < min
return max if value > max
value
end
|
.color(r = 255, g = 255, b = 255, a = 255) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/chobo/helpers.rb', line 22
def self.color(r = 255, g = 255, b = 255, a = 255)
clr = Gosu::Color.new
clr.red = r
clr.green = g
clr.blue = b
clr.alpha = a
clr
end
|
.hermite(v1, t1, v2, t2, weight) ⇒ Object
value1, tangent1, value2, tangent2
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/chobo/helpers.rb', line 62
def self.hermite(v1, t1, v2, t2, weight)
sCubed = weight * weight * weight
sSquared = weight * weight
result = 0.0
if weight == 0.0
result = v1
elsif weight == 1.0
result = v2
else
result = (2 * v1 - 2 * v2 + t2 + t1) * sCubed + (3 * v2 - 3 * v1 - 2 * t1 - t2) * sSquared + t1 * weight + v1
end
result
end
|
.lerp(x, y, w) ⇒ Object
52
53
54
|
# File 'lib/chobo/helpers.rb', line 52
def self.lerp x, y, w
x + (y - x) * w
end
|
.lerp_angle(from, to, frac) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/chobo/helpers.rb', line 41
def self.lerp_angle from, to, frac
if to - from > 180.to_radians
to -= 360.to_radians
end
if to - from < -180.to_radians
to += 360.to_radians
end
from + frac * (to - from)
end
|
.load_image(window, name) ⇒ Object
5
6
7
8
|
# File 'lib/chobo/helpers.rb', line 5
def self.load_image(window, name)
return @images[name] if @images[name]
return @images[name] = Gosu::Image.new(window, "#{CONTENT_ROOT}/gfx/#{name}.png")
end
|
.load_sample(window, name) ⇒ Object
14
15
16
|
# File 'lib/chobo/helpers.rb', line 14
def self.load_sample(window, name)
Gosu::Sample.new(window, "#{CONTENT_ROOT}/audio/#{name}.wav")
end
|
.load_song(window, name) ⇒ Object
18
19
20
|
# File 'lib/chobo/helpers.rb', line 18
def self.load_song(window, name)
Gosu::Song.new(window, "#{CONTENT_ROOT}/audio/#{name}.wav")
end
|
.load_tiles(window, name, tile_width, tile_height) ⇒ Object
10
11
12
|
# File 'lib/chobo/helpers.rb', line 10
def self.load_tiles(window, name, tile_width, tile_height)
Gosu::Image.load_tiles(window, "#{CONTENT_ROOT}/gfx/#{name}.png", tile_width, tile_height, true)
end
|
.qlerp(min, max, weight) ⇒ Object
cubic interpolation using a hermite spline, aka smooth step
57
58
59
|
# File 'lib/chobo/helpers.rb', line 57
def self.qlerp(min, max, weight)
hermite(min, 0.0, max, 0.0, weight)
end
|
.wrap_angle(angle) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/chobo/helpers.rb', line 31
def self.wrap_angle(angle)
while angle > 360.to_radians
angle -= 360.to_radians
end
while angle < 0.0
angle += 360.to_radians
end
angle
end
|