Permalink
Browse files

working on slide 7

  • Loading branch information...
1 parent 1bd2af0 commit b1fce5e28ef001cfd9dc8df33982d55ae5a49901 Juha Paananen committed Aug 29, 2011
Showing with 80 additions and 1 deletion.
  1. +36 −0 7.html
  2. +19 −0 7.js
  3. +24 −0 audio.js
  4. BIN audio/fire.ogg
  5. +1 −1 gamecontrol.js
View
@@ -0,0 +1,36 @@
+<html>
+<head>
+ <script type="text/javascript" src="lib/jquery.js"></script>
+ <script type="text/javascript" src="lib/underscore.js"></script>
+ <script type="text/javascript" src="lib/rx.js"></script>
+ <script type="text/javascript" src="lib/rx.jQuery.js"></script>
+ <script type="text/javascript" src="lib/raphael.js"></script>
+ <script type="text/javascript" src="lib/vector.js"></script>
+ <script type="text/javascript" src="lib/prettify.js"></script>
+ <script type="text/javascript" src="presentation.js"></script>
+ <script type="text/javascript" src="7.js"></script>
+ <script type="text/javascript" src="keystate.js"></script>
+ <script type="text/javascript" src="gamecontrol.js"></script>
+ <script type="text/javascript" src="audio.js"></script>
+ <script type="text/javascript">
+ $(function() { initPresentation(7) })
+ </script>
+ <link href="devday-rx.css" rel="stylesheet" type="text/css"/>
+ <link href="prettify.css" rel="stylesheet" type="text/css"/>
+</head>
+<body>
+ <div id="content">
+ <h1>Fire!</h1>
+ <ul>
+ <li>TODO</li>
+ </ul>
+ </div>
+ <div id="demo">
+ <div id="arena"></div>
+ </div>
+ <div id="src"><pre class="prettyprint"/></div>
+</body>
+</html><html>
+
+
+
View
@@ -0,0 +1,19 @@
+$(function() {
+ var startPos = Point(50, 50)
+ var controller = GameController(startPos)
+ var r = Raphael(document.getElementById('arena'), 200, 200);
+ var player = r.image("images/man-left-1.png", startPos.x, startPos.y, 40, 40)
+ controller.position.Subscribe(function (pos) { player.attr({x : pos.x, y : pos.y}) })
+
+ var animation = controller.position
+ .Scan(1, function(prev, _) { return prev % 2 + 1})
+ animation.Subscribe(function (index) {
+ player.attr({src : "images/man-left-" + index + ".png"})})
+
+ var angle = controller.direction
+ .Where(id)
+ .Select(function(vec) { return vec.getAngleDeg()})
+ angle.Subscribe(function(angle) { player.rotate(angle + 180, true) })
+
+ controller.fire.Subscribe(Audio().playSound("fire"))
+})
View
@@ -0,0 +1,24 @@
+function Audio() {
+ var sounds = {}
+
+ function loadSound(soundName) {
+ var audioElement = document.createElement('audio')
+ audioElement.setAttribute('src', "audio/" + soundName + ".ogg")
+ return audioElement
+ }
+
+ function getSound(soundName) {
+ if (!sounds[soundName]) {
+ sounds[soundName] = loadSound(soundName)
+ }
+ return sounds[soundName]
+ }
+ function play(soundName) {
+ getSound(soundName).play()
+ }
+ return {
+ playSound : function(soundName) { return function() { play(soundName) }},
+ }
+}
+
+
View
Binary file not shown.
View
@@ -16,5 +16,5 @@ function GameController(startPos) {
.Scan(startPos, function(pos, move) { return pos.add(move.times(4)) })
.StartWith(startPos)
- return { direction : direction, position : position }
+ return { direction : direction, position : position, fire : keyDowns(32) }
}

0 comments on commit b1fce5e

Please sign in to comment.