Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bars moves the player!

  • Loading branch information...
commit 0216ac25a45718824623126934bf8c2b3ebb19d2 1 parent b11fff6
@EndangeredMassa authored
View
74 web/public/javascripts/mind.js
@@ -1,3 +1,13 @@
+
+var moveSpeed = 0;
+var nextBar = 2500;
+var bars = [];
+
+var bg;
+var player;
+var stage;
+var currentKey;
+
function rand(min, max) {
return parseInt(Math.random() * max + min, 10);
}
@@ -48,10 +58,6 @@ window.onload = function(){
runGame();
};
-var bg;
-var player;
-var stage;
-
function runGame(){
var canvas;
@@ -74,6 +80,10 @@ function runGame(){
canvas = $('game');
stage = new Stage(canvas);
+ window.addEventListener('keydown', function(e){
+ currentKey = e.keyCode;
+ });
+
Ticker.addListener(window);
Ticker.useRAF = true;
Ticker.setInterval(17);
@@ -84,15 +94,65 @@ function buildInterfaceIfReady()
if(!bg || !player) return;
player.x = 120;
- player.y = 200;
+ player.y = 400;
stage.addChild(bg, player);
+ bars.push(addBar(0, 600));
stage.update();
}
-var moveSpeed = 1.0;
-function tick(){
+function addBar(x, y) {
+ var text = 'DFGI2G23DFG34DG2SFD82F2SF2SFEWF223';
+ var bar = new Text(text, '30px bold Courier New', '#0F0');
+ bar.x = x;
+ bar.y = y;
+ stage.addChild(bar);
+ return bar;
+}
+
+
+function getKey(){
+ if(currentKey == 37) return 'left';
+ if(currentKey == 39) return 'right';
+}
+
+function tick(elapsed) {
+ // board movement
+ for(var i=0; i < bars.length; i++) {
+ var bar = bars[i];
+ bar.y -= 2;
+
+ var playerBottom = player.y + 65;
+ //console.log(playerBottom + ' / ' + player.y + ' / ' + bar.y);
+ var barTop = bar.y - 22;
+
+ var onBar = barTop < playerBottom && barTop > player.y;
+ var overHole = false;
+
+ if(onBar && !overHole)
+ player.y -= (playerBottom - barTop);
+ }
+
+
+ // player movement
+ if(getKey() == 'left') {
+ moveSpeed = -1.0;
+ } else if(getKey() == 'right') {
+ moveSpeed = 1.0;
+ }
+
player.x += (moveSpeed * 4.5);
+ if (player.x > 548) { player.x = 548; }
+ if (player.x < 0) { player.x = 0; }
+
+
+ // next tick setup
+ nextBar -= elapsed;
+ if(nextBar<=0) {
+ nextBar = 2000;
+ bars.push(addBar(0, 600));
+ }
+
stage.update();
}
View
6 web/public/stylesheets/style.css
@@ -1,8 +1,8 @@
body {
- padding: 50px;
- font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+ font: 14px bold "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
-}
+}
+
View
13 web/views/index.jade
@@ -1,24 +1,21 @@
-<canvas id="game" width="600" height="800"></canvas>
-
+<canvas id="game" width="600" height="600"></canvas>
<br>
table
tr
td Attention
+ td Meditation
+ td Low Alpha
+ td High Alpha
+ tr
td
<canvas id="attention" width="400" height="100"></canvas><br><br>
- tr
- td Meditation
td
<canvas id="meditation" width="400" height="100"></canvas><br><br>
- tr
- td Low Alpha
td
<canvas id="low-alpha" width="400" height="100"></canvas><br><br>
- tr
- td High Alpha
td
<canvas id="high-alpha" width="400" height="100"></canvas><br><br>
Please sign in to comment.
Something went wrong with that request. Please try again.