Skip to content

Commit

Permalink
Have the player reset when out of world limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sourrust committed Dec 1, 2012
1 parent 5e5f896 commit 0bf5c20
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions scripts/components/mainclone.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
define('mainclone', ['crafty','box2d','box2dtwoway','camera','clone'],
define('mainclone',

function(Crafty) {
[ 'crafty'
, 'box2d'
, 'box2dtwoway'
, 'camera'
, 'clone'
, 'entry'
],

function(Crafty, b2) {
'use strict';

Crafty.c('MainClone', {
init: function() {
this.addComponent('Clone, Camera, b2Twoway');

this.twoway(10, 10);

this.bind('Change', function(position) {
var clone, i, l, vec;

// Reset to starting position if player falls off map
if(position._y > 640) {
vec = new b2.Vec2(400/32, 500/32);
this.body.SetPosition(vec);

l = this._clones.length;
vec.x = 0;
vec.y = 500 / 32;
for(i = 0; i < l; i++) {
clone = this._clones[i];
clone.visible = false;
clone.body.SetPosition(vec);
}
}
});
}
});
});

0 comments on commit 0bf5c20

Please sign in to comment.