shank 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/.gitignore +22 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +22 -0
  4. data/README.md +0 -0
  5. data/Rakefile +2 -0
  6. data/lib/assets/javascripts/engine.gamepads.coffee +46 -0
  7. data/lib/assets/javascripts/engine_stats.coffee +10 -0
  8. data/lib/assets/javascripts/error_handler.coffee +11 -0
  9. data/lib/assets/javascripts/game_keys.coffee +6 -0
  10. data/lib/assets/javascripts/gamepads.coffee +21 -0
  11. data/lib/assets/javascripts/gamepads.controller.coffee +138 -0
  12. data/lib/assets/javascripts/init.coffee +6 -0
  13. data/lib/assets/javascripts/joysticks.coffee +238 -0
  14. data/lib/assets/javascripts/jquery.hotkeys.coffee +161 -0
  15. data/lib/assets/javascripts/jquery.reverse_merge.coffee +21 -0
  16. data/lib/assets/javascripts/keydown.coffee +73 -0
  17. data/lib/assets/javascripts/mouse.coffee +66 -0
  18. data/lib/assets/javascripts/music.coffee +78 -0
  19. data/lib/assets/javascripts/pixie_canvas.coffee +739 -0
  20. data/lib/assets/javascripts/request_animation_frame.coffee +22 -0
  21. data/lib/assets/javascripts/shank.coffee +18 -0
  22. data/lib/assets/javascripts/sound.coffee +131 -0
  23. data/lib/assets/javascripts/storage.coffee +88 -0
  24. data/lib/shank/version.rb +3 -0
  25. data/lib/shank.rb +10 -0
  26. data/shank.gemspec +17 -0
  27. data/test/jquery.reverse_merge.coffee +43 -0
  28. data/test/keydown.coffee +19 -0
  29. data/test/pixie_canvas.coffee +18 -0
  30. data/test/request_animation_frame.coffee +7 -0
  31. data/test/sound.coffee +7 -0
  32. data/test/storage.coffee +47 -0
  33. data/test/xstats.coffee +7 -0
  34. data/vendor/assets/javascripts/xstats.js +767 -0
  35. metadata +113 -0
