Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float ballX;
- float ballY;
- int pos1;
- int pos2;
- int d;
- float Gravity;
- void setup() {
- //size of screen
- size ( 1080, 720);
- // where ball starts
- ballX = width/2;
- ballY = height/2;
- // ball width and height or better known as diamater
- d = 25;
- }
- void draw() {
- background (0);
- ellipse (ballX, ballY, d, d);
- stroke (255);
- fill (255, 0, 0);
- if (keyPressed){
- fill (0, 255, 0);
- }
- // if the ball goes off the screen to the left it will appear on the right and vice versa
- if (ballX<=0-d) {
- ballX = width;
- } else if (ballX>=width+d){
- ballX=0;
- }
- // if the ball goes off the top of the screen it will appear on the bottom and vice versa
- if (ballY<=0-d) {
- ballY = height;
- } else if (ballY>=height+d){
- ballY=0;
- }
- println("ballX:" + ballX);
- println("ballY:" + ballY);
- }
- // ball movement and "speed" when "key" is pressed
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == UP) {
- ballY -=15;
- } else if (keyCode==DOWN) {
- ballY +=15;
- } else if (keyCode==RIGHT) {
- ballX +=15;
- } else if (keyCode==LEFT) {
- ballX -=15;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement