float heroW=30, heroH=40, heroR=10; // Size of creature; float heroM=1.0; float heroX=0, heroY=0; //position of creature float heroDX=2, heroDY=1; // Speed (diagonally). float bombX=0,bombY=0, bombW=20,bombH=20; float bombDX=2, bombDY=1; int sunX,sunY,sunR; void setup() { size(640,480); reset(); } void reset() // Reinitialize all values // { heroW=30; heroH=40; heroR=10; // Size of creature; heroM=1.0; heroX=0; heroY=0; // Position of creature. heroDX=2; heroDY=1; // Speed (diagonally). sunX= width-100; sunY= 50; sunR= 50; } void draw() //// Move and draw hero (and scene). { drawScene(); moveHero(); drawHero(); drawBomb(); } void drawScene() { background(200,220,255); //// Sun. fill(255,255,0); noStroke(); ellipse( sunX,sunY, sunR,sunR ); //// Grass at bottom; noStroke(); fill(100,255,100); rect(0,height/4, width,height); } void drawHero() //// Draw him { strokeWeight(0); fill(100,0,255); ellipseMode(RADIUS); ellipse( heroX+heroW/2, heroY-heroR, heroR, heroR); fill(random(205),random(250),random(200)); rectMode(CORNER); rect( heroX, heroY, heroW,heroH ); stroke( 0, 0, 255 ); // Blue legs ); strokeWeight(6); float legY; legY= heroY+heroH; // Top of legs. line( heroX+2, legY, heroX-random(1), legY+30 ); line( heroX+heroW-2, legY, heroX+heroW+random(1), legY+30 ); strokeWeight(4); float armY; armY= heroY+5; // Top of arms. line( heroX, armY, heroX-random(1), armY+25 ); line( heroX+heroW, armY, heroX+heroW+random(1), armY+25 ); strokeWeight(0); } void moveHero() //// { heroX= (heroX + heroDX) % width; heroY= (heroY + heroDY) % height; text( "heroY: "+heroY, 10, height-20); if (heroX>630) { heroDX= -heroDX; } else if (heroX<0) { heroDX = -heroDX; } if (heroY>400) { heroDY= -heroDY; } else if (heroY<170) { heroDY = -heroDY; } } void mousePressed() //// Jump here, when click { heroX= mouseX; heroY= mouseY; } void keyPressed() //// Which key was pressed? { if (key == 'X') heroDX= heroDX + 1; // Faster in DX. if (key == 'x') heroDX= heroDX - 1; // Slower in DX. if (key == 'Y') heroDY= heroDY + 1; // Faster in DY. if (key == 'y') heroDY= heroDY - 1; // Slower in DY. if (key == '+') heroH= heroH * 1.25; // Make 25% taller if (key == '-') heroH= heroH * 0.75; // Make 25% smaller if (key == 'H') heroR++; // Head bigger/smaller if (key == 'h') heroR--; if (key=='r') reset(); } void drawBomb() //// Draw bomb { // Check if bomb exists. if (bombY <0 || bombY>height) { return; } //// Make bomb fall; bombY += bombDY; //// Draw bomb; fill(200,0,100); ellipse( bombX, bombY, 20,80 ); }