If you think the Android project killingspree listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.sillygames.killingSpree.managers.physics;
//www.java2s.comimport com.sillygames.killingSpree.categories.EnemyCategory;
import com.sillygames.killingSpree.categories.ExplodingWeaponCategory;
import com.sillygames.killingSpree.categories.LivingCategory;
import com.sillygames.killingSpree.categories.NonExplodingWeaponCategory;
import com.sillygames.killingSpree.managers.physics.Body.BodyType;
import com.sillygames.killingSpree.serverEntities.ServerPlayer;
publicclass CollisionProcessor {
publicstaticboolean jumpOn(Body body1, Body body2) {
if (body1.getUserData() instanceof ServerPlayer) {
if (body2.getUserData() instanceof LivingCategory) {
body1.setLinearVelocity(body1.getLinearVelocity().x, 40);
if (((LivingCategory)body2.getUserData()).kill())
body1.getUserData().addKill();
}
} elseif (body1.getUserData() instanceof EnemyCategory) {
if (body2.getUserData() instanceof ServerPlayer) {
((ServerPlayer)body2.getUserData()).kill();
}
}
processWeapons(body1, body2);
processWeapons(body2, body1);
return false;
}
publicstaticboolean jumpedOn(Body body1, Body body2) {
if (body1.getUserData() instanceof EnemyCategory) {
if (body2.getUserData() instanceof ServerPlayer) {
if (((LivingCategory)body1.getUserData()).kill())
body2.getUserData().addKill();
body2.setLinearVelocity(body1.getLinearVelocity().x, 40);
}
} elseif (body1.getUserData() instanceof ServerPlayer) {
if (body2.getUserData() instanceof EnemyCategory) {
((ServerPlayer)body1.getUserData()).kill();
} elseif (body2.getUserData() instanceof ServerPlayer) {
((ServerPlayer)body1.getUserData()).kill();
((ServerPlayer)body2.getUserData()).addKill();
}
}
processWeapons(body1, body2);
processWeapons(body2, body1);
return false;
}
publicstaticboolean touchLeft(Body body1, Body body2) {
if (body1.getUserData() instanceof EnemyCategory) {
if (body2.getUserData() instanceof ServerPlayer) {
((ServerPlayer)body2.getUserData()).kill();
}
} elseif (body1.getUserData() instanceof ServerPlayer) {
if (body2.getUserData() instanceof EnemyCategory) {
((ServerPlayer)body1.getUserData()).kill();
}
}
processWeapons(body1, body2);
processWeapons(body2, body1);
return false;
}
publicstaticboolean touchRight(Body body1, Body body2) {
if (body1.getUserData() instanceof EnemyCategory) {
if (body2.getUserData() instanceof ServerPlayer) {
((ServerPlayer)body2.getUserData()).kill();
}
}
elseif (body1.getUserData() instanceof ServerPlayer) {
if (body2.getUserData() instanceof EnemyCategory) {
((ServerPlayer)body1.getUserData()).kill();
}
}
processWeapons(body1, body2);
processWeapons(body2, body1);
return false;
}
publicstaticvoid processWeapons(Body body1, Body body2){
if (body1.getUserData() instanceof ExplodingWeaponCategory) {
if (body2.bodyType == BodyType.DynamicBody) {
if (body1.toDestroy)
return;
((ExplodingWeaponCategory) body1.getUserData()).explode();
}
} elseif (body1.getUserData() instanceof NonExplodingWeaponCategory) {
if (body2.toDestroy)
return;
if (body2.getUserData() instanceof LivingCategory) {
if (((LivingCategory)body2.getUserData()).kill()
&& body2 != body1.getUserData().body) {
((NonExplodingWeaponCategory) body1.getUserData()).
getShooter().addKill();
}
}
body1.getUserData().dispose();
}
}
}