randy
YaBB Newbies
Offline
Posts: 7
tron style game help
Nov 3rd , 2005, 6:31pm
Hi, still fairly new to processing or any code for that matter. im trying to eventually recreate the tron game (two motorcycles with a wall that forms behind them). as of now though i cant even seem to really get the "wall" to work. so far i have this: <code> int speed = 1; int lines = 10000; Move [] move; float[] ax = new float[lines]; float [] ay = new float[lines]; void setup(){ size(400, 400); framerate(30); move = new Move[2]; for(int i=0; i<move.length; i++){ move[i] = new Move(0, 0, 0, 0, width/2, height/2, width/2, height/2); } for(int i=0; i<lines; i++){ ax[i] = width/2; ay[i] = height/2; } } void draw (){ background(100); for(int i=0; i<move.length; i++){ move[i].keys(); move[i].update(); } for(int i=0; i<move.length; i++){ move[i].make(); } } class Move{ float moveleft, moveright, moveup, movedown, xpos, ypos, oldx, oldy; Move(float moveleft, float moveright, float moveup, float movedown, float xpos, float ypos, float oldx, float oldy){ this.moveleft = moveleft; this.moveright = moveright; this.moveup = moveup; this.movedown = movedown; this.xpos = xpos; this.ypos = ypos; this.oldx = oldx; this.oldy = oldy; } void make(){ for(int i=1; i<move.length; i++){ oldx = xpos; oldy = ypos; stroke(255); point(xpos, ypos); } } void update(){ xpos = xpos + moveright - moveleft; ypos = ypos - moveup + movedown; ax[lines-1] = oldx; ay[lines-1] = oldy; } void keys(){ for(int i=0; i<move.length; i++){ if(key == 'w' || key == 'W' || keyCode == UP){ moveup = speed; movedown = 0; moveleft = 0; moveright = 0; //println("W was pressed"); } if(key == 's' || key == 'S' || keyCode == DOWN){ moveup = 0; movedown = speed; moveleft = 0; moveright = 0; } if(key == 'a' || key == 'A' || keyCode == LEFT){ moveup = 0; movedown = 0; moveleft = speed; moveright = 0; } if(key == 'd' || key == 'D' || keyCode == RIGHT){ moveup = 0; movedown = 0; moveleft = 0; moveright = speed; } } for(int i=1; i<lines; i++){ //if(keyPressed == true){ // ax[i] = ax[i+1]; // ay[i] = ay[i+1]; //} line(ax[i-1], ay[i-1], ax[i], ay[i]); } } } </code> i get a line from the original starting point and where the point is then moved to. ive been workin on this far too long and am quite frustrated because this seems to be the only result i can get and i have completly confused myself through the process. so sorry if the code is a little longwinded and excessive(which im sure it is). any help would be great. thanks randy