/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.fkfbQpzyrQ9/rev.4 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * Jump Example (v1.0) * by GoToLoop (2013/Aug) * * http://forum.processing.org/topic/i-need-help-30-7-2013 * http://studio.processingtogether.com/sp/pad/export/ro.9LZizxKsIAY4F/latest */ final static short DIM = 100, SPD = 4, BOLD = 4; final static short FLOOR = 215, JUMP = 75; static int dir, x, y = FLOOR; void setup() { size(DIM + x + BOLD/2, DIM + y + BOLD/2); fill(#0000FF); stroke(#FFFF00); strokeWeight(BOLD); } void draw() { background(0100); if (dir != 0) move(); rect(x, y, DIM, DIM); } void keyPressed() { if (dir == 0) dir = -SPD; } void mousePressed() { keyPressed(); } static void move() { if ((y += dir) < JUMP) dir *= -1; else if (y > FLOOR) { dir = 0; y = FLOOR; } }