float x,y, wall; float blocks; float ballX, ballY, xspeedball=5, yspeedball=-2; //Pacman //Albert Ng void setup() { size( 480, 240 ); // RESET: // Start the sun half-way across the screen. ballX= width/2; ballY= height/2; } void draw() { // SCENE: Maze background( 0, 0, 0 ); // Black background fill( 255, 255, 0 ); ellipse( ballX, ballY, 20,20 ); // Pacball fill(0, 0, 255 ); rect( 0, 0, 480,10 ); //Wall boundaries rect( 0, 230, 480,10 ); rect( 0, 10, 10, 280 ); rect( 470, 10, 10, 280 ); rect( 30, 40, 100, 20 ); //Maze rect( 30, 90, 100, 20 ); rect( 200, 200, 10, 60 ); action(); messages(); } void action() { fill(255, 255, 255); ballX=ballX + xspeedball; ballY=ballY - yspeedball; if (ballX > width-20) { xspeedball = -xspeedball; } if (ballX < wall) { xspeedball = - xspeedball; } if (ballY < wall+10 ) { yspeedball = - yspeedball; } if (ballY > height-20 ) { yspeedball = - yspeedball; } /* rect( 30, 40, 100, 20 ); //Maze rect( 30, 90, 100, 20 ); rect( 200, 200, 10, 60 ); */ // Bounce off maze surface at: rect( 30, 40, 100, 20 ); //Maze if (yspeedball<0 && ballY>40 && ballY<40+5 && ballX>30 && ballX<130 ) { yspeedball = - yspeedball; } if (yspeedball>0 && ballY>40+20 && ballY<40+20+5 && ballX>30 && ballX<130 ) { yspeedball = - yspeedball; } // Bounce off bottom maze surface at: rect( 30, 90, 100, 20 ); if (yspeedball>0 && ballY>90+20 && ballY<90+30 && ballX>30 && ballX<130 ) { yspeedball = - yspeedball; } if (yspeedball<0 && ballY>90 && ballY<90-10 && ballX>30 && ballX<130 ) { yspeedball = - yspeedball; } } void messages() { // MESSAGES. fill(255,255,255); // Also display the author and file name. text( "Maze Test: Albert Ng", 10, height-10 ); } void mousePressed() { ballX=80; ballY=75; }