odin4000
YaBB Newbies
Offline
Posts: 13
Re: multiple keypressed
Reply #2 - Jan 24th , 2009, 5:41pm
Thanks for the answer but im not sure how to use boolean arrays...im making a new array; int[] keys = ['q', 'a', 'o', 'l'] but when i type: keys[0] = true; its says: cannot convert from boolean to int ... here goes my whole code without the array and see by yourself. int x = 10; //rect1 X int y = 125; //rect1 Y int x2 = 390; //rect2 X int y2 = 125; //rect2 Y int bx = 200; //ball X int by = 125; //ball Y int c = -1; //ball x movement int v = 0; //ball y movement int p1 = 0; //Left player points int p2 = 0; //right player points void setup() { size(400, 250); rectMode(CENTER); ellipseMode(CENTER); smooth(); strokeWeight(2); frameRate(130); PFont arial; arial = loadFont("ariblk.vlw"); textFont(arial, 48); } void draw() { background(100); text(p1, 165, 35); //This is the first player's points. text(p2, 203, 35); //This is the second player's points. line(200, 0, 200, 250); ellipse(bx, by, 10, 10); //The Pong Ball bx = bx + c; //Default ball movements. by = by + v; if(bx == 20 && by >= y-25 && by <= y+25) { //Movements if ball touch left player. if(by < y) { c = +2; v = -2; } if(by > y) { c = +2; v = +2; } if(by == y) { c = +2; v = 0; } } if(bx == 380 && by >= y2-25 && by <= y2+25) { //Movements if ball touch right player. if(by < y2) { c = -2; v = -2; } if(by > y2) { c = -2; v = +2; } if(by == y2) { c = -2; v = 0; } } if(bx < 0) { //If the ball pass left limit. bx = 200; by = 150; v = 0; c = -1; p2 = p2+1; } if(bx > 400) { //If the ball pass right limit. bx = 200; by = 150; v = 0; c = +1; p1 = p1+1; } if(by > 250) { //The ball touch the lower limit. v = -2; } if(by < 0) { //The ball touch the upper limit. v = +2; } rect(x, y, 10, 50); //This is the left pannel. rect(x2, y2, 10, 50); //This is the right pannel. if(keyPressed == true) { if(key == 'q') { //Move the left player up. y = max(25, y-2); } if(key == 'a') { //Move the rigth player down. y = min(225, y+2); } if(key == 'o') { //Move the right player up. y2 = max(25, y2-2); } if(key == 'l') { //Move the right player down. y2 = min(225, y2+2); } } }