salamander 0.0.4 → 0.0.5
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/lib/salamander.rb
CHANGED
data/lib/salamander/actor.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Salamander
|
2
2
|
class Actor
|
3
|
+
# Executes code within the context of an Actor.
|
4
|
+
#
|
5
|
+
# If given a filename, reads the contents and evaluates it.
|
3
6
|
def self.draw (screen, filename=nil, &blk)
|
4
7
|
actor = new(screen)
|
5
8
|
if filename
|
@@ -19,40 +22,49 @@ module Salamander
|
|
19
22
|
end
|
20
23
|
|
21
24
|
|
25
|
+
# Get the current position as an array.
|
22
26
|
def position
|
23
27
|
[@x, @y]
|
24
28
|
end
|
25
29
|
|
30
|
+
# Move a given distance in the current direction.
|
26
31
|
def move (distance)
|
27
32
|
x = distance * Math.cos(angle) + @x
|
28
33
|
y = distance * Math.sin(angle) + @y
|
29
34
|
move_to(x, y)
|
30
35
|
end
|
31
36
|
|
37
|
+
# Move to a specific point
|
32
38
|
def move_to (x, y)
|
33
39
|
@x, @y = x, y
|
34
40
|
end
|
35
41
|
|
36
42
|
|
43
|
+
# The current angle, in radians.
|
37
44
|
def angle
|
38
45
|
@angle
|
39
46
|
end
|
40
47
|
|
48
|
+
# Turn towards a new direction.
|
49
|
+
#
|
50
|
+
# 'theta' may be :right, :left, :around, or a number of radians. Positive amounts of radians turn right, while negative amounts go to the left.
|
41
51
|
def turn (theta)
|
42
52
|
theta = DIRECTIONS[theta] if theta.is_a? Symbol
|
43
53
|
face(theta + angle)
|
44
54
|
end
|
45
55
|
|
56
|
+
# Face a specific direction
|
57
|
+
#
|
58
|
+
# 'theta' may be :north, :northeast, :east, etc. or a number of radians. 0 radians points east, and increasing amounts go clockwise.
|
46
59
|
def face (theta)
|
47
60
|
theta = COMPASS[theta] if theta.is_a? Symbol
|
48
61
|
@angle = theta % (2 * Math::PI)
|
49
62
|
end
|
50
63
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
64
|
+
# Gets or sets the current drawing color in numeric RGBA format.
|
65
|
+
#
|
66
|
+
# If 'color' is nil, gets the current color.
|
67
|
+
# Otherwise, 'color' must be in "#RRGGBB" notation.
|
56
68
|
def color (color=nil)
|
57
69
|
if not color then
|
58
70
|
@color
|
@@ -68,6 +80,7 @@ module Salamander
|
|
68
80
|
end
|
69
81
|
|
70
82
|
|
83
|
+
# The SDL surface being drawn to
|
71
84
|
def surface
|
72
85
|
@surface
|
73
86
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module Salamander::Drawing
|
2
2
|
module Line
|
3
|
-
|
3
|
+
# Draws a line from the current position to (x2, y2) in the current drawing color.
|
4
|
+
def line_to (x2, y2)
|
4
5
|
x1, y1 = position
|
5
6
|
move_to(x2, y2)
|
6
7
|
SDL::Gfx.aalineColor(surface, x1.round, y1.round, x2.round, y2.round, color)
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
+
# Draws a line 'distance' pixels long from the current position in the current drawing color.
|
11
|
+
def line (distance)
|
10
12
|
x1, y1 = position
|
11
13
|
move distance
|
12
14
|
x2, y2 = position
|
@@ -2,17 +2,21 @@ module Salamander::Drawing
|
|
2
2
|
module Shapes
|
3
3
|
include Line
|
4
4
|
|
5
|
+
# Draws a star-like shape with number 'points' of points.
|
6
|
+
#
|
7
|
+
# 'points' must be odd.
|
5
8
|
def star (points, length)
|
6
9
|
raise "The star must have an odd number of points" if points % 2 == 0
|
7
10
|
points.times do
|
8
|
-
|
11
|
+
line length
|
9
12
|
turn (720.0/points).degrees
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
16
|
+
# Draws a regular polygon with 'sides' sides, each of length 'length'
|
13
17
|
def polygon (sides, length)
|
14
18
|
sides.times do
|
15
|
-
|
19
|
+
line length
|
16
20
|
turn (360.0/sides).degrees
|
17
21
|
end
|
18
22
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
class Numeric
|
2
|
-
#
|
2
|
+
# Does nothing - input is assumed to be radians already
|
3
3
|
def radians
|
4
4
|
self
|
5
5
|
end
|
6
6
|
|
7
|
-
#
|
8
|
-
# Convert to radians
|
7
|
+
# Converts from degrees to radians.
|
9
8
|
def degrees
|
10
9
|
self / 180.0 * Math::PI
|
11
10
|
end
|
data/lib/salamander/version.rb
CHANGED