pixie_dust 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README +16 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/game.js +9200 -0
  8. data/lib/corelib.js +3331 -0
  9. data/lib/pixie_dust/version.rb +3 -0
  10. data/lib/pixie_dust.rb +14 -0
  11. data/pixie.json +15 -0
  12. data/pixie_dust.gemspec +29 -0
  13. data/source/active_bounds.coffee +48 -0
  14. data/source/ageable.coffee +23 -0
  15. data/source/bounded.coffee +282 -0
  16. data/source/camera.coffee +138 -0
  17. data/source/camera.fade.coffee +69 -0
  18. data/source/camera.flash.coffee +69 -0
  19. data/source/camera.rotate.coffee +11 -0
  20. data/source/camera.shake.coffee +27 -0
  21. data/source/camera.zoom.coffee +25 -0
  22. data/source/camera.zsort.coffee +13 -0
  23. data/source/clampable.coffee +61 -0
  24. data/source/collidable.coffee +126 -0
  25. data/source/collision.coffee +272 -0
  26. data/source/collision_response.coffee +28 -0
  27. data/source/color.coffee +1113 -0
  28. data/source/color_table.coffee +2534 -0
  29. data/source/controllable.coffee +66 -0
  30. data/source/cooldown.coffee +82 -0
  31. data/source/debuggable.coffee +253 -0
  32. data/source/drawable.coffee +167 -0
  33. data/source/dust_emitter.coffee +36 -0
  34. data/source/easing.coffee +38 -0
  35. data/source/emitter.coffee +7 -0
  36. data/source/emitterable.coffee +68 -0
  37. data/source/engine.coffee +274 -0
  38. data/source/engine.collision.coffee +77 -0
  39. data/source/engine.data.coffee +23 -0
  40. data/source/engine.delay.coffee +41 -0
  41. data/source/engine.fps_counter.coffee +32 -0
  42. data/source/engine.game_state.coffee +86 -0
  43. data/source/engine.joysticks.coffee +47 -0
  44. data/source/engine.keyboard.coffee +17 -0
  45. data/source/engine.levels.coffee +69 -0
  46. data/source/engine.mouse.coffee +16 -0
  47. data/source/engine.selector.coffee +166 -0
  48. data/source/engine.stats.coffee +16 -0
  49. data/source/engine.tilemap.coffee +41 -0
  50. data/source/engine_background.coffee +32 -0
  51. data/source/expirable.coffee +47 -0
  52. data/source/flickerable.coffee +78 -0
  53. data/source/follow.coffee +65 -0
  54. data/source/framerate.coffee +42 -0
  55. data/source/game_object.coffee +181 -0
  56. data/source/game_object.effect.coffee +33 -0
  57. data/source/game_object.meter.coffee +191 -0
  58. data/source/game_over.coffee +40 -0
  59. data/source/game_state.coffee +67 -0
  60. data/source/game_state.save_state.coffee +76 -0
  61. data/source/game_state.single_camera.coffee +40 -0
  62. data/source/game_state_cameras.coffee +33 -0
  63. data/source/level_state.coffee +32 -0
  64. data/source/movable.coffee +57 -0
  65. data/source/oscillator.coffee +18 -0
  66. data/source/pixie_dust.coffee +2 -0
  67. data/source/resource_loader.coffee +35 -0
  68. data/source/rotatable.coffee +38 -0
  69. data/source/sprite.coffee +181 -0
  70. data/source/text_effect.coffee +74 -0
  71. data/source/text_effect.floating.coffee +22 -0
  72. data/source/text_screen.coffee +38 -0
  73. data/source/tilemap.coffee +56 -0
  74. data/source/timed_events.coffee +78 -0
  75. data/source/title_screen.coffee +38 -0
  76. data/source/tween.coffee +70 -0
  77. data/test/active_bounds.coffee +67 -0
  78. data/test/bounded.coffee +98 -0
  79. data/test/camera.coffee +29 -0
  80. data/test/clampable.coffee +18 -0
  81. data/test/collidable.coffee +51 -0
  82. data/test/collision.coffee +70 -0
  83. data/test/color.coffee +533 -0
  84. data/test/controllable.coffee +108 -0
  85. data/test/cooldown.coffee +116 -0
  86. data/test/debuggable.coffee +71 -0
  87. data/test/drawable.coffee +31 -0
  88. data/test/emitter.coffee +0 -0
  89. data/test/emitterable.coffee +15 -0
  90. data/test/engine.coffee +228 -0
  91. data/test/engine_data.coffee +12 -0
  92. data/test/engine_delay.coffee +14 -0
  93. data/test/engine_selector.coffee +100 -0
  94. data/test/expirable.coffee +35 -0
  95. data/test/flickerable.coffee +51 -0
  96. data/test/follow.coffee +34 -0
  97. data/test/game_object.coffee +78 -0
  98. data/test/game_object_effect.coffee +17 -0
  99. data/test/metered.coffee +33 -0
  100. data/test/movable.coffee +46 -0
  101. data/test/oscillator.coffee +28 -0
  102. data/test/resource_loader.coffee +7 -0
  103. data/test/rotatable.coffee +20 -0
  104. data/test/sprite.coffee +21 -0
  105. data/test/text.coffee +25 -0
  106. data/test/timed_events.coffee +23 -0
  107. data/test/tweening.coffee +18 -0
  108. metadata +233 -0
@@ -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
+
@@ -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,18 @@
1
+ module "Clampable"
2
+
3
+ test "#clamp", ->
4
+ o = GameObject
5
+ x: 1500
6
+
7
+ max = 100
8
+
9
+ o.clamp
10
+ x:
11
+ min: 0
12
+ max: max
13
+
14
+ o.trigger "afterUpdate"
15
+
16
+ equals o.I.x, max
17
+
18
+ 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()