miguel
YaBB Newbies
Offline
Posts: 4
two arrays of objects - HELP!!
Jun 10th , 2009, 2:06pm
Hi! I'm starting with processing, and I've been trying to make a this game with processing... But I just can't get past this problem. When one of the objects of the class 'Bomb' generated by the array list bomb[] hits the other object of the class 'Target' generated by the array list target[] It is purposed to appen "something", but I just can't define that colison in sintax... Can anybody help me!?!!? :-/ //////////////////////////////////// int alturadocursor= 50; int numBomb = 0; Bomb []bomb = new Bomb[numBomb]; int numTarget =2; Target []target = new Target[numTarget]; void setup () { size (350,300); for(int i = 0; i<numTarget; i++) { target[i] = new Target(random(60, 140),random (180,220),5); } } void draw(){ noCursor(); smooth(); background (255); mouse(); for(int i = 0; i<bomb.length; i++) { bomb[i].display(); bomb[i].movimento(); } for(int i = 0; i<numTarget;i++) { target[i].displaymosca1(); target[i].movemosca(); } } void mousePressed(){ Bomb b = new Bomb(mouseX,alturadocursor,1.2); bomb = (Bomb[]) append (bomb,b); } void manage() { for(int i = 0; i<numTarget; i++) { target[i] = new Target(random(60, 140),random (180,220),5); } } void mouse(){ strokeCap(ROUND); line(mouseX,46,mouseX+width/5,46); line(mouseX+width/5,46,mouseX+width/5,40); line(mouseX-width/5,46,mouseX-width/5,40); line(mouseX,46,mouseX-width/5,46); fill(#6C1510); beginShape(); vertex(mouseX-5,46); vertex(mouseX-2,43); vertex(mouseX+2,43); vertex(mouseX+5,46); vertex(mouseX+5,52); vertex(mouseX-5,52); endShape(CLOSE); } ///////////////////////////////CLASS BOMB class Bomb { float x,y;//pos x e y da bomba float g; //gravidade float c1,c2; //cor float t1,t2;// tamanho da bomba quer quando é menor ou igual a height; float bd = 50; Bomb(float xpos, float ypos, float gravidade) { x=xpos; y=ypos; g=gravidade; } void display() { t1=1; t2=random(0,bd); c1=0; c2=random(255); if(y<height){ fill(c1); ellipse(x,y,t1,t1); } else { fill(c2); ellipse(x,y,t2,t2); bd=bd-0.5; } } void movimento() { y=y+g; if (y>=height) { y=height; } } } ////////////////////CLASS TARGET class Target { float a; float b; float tam; float xoscilation = 0.1; float xoincrement =0.01; float a1; float a2; float w; float updw=0.5; float v; Target(float px, float py, float t){ a=px; b=py; tam=t; } void displaymosca1(){ fill(0); ellipse(a,b,tam,tam); frameRate(600); w=random(b-5,b+5); line(a,b,a-7,w); line(a,b,a+7,w); } void movemosca(){ a = a + random(-3, 3); b = b + random(-1, 1); if (a<=0){ a=0; } if (a>=width){ a = width; if (b<=60){ b=60; } if (b>=height){ b=height; } } } }