If you think the Android project Castle-Invaders 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.noobygames.castleinvaders;
/*www.java2s.com*/import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.noobygames.castleinvaders.World.Species;
import com.noobygames.castleinvaders.World.States;
publicabstractclass DynamicGameObject extends GameObject {
protected GameLiving target;
public States state;
public Species species;
publicfinal Vector2 velocity;
publicfinal Vector2 accel;
publicfinalfloat width;
privatefloat centerX;
protecteddouble hitRange;
publicenum Condition {
snare, root, dot, stun
}
public DynamicGameObject(float x, float y, float width, float height,
Species species) {
super(x, y, width, height);
target = null;
this.species = species;
velocity = new Vector2();
accel = new Vector2();
this.width = width;
setCenterX(x+width/2);
}
public DynamicGameObject(Rectangle bounds) {
super(bounds);
velocity = null;
accel = null;
width = bounds.getWidth();
}
/**
* Pr?ft den Abstand zwischen Objekt & Target
*
* @param obj1
* object
* @param obj2
* target
* @return returns true on target hit
**/protectedboolean rangeCheck(GameLiving obj1, GameLiving obj2) {
if (obj1.species == Species.greyTroll
|| obj1.species == Species.iceTroll
|| obj1.species == Species.lavaTroll) {
if (Math.pow(obj1.hitRange, 2) >= Math.pow((obj1.position.x + 20)
- obj2.position.x, 2))
return true;
} elseif (obj1.species == Species.orc) {
if (Math.pow(obj1.hitRange, 2) >= Math.pow((obj1.position.x)
- obj2.position.x, 2))
return true;
}
return false;
}
publicfloat getCenterX() {
return centerX;
}
publicvoid setCenterX(float centerX) {
this.centerX = centerX;
}
}