Question: Question: With Processing, How do I move the robot to the left when the robot reaches the lower edge? Then, how do I move it

Question: With Processing, How do I move the robot to the left when the robot reaches the lower edge? Then, how do I move it upward when the robot reaches the left end?

PImage bgImg; // name of the background PImage robotImg; // name of the robot int robotX; // x position of the robot int robotY; // y position of the robot int velX; // x direction velocity of the robot int velY; // y direction velocity of the robot int speed; int direction; // speed of the robot

void setup() { size(750, 650); // set the window size bgImg = loadImage("space.png"); // background robotImg = loadImage("robot.png"); // robot

robotX = 0; // initial position of the robot robotY = 0; speed = 10; velX = speed; velY = speed; direction = 1; }

void draw() { image(bgImg, 0, 0); // display the background image(robotImg, robotX, robotY); // display the robot if(direction == 1) { velX = speed; velY = 0; if(robotX == width-300)//reach the right end { direction = 2; } }else if(direction == 2) { velX = 0; velY = speed; if(robotY == height-300)//reach the lower edge { direction = 3; } } robotX = robotX + velX; // make the robot move horizontally robotY = robotY + velY; // make the robot move vertically }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!