
Enemy Clipping In Marte Engine
By:
the_zenith_ on
Aug 12th, 2011 | syntax:
Java | size: 0.90 KB | hits: 110 | expires: Never
Stock code:
//if we don't hit a solid in the direction we're moving, move....
if (e.collide(SOLID, e.x + Math.signum(spdx), e.y - s ) == null)
{ ... move ...
Overridden code:
// store the entity that we would collide with
Entity other = e.collide(SOLID, e.x + Math.signum(spdx), e.y - s );
boolean clipThroughEnemy = false;
// if there is an entity...
if (other != null){
boolean otherIsEnemy = false;
//iterate through MY_ENEMY if any of the other's types
// and see if it matches one of our enemy types.
for (String type : MY_ENEMY){
if(other.getType().contains(type))
otherIsEnemy = true;
}
// if we're invulnerable and the other is an enemy, we can clip
clipThroughEnemy = (!isVulnerable && otherIsEnemy);
}
if (other == null || clipThroughEnemy)
{ ... move ...