mateooo
Junior Member
Offline
Posts: 58
Re: colliding with 2 agents
Reply #10 - Jan 12th , 2009, 7:23am
hello, philho. I can make that each agent perceives the state of each agent that collides it, that works fine. But what i need is that each agent can percieve the state of the "2" agents (just when it collides with 2) that collides it and add them. Perceiving the state of one agent that collides is not problem , but how can i make something like this: each agent moves randomly when 2 agents collide one agent , the agent can percieve the state of both agents and then add them . if the sum of both agents that are colliding me is more than "whatever" something happens. Any idea? int numAgente= 12; Agente[] arreglo = new Agente[numAgente]; void setup(){ size(800,700); smooth(); noStroke(); // print( random (5)); background(238, 282, 299); for (int i=0; i<numAgente; i++){ arreglo[i] = new Agente(i); } } void draw(){ background(38, 82, 29); for (int k=0; k<numAgente; k++){ arreglo[k].mueve(); } for (int k=0; k<numAgente; k++){ arreglo[k].check(); } for (int k=0; k<numAgente; k++){ arreglo[k].dibuja(); } } class Agente{ float x = random(800); float y = random(700); float stateA = random (5); float stateB = random (5); color coloryo; int rank; Agente(int i) { rank = i; } void mueve(){ // x = x + movimiento; x = x + random(20) - 10; y = y + random(20) - 10 ; } void check(){ int collisionCount = 0; for (int i=0; i<numAgente; i++){ if ( i != rank){ float dista = dist(arreglo[i].x, arreglo[i].y, x, y); if (dista < 60){ collisionCount++; // print(arreglo[i].stateA + "--"); //here it checks if the state of each agent that collides is more than 3 //if so, then it adds 1 to my state, // but i need to check the state of the colliding agent just when i collide with 2 at the same time and then sum both // if the sum of both agents that are colliding me is more than 4 , then something happens, how can i do this? if (arreglo[i].stateA > 3) { stateA = stateA + 1; } } } } if (collisionCount >= 2) { coloryo = color(222, 40, 0); } else if (collisionCount == 1) { coloryo = color(222, 240, 0); } else { coloryo = color(2, 40, 0); } } void dibuja(){ fill(24, 88,99, 54); ellipse(x, y , 60, 60); fill(coloryo); ellipse(x , y ,15,15); } }