Cover
 This is the archive Discourse for the Processing (ALPHA) software. Please visit the new Processing forum for current information.
 Processing 1.0 _ALPHA_    Programming Questions & Help    Programs (Moderators: fry, REAS)    collision « Previous topic | Next topic »

 Pages: 1
 Author Topic: collision  (Read 413 times)
hallo

 collision « on: Jan 26th, 2005, 12:32pm »

Hi everyone!

This code below is not complete. When the little man hits the black ball it bounce back, but thats not what i want. When the little man hits the black ball, the black ball should dissapear!

Does anyone know how to do this.
So the black ball should dissapear after contact and the ball should keep on coming!

There are 2 images missing, the background and a man.
You can subsistute this.

//the catch project code
BImage eiland;
BImage mannetje;
float kokosx;
float kokosy;
float kokosway =1; // hoe snel hij loopt van de kokos
float straal=15; // de straal van kokosnoot
float richting= 0; // welke richting de ball gaat
float w1=16,h1=32;
float x = 20; // x van de image
float y = 50;
float grens=0;

// Global variables for the paddle
//int balkbre = 20;
//int balkho = 5;
//int balkdikte=15;

void setup()
{
size(600,400);
framerate(30);
mannetje= loadImage("higgins.gif"); // hoogte = 32 breedt=16
//image(c,x,y,w1,h1);
//background(eiland);
//image(mannetje,0,400-32);
kokosx= height/2;
kokosy=1;
smooth();

rect(20,350,40,40);
}

void loop()
{
background(eiland);
kokosx+=richting;
kokosy+=kokosway*2;
if(kokosy > height+straal) {
kokosy = -width/2-straal;
kokosx = random(0, width);
richting = 0;
}
//float balkx = constrain(mouseX,w1, width-w1);
float py = height-h1-straal;
if(kokosy == py
&& kokosx > x - w1 - straal
&& kokosx < x + w1 + straal) {
kokosway *= -1;
/*if(mouseX != pmouseX) {*/
if(richting >  5) { richting =  5; }
if(richting < -5) { richting = -5; }
//}
}
if(kokosy < straal && kokosway == -1) {
kokosway *= -1;
}

// If the ball is touching top or bottom edge, reverse direction
if(kokosx > width-straal) {
richting = richting * -1;
}
if(kokosx < straal) {
richting = richting * -1;
}

// Draw ball
fill(19);
ellipse(kokosx, kokosy, straal, straal);

image(mannetje,x,height-h1,w1,h1);

}

//implementatie
class Ball
{
float x;
float y;

void drawShape()
{
stroke(#000000);
fill(#800080);
ellipse(x, y, 5, 5);
}
}

void keyPressed( ){
//if(key=='w'||key==UP){
//     y = y - 5;

// }else if(key=='s'||key==DOWN){
//     y = y + 5;

//}else
if(key=='a'||key==LEFT){
x = x - 5;
}else if(key=='d'||key==RIGHT){
x = x + 5;

}
}

/*class Kokos
{
float xkok,ykok,straal,bouncex,bouncey;

void Koko()
{
Draw();
}
void Draw()
{
stroke(120);
fill(130);
ellipse(xkok,ykok,straal,straal);
}
}
*/
 « Last Edit: Jan 26th, 2005, 12:43pm by hallo »
 Pages: 1

 Forum Jump: ----------------------------- Discussion -----------------------------  - Community, Collaboration, Status   - Events, Publications, Propaganda   - General Processing Discussion ----------------------------- Programming Questions & Help -----------------------------  - Syntax => Programs   - Integration ----------------------------- Topics & Contributions -----------------------------  - Tools   - Responsive Form, Games   - Information Visualization   - Simulation, Artificial Life   - Tangible Computing   - Automated Systems   - Sound   - Video, Camera   - Beyond Categories ----------------------------- Suggestions -----------------------------  - Software Suggestions   - Website, Reference, Example Suggestions ----------------------------- Bugs -----------------------------  - Software Bugs   - Website, Reference, Example Bugs   - Bug Fixes, Implemented Suggestions ----------------------------- Teaching -----------------------------  - Course Blueprints   - Theory and Practice « Previous topic | Next topic »