Java tutorial
/* * Copyright 2014 Jesse Corbett * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package us.notsoserio.ninja.physics; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.Fixture; import us.notsoserio.ninja.entity.Entity; import us.notsoserio.ninja.weapons.projectiles.Projectile; /** * Created by Jesse on 7/18/2014. * Please play nice with the code! */ public class CollisionPhysics { public static void EntityGround(Body entity) { ((Entity) entity.getUserData()).isInControl = true; ((Entity) entity.getUserData()).CollidingWithCount++; entity.setLinearVelocity(0, 0); } public static void UnEntityGround(Body entity) { ((Entity) entity.getUserData()).CollidingWithCount--; } public static void SensorGround(Fixture sensor) { ((EntityCollisionSensor) sensor.getUserData()).collisionCount++; } public static void UnSensorGround(Fixture sensor) { ((EntityCollisionSensor) sensor.getUserData()).collisionCount--; } public static void EntityProjectile(Body entity, Body projectile) { if (((Projectile) projectile.getUserData()).Owner != entity.getUserData() && ((Projectile) projectile.getUserData()).Active) { ((Entity) entity.getUserData()).health -= ((Projectile) projectile.getUserData()).damage; ((Projectile) projectile.getUserData()).flaggedForDestruction = true; if (((Entity) entity.getUserData()).health <= 0) { ((Entity) entity.getUserData()).flaggedForDestruction = true; } } } public static void ProjectileGround(Fixture projectile) { if (((Projectile) projectile.getBody().getUserData()).WaitTicks-- <= 0) { ((Projectile) projectile.getBody().getUserData()).Active = false; projectile.getBody().setBullet(false); } } public static void ProjectileProjectile(Fixture projectile1, Fixture projectile2) { if (((Projectile) projectile1.getBody().getUserData()).WaitTicks-- <= 0) { ((Projectile) projectile1.getBody().getUserData()).Active = false; projectile1.getBody().setBullet(false); } if (((Projectile) projectile2.getBody().getUserData()).WaitTicks-- <= 0) { ((Projectile) projectile2.getBody().getUserData()).Active = false; projectile2.getBody().setBullet(false); } } }