public virtual void update(TileMap map, TimeSpan elapsed) { if (SlatedToRemove) { return; } isOnFloor = map.isRectOnFloor(bounds.Rect); if (!isOnFloor) { bounds.moveY(2); } }
public virtual void update(TimeSpan elapsed) { if (SlatedToRemove) { return; } isOnFloor = Map.isRectOnFloor(Bounds, Direction.Stopped); if (!isOnFloor) { Bounds.moveY(2); } }
public void update(TileMap map, TimeSpan elapsed) { if (alive) { lastElapsed = elapsed; int vel = getRealSpeed(); if (horizontal) { drawRect.X += vel; bounds.moveX(vel); } else { drawRect.Y += vel; bounds.moveY(vel); } distTraveled += Math.Abs(vel); if (distTraveled > maxdist || drawRect.Right < 0 || drawRect.Left >= map.getPixelWidth()) { alive = false; } else { // Test walls based on direction (left, right) if (horizontal) { int oldX = bounds.X, newX; if (vel > 0) { newX = map.checkBoundsXRight(bounds, Direction.Right); } else { newX = map.checkBoundsXLeft(bounds, Direction.Left); } if (newX != oldX || bounds.Y != drawRect.Y) { alive = false; return; } } else { int oldY = bounds.Y, newY; if (vel > 0) { newY = map.checkBoundsYDown(bounds, Direction.Right); } else { newY = map.checkBoundsYUp(bounds, Direction.Right); } if (newY != oldY) { alive = false; return; } } // Test collision with entites foreach (Entity e in map.entityIterator()) { if (!e.Alive) { continue; } EntityHit eHit; if (horizontal) { eHit = e.EBounds.collide(new Point(bounds.Right, bounds.Center.Y)); // If not hit in front, check back if (eHit.Part == EntityPart.None) { eHit = e.EBounds.collide(new Point(bounds.Left, bounds.Center.Y)); } } else { int y; if (msSpeed > 0) { y = bounds.Bottom; } else { y = bounds.Top; } eHit = e.EBounds.collide(new Point(bounds.Left, y)); // If not hit on left, check right if (eHit.Part == EntityPart.None) { eHit = e.EBounds.collide(new Point(bounds.Right, y)); } } if (eHit.Part != EntityPart.None) { alive = false; if (eHit.Part != EntityPart.Miss) { float dmgReducer = 0; if (eHit.PercFromCenter >= 0.75) { dmgReducer = 0.25f; } else if (eHit.PercFromCenter >= 0) { dmgReducer = 1 - eHit.PercFromCenter; } int realDmg = e.hitInThe(eHit.Part, dmg, dmgReducer); realDmg += e.slide(eHit.KnockBack); map.addHitText(e, realDmg); if (!e.Alive) { xp += e.XPValue; } } return; } } } } }