@@ -0,0 +1,21 @@
1
+ ###*
2
+ Merges properties from objects into target without overiding.
3
+ First come, first served.
4
+
5
+ @name reverseMerge
6
+ @methodOf jQuery#
7
+
8
+ @param {Object} target the object to merge the given properties onto
9
+ @param {Object} objects... one or more objects whose properties are merged onto target
10
+
11
+ @return {Object} target
12
+ ###
13
+ jQuery.extend
14
+ reverseMerge: (target, objects...) ->
15
+ for object in objects
16
+ for name of object
17
+ unless target.hasOwnProperty(name)
18
+ target[name] = object[name]
19
+
20
+ return target
21
+
@@ -0,0 +1,73 @@
1
+ $ ->
2
+ ###*
3
+ The global keydown property lets your query the status of keys.
4
+
5
+ <code><pre>
6
+ if keydown.left
7
+ moveLeft()
8
+
9
+ if keydown.a or keydown.space
10
+ attack()
11
+
12
+ if keydown.return
13
+ confirm()
14
+
15
+ if keydown.esc
16
+ cancel()
17
+ </pre></code>
18
+
19
+ @name keydown
20
+ @namespace
21
+ ###
22
+
23
+ ###*
24
+ The global justPressed property lets your query the status of keys. However,
25
+ unlike keydown it will only trigger once for each time the key is pressed.
26
+
27
+ <code><pre>
28
+ if justPressed.left
29
+ moveLeft()
30
+
31
+ if justPressed.a or justPressed.space
32
+ attack()
33
+
34
+ if justPressed.return
35
+ confirm()
36
+
37
+ if justPressed.esc
38
+ cancel()
39
+ </pre></code>
40
+
41
+ @name justPressed
42
+ @namespace
43
+ ###
44
+ window.keydown = {}
45
+ window.justPressed = {}
46
+
47
+ prevKeysDown = {}
48
+
49
+ keyName = (event) ->
50
+ jQuery.hotkeys.specialKeys[event.which] ||
51
+ String.fromCharCode(event.which).toLowerCase()
52
+
53
+ $(document).bind "keydown", (event) ->
54
+ key = keyName(event)
55
+ keydown[key] = true
56
+
57
+ $(document).bind "keyup", (event) ->
58
+ key = keyName(event)
59
+ keydown[key] = false
60
+
61
+ window.updateKeys = () ->
62
+ window.justPressed = {}
63
+ keydown.any = false
64
+
65
+ for key, value of keydown
66
+ justPressed[key] = value unless prevKeysDown[key]
67
+
68
+ justPressed.any = true if (justPressed[key] || mousePressed.left || mousePressed.right)
69
+ keydown.any = true if (value || mouseDown.left || mouseDown.right)
70
+
71
+ prevKeysDown = {}
72
+ for key, value of keydown
73
+ prevKeysDown[key] = value
@@ -0,0 +1,66 @@
1
+ $ ->
2
+ ###*
3
+ The global mouseDown property lets your query the status of mouse buttons.
4
+
5
+ <code><pre>
6
+ if mouseDown.left
7
+ moveLeft()
8
+
9
+ if mouseDown.right
10
+ attack()
11
+ </pre></code>
12
+
13
+ @name mouseDown
14
+ @namespace
15
+ ###
16
+
17
+ ###*
18
+ The global mousePressed property lets your query the status of mouse buttons.
19
+ However, unlike mouseDown it will only trigger the first time the button
20
+ pressed.
21
+
22
+ <code><pre>
23
+ if mousePressed.left
24
+ moveLeft()
25
+
26
+ if mousePressed.right
27
+ attack()
28
+ </pre></code>
29
+
30
+ @name mousePressed
31
+ @namespace
32
+ ###
33
+ window.mouseDown = {}
34
+ window.mousePressed = {}
35
+ window.mousePosition = Point(0, 0)
36
+
37
+ prevButtonsDown = {}
38
+
39
+ buttonNames =
40
+ 1: "left"
41
+ 2: "middle"
42
+ 3: "right"
43
+
44
+ buttonName = (event) ->
45
+ buttonNames[event.which]
46
+
47
+ $(document).bind "mousemove", (event) ->
48
+ #TODO Position relative to canvas element
49
+ mousePosition.x = event.pageX
50
+ mousePosition.y = event.pageY
51
+
52
+ $(document).bind "mousedown", (event) ->
53
+ mouseDown[buttonName(event)] = true
54
+
55
+ $(document).bind "mouseup", (event) ->
56
+ mouseDown[buttonName(event)] = false
57
+
58
+ window.updateMouse = ->
59
+ window.mousePressed = {}
60
+
61
+ for button, value of mouseDown
62
+ mousePressed[button] = value unless prevButtonsDown[button]
63
+
64
+ prevButtonsDown = {}
65
+ for button, value of mouseDown
66
+ prevButtonsDown[button] = value
@@ -0,0 +1,78 @@
1
+ ###*
2
+ The Music object provides an easy API to play
3
+ songs from your sounds project directory. By
4
+ default, the track is looped.
5
+
6
+ <code><pre>
7
+ Music.play('intro_theme')
8
+ </pre></code>
9
+
10
+ @name Music
11
+ @namespace
12
+ ###
13
+
14
+ Music = (->
15
+ # TODO: Load this from local storage of user preferences
16
+ globalMusicVolume = 1
17
+ trackVolume = 1
18
+
19
+ # TODO: Add format fallbacks
20
+ track = $ "<audio />",
21
+ loop: "loop"
22
+ .appendTo('body').get(0)
23
+
24
+ updateTrackVolume = ->
25
+ track.volume = globalMusicVolume * trackVolume
26
+
27
+ ###*
28
+ Set the global volume modifier for all music.
29
+
30
+ Any value set is clamped between 0 and 1. This is multiplied
31
+ into each individual track that plays.
32
+
33
+ If no argument is given return the current global music volume.
34
+
35
+ @name globalVolume
36
+ @methodOf Music
37
+ @param {Number} [newVolume] The volume to set
38
+ ###
39
+ globalVolume: (newVolume) ->
40
+ if newVolume?
41
+ globalMusicVolume = newVolume.clamp(0, 1)
42
+
43
+ updateTrackVolume()
44
+
45
+ return globalMusicVolume
46
+
47
+ ###*
48
+ Plays a music track.
49
+
50
+ @name play
51
+ @methodOf Music
52
+ @param {String} name The name of the track to play.
53
+ ###
54
+ play: (name) ->
55
+ updateTrackVolume()
56
+ # TODO: Format fallbacks
57
+ track.src = "#{BASE_URL}/sounds/#{name}.mp3"
58
+ track.play()
59
+
60
+ ###*
61
+ Get or set the current music volume. Any value passed is
62
+ clamped between 0 and 1. Use this to adjust the volume of
63
+ individual tracks or to increase or decrease volume during
64
+ gameplay.
65
+
66
+ @name volume
67
+ @methodOf Music
68
+ @param {Number} [newVolume] The volume to set to.
69
+ ###
70
+ volume: (newVolume) ->
71
+ if newVolume?
72
+ trackVolume = newVolume.clamp(0, 1)
73
+ updateTrackVolume()
74
+
75
+ return this
76
+ else
77
+ return trackVolume
78
+ )()