// Δηλώνουμε τα ονόματα των αντικειμένων (objects) σα να ήταν μεταβλητές. int screen = 0; //0 arxiko , 1 game import processing.serial.*; char mode = '0'; Serial mp; boolean firstTime = false; float d = 0; wall w1, w2, w3, w4; player p1, p2; float new_d=0; int menu; // p1 = red // p2 = blue PImage rp, bp, b, w, m; void setup() { rp = loadImage("red.png"); bp = loadImage("blue.png"); b = loadImage("bg.jpg"); w = loadImage("wall.png"); m = loadImage("flappymenuscreen1.jpg"); size(800, 600); //w1 = new wall(800, 10, 48, 100, -4, #0DFA16, w); //w2 = new wall(600, 500, 50, 70, -4, #0DFA16, w); //w3 = new wall(750, 400, 43, 90, -4, #0DFA16, w); //w4 = new wall(650, 300, 55, 120, -6, #0DFA16, w); w1 = new wall(800, 10, 48, 100, -4, #0DFA16, w); w2 = new wall(600, 50, 50, 70, -4, #0DFA16, w); w3 = new wall(750, 500, 43, 90, -4, #0DFA16, w); w4 = new wall(650, 450, 55, 120, -6, #0DFA16, w); p1 = new player(width/2, height/2+80, 90, 0, #E00E0E, 2, rp); //red is katoteros p2 = new player(width/2, height/2-80, 90, 0, #0A1FF5, 1, bp); //blue is anoteros textSize(20); //mp = new Serial (this, Serial.list()[0], 9600); //mp.bufferUntil ('\n'); } void draw() { println("draw screen: ", screen); if ( screen == 0 ) // p1 = red { // p2 = blue background(m); } else { background(b); if (mode == '2' || mode == '0' ) { p1.display(); p1.move(); p1.checkCollision(w1); p1.checkCollision(w2); p1.checkCollision(w3); p1.checkCollision(w4); } if (mode == '1' || mode == '0') { p2.display(); p2.move(); p2.checkCollision(w1); p2.checkCollision(w2); p2.checkCollision(w3); p2.checkCollision(w4); } w1.display(); w2.display(); w3.display(); w4.display(); w1.move(); w2.move(); w3.move(); w4.move(); if ((p1.lives == 0 && p2.lives == 0 && mode == '0') || ( p2.lives == 0 && mode == '1' )|| ( p1.lives == 0 && mode == '2' )) { background(b); p1.revive(); p2.revive(); p1.display(); p2.display(); textSize(100); fill(#980879); text("! GAME OVER !", 150, 300); noLoop(); } } } void keyPressed() { println(key); if ( screen == 0 ) { println("xaxaxa"); if (key == '0' || key == '1' || key == '2' ) { println("aaaaaaaaaa"); mode = key; screen = 1; } } else { if (key == CODED && keyCode == UP) p2.setSpeed(-5); if (key == CODED && keyCode == DOWN) p2.setSpeed(5); if (key == 'w') p1.setSpeed(-5); if (key == 's') p1.setSpeed(5); if (key == ' ') { d=0; p1.setLives(5); p2.setLives(5); textSize(20); p1.revive(); p2.revive(); loop(); } if (key == TAB && firstTime == false ) { noLoop(); firstTime = true; textSize(80); fill(#980879); text("! Freezed !", 150, 300); } else if (key == TAB && firstTime == true ) { loop(); firstTime = false; } } } void serialEvent(Serial mp) { if (mp.available() > 0 ) getData(); } void getData() { String data; data = mp.readStringUntil('\n'); if (data != null) // Ελέγχουμε αν όντως πήραμε κάτι. { data = data.trim(); // Κόβουμε κενούς χαρακτήρες από το τέλος της συμβολοσειράς. try { new_d = Float.valueOf(data); println( new_d ); if ( new_d > d + 5 ) p1.setSpeed(-5); if ( new_d < d - 5) p1.setSpeed(5); //if ( new_d == d ) // p1.setSpeed(0); d = new_d; } catch(Exception e) { ; } mp.clear(); } }