public void alertCollision(I_WorldObject collidedObject) { if (collidedObject.getName() == "nun") { this.setVelocity(Vector2.Zero); this.setDirection(new Vector2(1, 0)); this.setSpeed(Vector2.Zero); this.setPhysics(false); playerPosition = WorldData.GetInstance().playerInitialPosition; } if (!collidedObject.isRigid()) { if (collidedObject.getName() == "Spikes" || collidedObject.getName() == "SpikeField") { setAlive(false); this.setVelocity(Vector2.Zero); this.setDirection(new Vector2(1, 0)); this.setSpeed(Vector2.Zero); this.setPhysics(false); playerPosition = WorldData.GetInstance().playerInitialPosition; setAlive(true); } if (collidedObject.getName() == "scroll") { collidedObject.setAlive(false); WorldData.level++; } } if (collidedObject.isRigid()) { //this.playerColor = Color.Red; BoundingBox myAABB = this.playerBoundingBox; BoundingBox other = collidedObject.getBoundingBox(); int leftBound = (int)Math.Max(myAABB.Min.X, other.Min.X); int rightBound = (int)Math.Min(myAABB.Max.X, other.Max.X); int upperBound = (int)Math.Max(myAABB.Min.Y, other.Min.Y); int lowerBound = (int)Math.Min(myAABB.Max.Y, other.Max.Y); int xMovement = rightBound - leftBound; int yMovement = lowerBound - upperBound; if (xMovement < yMovement) { if (myAABB.Min.X < other.Min.X) { this.playerPosition.X -= xMovement - 1; } else { this.playerPosition.X += xMovement + 1; } } else { if (myAABB.Min.Y < other.Min.Y) { this.playerState = State.GROUNDED; this.playerPosition.Y -= (yMovement); this.setVelocity(new Vector2(0, 0)); } else { //this.playerState = State.HIGH; this.playerPosition.Y += (yMovement); this.setVelocity(new Vector2(0, 0)); //this.gravityState = true; } } } }