So this is what is happening, The game keeps stopping because two circles collide with each other, I am trying to prevent that by making sure the ID is the square ID, im trying to allow the circles to collide together and just ignore the collisions but its not doing that, and I dont know how exactly to stop this from colliding with each other and only allow it to collide with the square.
basically I want to stop the circle from colliding with another circle and allow it to collide with the square.
Any help would be great thank you
game.engine.engine class
//collision detection class
iter = p_group.listIterator();
Sprite spr = null;
while (iter.hasNext()) {
spr = (Sprite)iter.next();
//remove from list if flagged
if (!spr.getAlive()) {
iter.remove();
continue;
}
//is collision enabled for this sprite?
if (spr.getCollidable()) {
//has this sprite collided with anything?
if (spr.getCollided()) {
//is the target a valid object?
if (spr.getOffender() != null) {
/*
* External func call: notify game of collision
* (with validated offender)
*/
collision(spr);
//reset offender
spr.setOffender(null);
}
//reset collided state
spr.setCollided(false);
}
}
}
this is where i check for collision in the game class which extends game.engine.engine package.
Game Class
// all the circles were are set up the same, theres four
// circletopleft, circletopright, circlebottomleft
// circle bottom left collides with circle top right
// theres no diffence between the code of the circles they are all the same
/*ball*/circleBottomLeft.setCollidable(true);
circleBottomLeft.setIdentifier(CIRCLEID_3);
addToGroup(circleBottomLeft);
//init ball sprite
circleBottomRight.position = new Float2(550, h-550);
circleBottomRight.setVelocity(new Float2(10.0f, -9.0f));
//keep ball inside secreen boundary
Point size4 = circleBottomRight.getSize();
circleBottomRight.addAnimation(new ReboundBehavior(new RectF
(0 , 0 , w-size4.x, h-size4.y),size4,circleBottomRight.getVelocity()) );
/*ball*/circleBottomRight.setCollidable(true);
circleBottomRight.setIdentifier(CIRCLEID_4);
addToGroup(circleBottomRight);
}
//collision class extended from game.engine.Engine
public void collision(Sprite sprite) {
// TODO Auto-generated method stub
final int oneMin = 60;
final int twoMin = 120;
final int threeMin = 180;
final int fourMin = 240;
final int fiveMin = 300;
Sprite other = sprite.getOffender();
Float2 vel = sprite.getVelocity();
switch (sprite.getIdentifier()) {
case CIRCLEID_1:
vel = sprite.getVelocity();
other.position.y += 1;
case CIRCLEID_2:
vel = sprite.getVelocity();
other.position.y += 1;
case CIRCLEID_3:
vel = sprite.getVelocity();
other.position.y += 1;
case CIRCLEID_4:
vel = sprite.getVelocity();
other.position.y += 1;
break;
}
switch (other.getIdentifier()) {
case oneMin:
if (this.getElapsedTime() == oneMin) {
vel.y = -1;
sprite.setVelocity(vel);
sprite.position.y += vel.y*2;
}
break;
case twoMin:
if (this.getElapsedTime() == twoMin) {
vel.y = -1;
sprite.setVelocity(vel);
sprite.position.y += vel.y*2;
}
break;
case threeMin:
if (this.getElapsedTime() == threeMin) {
vel.y = -1;
sprite.setVelocity(vel);
sprite.position.y += vel.y*2;
}
break;
case fourMin:
if (this.getElapsedTime() == fourMin) {
vel.y = -1;
sprite.setVelocity(vel);
sprite.position.y += vel.y*2;
}
break;
case fiveMin:
if (this.getElapsedTime() == fiveMin) {
vel.y = -1;
sprite.setVelocity(vel);
sprite.position.y += vel.y*2;
}
break;
case SQUARE_ID:
//make sure its not touched
if (other.getIdentifier() == SQUARE_ID &&
other.getIdentifier() == CIRCLEID_1 ||
other.getIdentifier() == CIRCLEID_2 ||
other.getIdentifier() == CIRCLEID_3 ||
other.getIdentifier() == CIRCLEID_4) {
stop();
Log.d("Game", "Collided, I collided with something");
if (p_paused) {
Message msg = handler.obtainMessage();
msg.arg1 = 1;
handler.sendMessage(msg);
it keeps stopping when top the two circles collide (417 seconds into the game theres a collision, and it doesnt touch the square. it happens exactly when the circle bottom left collides with circle top right