pixie_dust 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README +16 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/game.js +9200 -0
- data/lib/corelib.js +3331 -0
- data/lib/pixie_dust/version.rb +3 -0
- data/lib/pixie_dust.rb +14 -0
- data/pixie.json +15 -0
- data/pixie_dust.gemspec +29 -0
- data/source/active_bounds.coffee +48 -0
- data/source/ageable.coffee +23 -0
- data/source/bounded.coffee +282 -0
- data/source/camera.coffee +138 -0
- data/source/camera.fade.coffee +69 -0
- data/source/camera.flash.coffee +69 -0
- data/source/camera.rotate.coffee +11 -0
- data/source/camera.shake.coffee +27 -0
- data/source/camera.zoom.coffee +25 -0
- data/source/camera.zsort.coffee +13 -0
- data/source/clampable.coffee +61 -0
- data/source/collidable.coffee +126 -0
- data/source/collision.coffee +272 -0
- data/source/collision_response.coffee +28 -0
- data/source/color.coffee +1113 -0
- data/source/color_table.coffee +2534 -0
- data/source/controllable.coffee +66 -0
- data/source/cooldown.coffee +82 -0
- data/source/debuggable.coffee +253 -0
- data/source/drawable.coffee +167 -0
- data/source/dust_emitter.coffee +36 -0
- data/source/easing.coffee +38 -0
- data/source/emitter.coffee +7 -0
- data/source/emitterable.coffee +68 -0
- data/source/engine.coffee +274 -0
- data/source/engine.collision.coffee +77 -0
- data/source/engine.data.coffee +23 -0
- data/source/engine.delay.coffee +41 -0
- data/source/engine.fps_counter.coffee +32 -0
- data/source/engine.game_state.coffee +86 -0
- data/source/engine.joysticks.coffee +47 -0
- data/source/engine.keyboard.coffee +17 -0
- data/source/engine.levels.coffee +69 -0
- data/source/engine.mouse.coffee +16 -0
- data/source/engine.selector.coffee +166 -0
- data/source/engine.stats.coffee +16 -0
- data/source/engine.tilemap.coffee +41 -0
- data/source/engine_background.coffee +32 -0
- data/source/expirable.coffee +47 -0
- data/source/flickerable.coffee +78 -0
- data/source/follow.coffee +65 -0
- data/source/framerate.coffee +42 -0
- data/source/game_object.coffee +181 -0
- data/source/game_object.effect.coffee +33 -0
- data/source/game_object.meter.coffee +191 -0
- data/source/game_over.coffee +40 -0
- data/source/game_state.coffee +67 -0
- data/source/game_state.save_state.coffee +76 -0
- data/source/game_state.single_camera.coffee +40 -0
- data/source/game_state_cameras.coffee +33 -0
- data/source/level_state.coffee +32 -0
- data/source/movable.coffee +57 -0
- data/source/oscillator.coffee +18 -0
- data/source/pixie_dust.coffee +2 -0
- data/source/resource_loader.coffee +35 -0
- data/source/rotatable.coffee +38 -0
- data/source/sprite.coffee +181 -0
- data/source/text_effect.coffee +74 -0
- data/source/text_effect.floating.coffee +22 -0
- data/source/text_screen.coffee +38 -0
- data/source/tilemap.coffee +56 -0
- data/source/timed_events.coffee +78 -0
- data/source/title_screen.coffee +38 -0
- data/source/tween.coffee +70 -0
- data/test/active_bounds.coffee +67 -0
- data/test/bounded.coffee +98 -0
- data/test/camera.coffee +29 -0
- data/test/clampable.coffee +18 -0
- data/test/collidable.coffee +51 -0
- data/test/collision.coffee +70 -0
- data/test/color.coffee +533 -0
- data/test/controllable.coffee +108 -0
- data/test/cooldown.coffee +116 -0
- data/test/debuggable.coffee +71 -0
- data/test/drawable.coffee +31 -0
- data/test/emitter.coffee +0 -0
- data/test/emitterable.coffee +15 -0
- data/test/engine.coffee +228 -0
- data/test/engine_data.coffee +12 -0
- data/test/engine_delay.coffee +14 -0
- data/test/engine_selector.coffee +100 -0
- data/test/expirable.coffee +35 -0
- data/test/flickerable.coffee +51 -0
- data/test/follow.coffee +34 -0
- data/test/game_object.coffee +78 -0
- data/test/game_object_effect.coffee +17 -0
- data/test/metered.coffee +33 -0
- data/test/movable.coffee +46 -0
- data/test/oscillator.coffee +28 -0
- data/test/resource_loader.coffee +7 -0
- data/test/rotatable.coffee +20 -0
- data/test/sprite.coffee +21 -0
- data/test/text.coffee +25 -0
- data/test/timed_events.coffee +23 -0
- data/test/tweening.coffee +18 -0
- metadata +233 -0
data/test/bounded.coffee
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module "Bounds"
|
2
|
+
|
3
|
+
test 'it should have #distance', ->
|
4
|
+
player = GameObject()
|
5
|
+
|
6
|
+
player.include Bounded
|
7
|
+
|
8
|
+
ok player.distance
|
9
|
+
|
10
|
+
test 'it should proxy #distance to Point.distance', ->
|
11
|
+
player = GameObject
|
12
|
+
x: 50
|
13
|
+
y: 50
|
14
|
+
width: 10
|
15
|
+
height: 10
|
16
|
+
|
17
|
+
player.include Bounded
|
18
|
+
|
19
|
+
enemy = GameObject
|
20
|
+
x: 110
|
21
|
+
y: 120
|
22
|
+
width: 7
|
23
|
+
height: 20
|
24
|
+
|
25
|
+
equals player.distance(enemy), Point.distance(player.position(), enemy.position())
|
26
|
+
|
27
|
+
test "#bounds returns correct x, y, width, height", ->
|
28
|
+
x = 5
|
29
|
+
y = 10
|
30
|
+
width = 50
|
31
|
+
height = 75
|
32
|
+
|
33
|
+
obj = GameObject
|
34
|
+
x: x
|
35
|
+
y: y
|
36
|
+
width: width
|
37
|
+
height: height
|
38
|
+
|
39
|
+
obj.include(Bounded)
|
40
|
+
|
41
|
+
equals obj.bounds().x, x - width/2
|
42
|
+
equals obj.bounds().y, y - height/2
|
43
|
+
equals obj.bounds().width, width
|
44
|
+
equals obj.bounds().height, height
|
45
|
+
|
46
|
+
test "#centeredBounds returns correct x, y, xw, yx", ->
|
47
|
+
x = -5
|
48
|
+
y = 20
|
49
|
+
|
50
|
+
obj = GameObject
|
51
|
+
x: x
|
52
|
+
y: y
|
53
|
+
width: 100,
|
54
|
+
height: 200
|
55
|
+
|
56
|
+
obj.include(Bounded)
|
57
|
+
bounds = obj.centeredBounds()
|
58
|
+
|
59
|
+
equals bounds.x, x
|
60
|
+
equals bounds.y, y
|
61
|
+
equals bounds.xw, 100 / 2
|
62
|
+
equals bounds.yw, 200 / 2
|
63
|
+
|
64
|
+
test "#bounds(width, height) returns correct x, y", ->
|
65
|
+
x = 20
|
66
|
+
y = 10
|
67
|
+
width = 15
|
68
|
+
height = 25
|
69
|
+
|
70
|
+
offsetX = 7.5
|
71
|
+
offsetY = 12
|
72
|
+
|
73
|
+
obj = GameObject
|
74
|
+
x: x
|
75
|
+
y: y
|
76
|
+
width: width
|
77
|
+
height: height
|
78
|
+
|
79
|
+
obj.include(Bounded)
|
80
|
+
bounds = obj.bounds(offsetX, offsetY)
|
81
|
+
|
82
|
+
equals bounds.x, obj.center().x + offsetX - width/2
|
83
|
+
equals bounds.y, obj.center().y + offsetY - height/2
|
84
|
+
|
85
|
+
test "#center returns correct center point", ->
|
86
|
+
obj = GameObject
|
87
|
+
x: -5
|
88
|
+
y: 20
|
89
|
+
width: 10
|
90
|
+
height: 60
|
91
|
+
|
92
|
+
obj.include(Bounded)
|
93
|
+
center = obj.center()
|
94
|
+
|
95
|
+
ok center.equal(Point(-5, 20))
|
96
|
+
|
97
|
+
module()
|
98
|
+
|
data/test/camera.coffee
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module "Camera"
|
2
|
+
|
3
|
+
MockCanvas = ->
|
4
|
+
clear: ->
|
5
|
+
context: ->
|
6
|
+
beginPath: ->
|
7
|
+
clip: ->
|
8
|
+
rect: ->
|
9
|
+
drawRect: ->
|
10
|
+
fill: ->
|
11
|
+
withTransform: (t, fn) ->
|
12
|
+
fn(@)
|
13
|
+
clip: ->
|
14
|
+
|
15
|
+
test "create", ->
|
16
|
+
ok Camera()
|
17
|
+
|
18
|
+
test "overlay", 1, ->
|
19
|
+
object = GameObject()
|
20
|
+
object.bind 'overlay', ->
|
21
|
+
ok true
|
22
|
+
|
23
|
+
canvas = MockCanvas()
|
24
|
+
|
25
|
+
camera = Camera()
|
26
|
+
|
27
|
+
camera.trigger 'overlay', canvas, [object]
|
28
|
+
# Clear out the module
|
29
|
+
module()
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module "Collidable"
|
2
|
+
|
3
|
+
test "#separate", ->
|
4
|
+
leftObject = GameObject
|
5
|
+
x: 50
|
6
|
+
y: 50
|
7
|
+
width: 20
|
8
|
+
height: 20
|
9
|
+
velocity: Point(1, 0)
|
10
|
+
.include "Collidable"
|
11
|
+
|
12
|
+
rightObject = GameObject
|
13
|
+
x: 60
|
14
|
+
y: 50
|
15
|
+
width: 20
|
16
|
+
height: 20
|
17
|
+
velocity: Point(0, 0)
|
18
|
+
.include "Collidable"
|
19
|
+
|
20
|
+
Collidable.separate(leftObject, rightObject)
|
21
|
+
|
22
|
+
equal leftObject.I.x, 45
|
23
|
+
equal rightObject.I.x, 65
|
24
|
+
#ok leftObject.I.velocity.equal(Point(0, 0))
|
25
|
+
#ok rightObject.I.velocity.equal(Point(1, 0))
|
26
|
+
|
27
|
+
test "conservation of momentum", ->
|
28
|
+
leftObject = GameObject
|
29
|
+
x: 50
|
30
|
+
y: 50
|
31
|
+
width: 20
|
32
|
+
height: 20
|
33
|
+
mass: 5
|
34
|
+
velocity: Point(1, 0)
|
35
|
+
.include "Collidable"
|
36
|
+
|
37
|
+
rightObject = GameObject
|
38
|
+
x: 60
|
39
|
+
y: 50
|
40
|
+
width: 20
|
41
|
+
height: 20
|
42
|
+
mass: 1
|
43
|
+
velocity: Point(0, 0)
|
44
|
+
.include "Collidable"
|
45
|
+
|
46
|
+
Collidable.separate(leftObject, rightObject)
|
47
|
+
|
48
|
+
#equal leftObject.I.velocity.x, 0
|
49
|
+
#equal rightObject.I.velocity.x, 5
|
50
|
+
|
51
|
+
module()
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module "Collision"
|
2
|
+
|
3
|
+
test "circular", ->
|
4
|
+
c1 = {x: 0, y: 0, radius: 2}
|
5
|
+
c2 = {x: 4, y: 3, radius: 4}
|
6
|
+
c3 = {x: 5, y: 6, radius: 1}
|
7
|
+
|
8
|
+
equal Collision.circular(c1, c2), true
|
9
|
+
equal Collision.circular(c1, c3), false
|
10
|
+
equal Collision.circular(c2, c3), true
|
11
|
+
|
12
|
+
test "collides (single objects)", 1, ->
|
13
|
+
player = GameObject
|
14
|
+
x: 0
|
15
|
+
y: 0
|
16
|
+
width: 10
|
17
|
+
height: 10
|
18
|
+
|
19
|
+
enemy = GameObject
|
20
|
+
x: 5
|
21
|
+
y: 5
|
22
|
+
width: 10
|
23
|
+
height: 10
|
24
|
+
|
25
|
+
Collision.collide player, enemy, (p, e) ->
|
26
|
+
ok(true)
|
27
|
+
|
28
|
+
test "collides (single and array)", 2, ->
|
29
|
+
player = GameObject
|
30
|
+
x: 0
|
31
|
+
y: 0
|
32
|
+
width: 10
|
33
|
+
height: 10
|
34
|
+
|
35
|
+
enemy = GameObject
|
36
|
+
x: 5
|
37
|
+
y: 5
|
38
|
+
width: 10
|
39
|
+
height: 10
|
40
|
+
|
41
|
+
enemy2 = GameObject
|
42
|
+
x: -5
|
43
|
+
y: -5
|
44
|
+
width: 10
|
45
|
+
height: 10
|
46
|
+
|
47
|
+
Collision.collide player, [enemy, enemy2], (p, e) ->
|
48
|
+
ok(true)
|
49
|
+
|
50
|
+
test "Collision.rayRectangle with both types of bounds", ->
|
51
|
+
rect = GameObject
|
52
|
+
x: 25
|
53
|
+
y: 0
|
54
|
+
width: 10
|
55
|
+
height: 10
|
56
|
+
|
57
|
+
start = Point(0, 0)
|
58
|
+
direction = Point(1, 0)
|
59
|
+
|
60
|
+
p1 = Collision.rayRectangle start, direction, rect.bounds()
|
61
|
+
|
62
|
+
equals p1.y, 0
|
63
|
+
equals p1.x, 20
|
64
|
+
|
65
|
+
p2 = Collision.rayRectangle start, direction, rect.centeredBounds()
|
66
|
+
|
67
|
+
equals p2.y, 0
|
68
|
+
equals p2.x, 20
|
69
|
+
|
70
|
+
module()
|