Modify a text file: $/6204.ski.pde
$/6204.ski.pde
//// BAM: always begin with comments to state your name and the purpose of your code! //// The following code was written by Loic Perez (61cst112) float skiX,skiY; // Ski guy position float stone1X,stone1Y; // Stone 1 float stone2X,stone2Y; // Stone 2 float stone3X,stone3Y; // Stone 3 float xspeed = 0.5; // Speed X (positive = right) float yspeed = 0.5; // Speed Y (positive = down) void setup() { size(600,400); skiX=5; // skiX start position skiY=200; // skiY start position stone1X=50; // stone1X start position stone1Y=0; // stone1Y start position stone2X=200; stone2Y=0; stone3X=350; stone3Y=0; } void draw() { background(40, 210, 255); // Background ellipseMode(CENTER); rectMode(CORNER); noStroke(); fill(255, 10); rect(0, 0, width, height); // Add the current speed to the location. stone1Y = stone1Y + yspeed; stone2Y = stone2Y + yspeed; stone3Y = stone3Y + yspeed; // Reset the starting point if (skiX > width) skiX=0; // Reset the skier X position if (stone1Y > height) stone1Y=0; if (stone2Y > height) stone2Y=0; if (stone3Y > height) stone3Y=0; // Action if (keyCode == DOWN) { skiY = skiY + yspeed; // Skier down movement only in case keyPressed } else if (keyCode == UP) { skiY = skiY - yspeed; // Skier up movement only in case keyPressed } else if (keyCode == LEFT) { // Skier left movement only in case keyPressed skiX = skiX - xspeed; } else if (keyCode == RIGHT) { // Skier right movement only in case keyPressed skiX = skiX + xspeed; } else { background(0, 0, 0); } // Death if (skiX == stone1X & skiY == stone1Y) skiX=0; // If the skier touches the stone if (skiX >= 400 & skiY <= 250) skiX=0; // If the skier touches the rectangle 3rd if (skiX <= 400 & skiY >= 300) skiX=0; // If the skier touches the rectangle down if (skiX <= 400 & skiY >= 300) skiY=200; // If the skier touches the rectangle down if (skiX <= 400 & skiY <= 100) skiX=0; // If the skier touches the rectangle up if (skiX <= 400 & skiY <= 100) skiY=200; // If the skier touches the rectangle up // Display at x,y location stroke(0); fill(255,120,0); // Orange ellipse(skiX,skiY,10,10); // Body fill(204,102,0); ellipse(stone1X,stone1Y,10,10); // stone1 ellipse(stone2X,stone2Y,10,10); // stone2 ellipse(stone3X,stone3Y,10,10); // stone3 fill (255,255,0); // Yellow rect(0,0,400,100); // Upper part : Upper block rect(0,300,400,100); // Lower part : Lower block rect(400,000,400,250); // 3rd one /*BAM*/ text( "Skier avoids falling stones", width/3, 10 ); /*BAM*/ text( "Loic Perez", 10, height-10 ); }