Skip to content

Instantly share code, notes, and snippets.

@arturcarvalho
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturcarvalho/2c3af68d4e99fb151fd8 to your computer and use it in GitHub Desktop.
Save arturcarvalho/2c3af68d4e99fb151fd8 to your computer and use it in GitHub Desktop.
getFloorY = function(item) {
return dims.atticHeight + item.room * dims.roomHeight - dims.floorHeightChars - item.height;
}
if() { // below bsment
} else { // above
if (item.dragged) {
for (var i = 0; i < floors.length; i++) {
if(item.y < getFloorY(item) && item.room !== i) { // (room !== i) just to reduce assignments
item.room = i;
break;
}
};
} else {
if (item.y >= getFloorY(item)) { // on the ground, stop the fall, animate
item.y = getFloorY(item);
item.body.velocity.y = 0;
item.onFloor = true;
item.state = (game.rnd.frac() > 0.5) ? 0 : 1; // walk left or right
}
}
}
------------
function doBooks(){
bookGroup = game.add.group();
//if there are books left, add them to piles in the basement
if(books > 0) {
var lastBookPile, i = 0;
for (i < books; i++) {
if(i > 0 && lastBookPile) {
lastBookPile.frame += 1;
}
if(i % 10 === 0){
var floorBasementY = overallHeight - dims.floorHeightBooks;
var nudgeBasementBooks = 180;
var newBookPile = game.add.sprite(nudgeBasementBooks + (i*36), floorBasementY, 'bookPileSheet');
bookGroup.add(newBookPile);
lastBookPile = newBookPile;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment