We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Help with shooting game!!!!
Page Index Toggle Pages: 1
Help with shooting game!!!! (Read 975 times)
Help with shooting game!!!!
Oct 19th, 2009, 10:57am
 
Hopefully someone can help me..I'm creating a very simple shooting game for university..i have two balls moving on different axis. When they collide i would like something simple to happen...say very simple explosion of sorts..If anyone could explain how i could do this please...below is my cod..
cheers

float x =50.0;
float speed = 1.0;
float radius = 15.0;
int direction = 1;
float y =500.0;
boolean fire = false;
float bulletSpeed = 1.0;
int bulletDirection = 1;

void setup(){
 size(500,500);
 smooth();
 noStroke();
 ellipseMode(RADIUS);
}

void draw(){
 fill(255);
 background(0);
 ellipse(x,33,radius,radius);
 x+=speed*direction;
 if((x>height-radius)||(x<radius)){
   direction=-direction;
 }
 if(fire==true){
   ellipse(250,y,5,5);
   y-=bulletSpeed*bulletDirection;
 }
 
 
 
}
   


void mousePressed()
{
   fire = true;
}
Re: Help with shooting game!!!!
Reply #1 - Oct 19th, 2009, 3:08pm
 
This is obviously homework so only expect help if you first post some code you've worked on and are having difficulty with - you'll learn more that way Wink

There's plenty of information around on collision detection (i.e. search the forum): it's just a matter of checking the distance between the two points each frame and taking the radii of the balls into account.  Once you detect a collision you could replace the balls with lots of little balls giving them random direction/speed.  You might also want to consider what happens if someone misses: i.e. reset fired to false and give them another shot.  And why not fire the shot from the current mouse x position?
Page Index Toggle Pages: 1