Don't like ads? PRO users don't see any ads ;-)
Guest

Enemy Clipping In Marte Engine

By: the_zenith_ on Aug 12th, 2011  |  syntax: Java  |  size: 0.90 KB  |  hits: 110  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Stock code:
  2.  
  3.         //if we don't hit a solid in the direction we're moving, move....
  4.         if (e.collide(SOLID, e.x + Math.signum(spdx), e.y - s ) == null)
  5.         { ... move ...
  6.  
  7.  
  8. Overridden code:
  9.  
  10.         // store the entity that we would collide with
  11.         Entity other = e.collide(SOLID, e.x + Math.signum(spdx), e.y - s );
  12.         boolean clipThroughEnemy = false;
  13.         // if there is an entity...
  14.         if (other != null){
  15.                 boolean otherIsEnemy = false;
  16.                 //iterate through MY_ENEMY if any of the other's types
  17.                 // and see if it matches one of our enemy types.
  18.                 for (String type : MY_ENEMY){
  19.                         if(other.getType().contains(type))
  20.                                 otherIsEnemy = true;
  21.                 }
  22.                 // if we're invulnerable and the other is an enemy, we can clip
  23.                 clipThroughEnemy = (!isVulnerable && otherIsEnemy);
  24.         }
  25.         if (other == null || clipThroughEnemy)
  26.         { ... move ...