Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago

Question

4. What will the team agreement contain?

Answered: 1 week ago