Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Computer Programming-Help?
I have this pdf with instructions...how do I make the ball move? What controls what? A sample code would help greatly.
2 Answers
- ?Lv 65 years ago
If you look at the source code by adding "view-source:" infront of the website
(view-source:http://www.cs.unm.edu/~joel/cs105/src/CS105_Lab2_B...
The ball is movement randomly
var speedX = 5*Math.random() - 5*Math.random();
var speedY = 5*Math.random() - 5*Math.random();
What move the ball is:
ballX = ballX + speedX;
ballY = ballY + speedY;
I don't know any javascript, but just above the code:
ballX = ballX + speedX;
ballY = ballY + speedY;
change speedX and speedY by the keypressed:
pseudo code!!!
If up arrow key pressed
speedY = speedY + 1
If down arrow key pressed
speedY = speedY - 1
If left arrow key pressed
speedX = speedX - 1
If right arrow key pressed
speedX = speedX + 1