Skip to content

Instantly share code, notes, and snippets.

@walterhiggins
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterhiggins/59a964996fc335406ec0 to your computer and use it in GitHub Desktop.
Save walterhiggins/59a964996fc335406ec0 to your computer and use it in GitHub Desktop.
A Minecraft Trampoline (Version 2)
/*global require, events */
var blocks = require('blocks'),
sounds = require('sounds');
var bouncers = {};
function bounceOn___(event){
var player = event.player;
var id = player.ID;
var bounce = bouncers[id] || 0.75; // get bounciness (default 0.75)
var location = player.location;
// need to convert coordinates to integers
var x = Math.floor(location.x);
var y = Math.floor(location.y - 1 ); // what's underfoot?
var z = Math.floor(location.z);
var block = location.world.getBlockAt(x, y, z);
if (block.typeId === blocks.___){
sounds.slimeAttack(player); // play an appropriate sound
player.motionY = bounce; // set player in motion
bouncers[id] = bounce * 1.05; // increase bounce for next jump
return;
}
if ( player.isOnGround() )
bouncers[id] = 0.75; // reset bounciness
}
events.playerMove( bounceOn___ );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment