Paso 3: Procesamiento de código
Import processing.serial.*;
Puerto serie = serie nueva (este, Serial.list() [0], 9600); Valor de cadena; gameover boolean = false, derecha = false, izquierda = falso, d = false, un = false, last = false, jugando = false; topscore int = 0, bottomscore = 0, botón = 0; Float changespeed = 0; Parte inferior de la paleta; Pongball de la bola; Tapa de paleta; void setup() {frameRate(100); noStroke(); pongball = new Ball(); fondo = nuevo Paddle(); superior = new Paddle(); top.y=0;size(1024,500); value=port.readStringUntil('\n');} void draw() {String [] importaciones; background(0); if (port.available() > 0) {value=port.readStringUntil('\n');} si (valor! = null) {importaciones = split (valor, ""); int i = 0; mientras (i 0) {bottomscore = 0; topscore = 0; port.write(7); gameover = false; jugando = false;}} Si (botón > 0) {gameover = false; jugando = false;}} } top.show(); Bottom.Show(); Si (! gameover) {pongball.move();} más {si (! jugando) {sendthing();} si (pasado) {pongball.x = top.x+60; pongball.y = top.y+13; pongball.up = false; pongball.right = false;} else {pongball.x = bottom.x+60; pongball.y = bottom.y-13; pongball.up = true; pongball.right = true;}} pongball.bounce(); pongball.Show(); Si (pongball.y < -8) {gameover = true; bottomscore ++; fin = true;} si (pongball.y > 508) {fin = falso; gameover = true; topscore ++;}}
anular sendthing() {si (topscore == 1 & &! pasado) {port.write(1);} si (topscore == 2 & &! pasado) {port.write(2);} si (topscore == 3 & &! pasado) {port.write(3);} si (bottomscore == 1 & & último) {port.write(4);} si (bottomscore == 2 & & último) {port.write(5);} si (bottomscore == 3 & y último) {port.write(6);}
jugando = true; }
Bola de la clase {int x, y; boolean para arriba, a la derecha; Ball() {x = 16; y = 484 hasta = true; derecha = true;} anular move() {si (a == true) {y=int(y-2-changespeed/2);} //up==false else {y=int(y+2+changespeed/2);} si (derecha == true) {x=int(x+5+changespeed);} //right==false else {x=int(x-5-changespeed);}} void bounce() {si (Haz (int (x) int(y))!=color(0))-8, {derecha = true; if (y > 9 & & y < 491) {port.write(8);}} si (get (int (x) + 8 int(y))!=color(0)) {derecha = false; (y > 9 & & y < 491) {port.write(8);}} si (get(int(x), int (y) -8) == color (255, 0, 0)) {arriba = false; si (y > 9 & & y < 491) {port.write(8);}} si (get(int(x), int (y) + 8) == color (255, 0, 0)) {hasta = true; if (y > 9 & & y < 491) {port.write(8);}}} void show() {fill (247, 226, 48), ellipse (x, y, 16, 16);}}
clase padel {int x, y; Paddle() {x = 250; y = 496;} void show() {fill (255, 0, 0); rect (x, y, 120, 4);}}