Niall
YaBB Newbies
Offline
Posts: 2
Triggering multiple events
Jan 7th , 2008, 2:47am
Hello, this is probably a question more about programming than processing specifically, so apologies if it's in the wrong place or anything. I'm pretty new to processing and programming in general, I've been messing around a bit trying to write a very basic shoot 'em up, which processing is maybe not ideal for, but it's a fun step away from flash. My problems come with trying to get the ship to shoot, specifically getting more than one bullet on the screen. I haven't figured out how to press the shoot button and press it again to get a different bullet, if that makes sense. I'm wondering if i need an string that would hold the information for each individual bullet? So far trying to sort this out has mainly been trial and error, but i'd really appreciate it if someone would be able to help me in the right direction with this. Thanks in advance, niall. Here is the code if anyone is interested. final static int NORTH = 1; final static int EAST = 2; final static int SOUTH = 4; final static int WEST = 8; int result; float x,y; boolean shoot; float shootx, shooty; void setup(){ size (400, 400); frameRate(30); } void draw(){ background(55551199); fill (500,y-50,100); triangle(10+x,30+y,30+x,20+y,10+x,10+y); fill (500,50,300); switch(result) { case NORTH: y-=5; break; case EAST: x+=5; break; case SOUTH: y+=5; break; case WEST: x-=5; break; case NORTH|EAST: y-=5; x+=5; break; case NORTH|WEST: y-=5; x-=5; break; case SOUTH|EAST: y+=5; x+=5; break; case SOUTH|WEST: y+=5; x-=5; break; } if (shoot) { shootx += 5; } line (shootx, shooty, 10+shootx, shooty); } void keyPressed(){ switch(key) { case('w'): case('W'): result |=NORTH; break; case('d'): case('D'): result |=EAST; break; case('s'): case('S'): result |=SOUTH; break; case('a'): case('A'): result |=WEST; break; } if (key == 'l' || key == 'L') { shoot = true; shootx = x+20; shooty = y+20; } } void keyReleased(){ switch(key) { case('w'): case('W'): result ^=NORTH; break; case('d'): case('D'): result ^=EAST; break; case('s'): case('S'): result ^=SOUTH; break; case('a'): case('A'): result ^=WEST; break; } }