Last active
August 29, 2015 14:15
-
-
Save walterhiggins/59a964996fc335406ec0 to your computer and use it in GitHub Desktop.
A Minecraft Trampoline (Version 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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