private static void RespondToTerrainCollision(AbstractTerrain terrain, AbstractCharacter character) { /*if (terrain is LavaTerrain) * { * character.DamageCharacter(((LavaTerrain)terrain).Damage); * }*/ }
private Color GetPowerupColor(AbstractCharacter character) { Color color = Color.White; if (character.CurrentPowerup is InvincibilityStar) { if (invincibilityStarSequence < 10) { color = Color.Red; } else if (invincibilityStarSequence >= 10 && invincibilityStarSequence <= 20) { color = Color.AntiqueWhite; } else if (invincibilityStarSequence >= 20) { color = Color.Blue; } if (invincibilityStarSequence > 30) { invincibilityStarSequence = 0; } invincibilityStarSequence++; } return(color); }
public HUD(AbstractCharacter character) { this.character = character; this.maxHealth = character.HealthLevel; this.vertOffset = 2; this.vertOffsetScore = 8; this.horizOffset = new int[maxHealth + 3]; this.heartEmpty = new AbstractAnimatedSprite[maxHealth]; this.heartFull = new AbstractAnimatedSprite[maxHealth]; for (int i = 0; i < maxHealth; i++) { this.horizOffset[i] = 2 + 18 * i; this.heartEmpty[i] = SpriteFactory.GetHeartEmptySprite(); this.heartFull[i] = SpriteFactory.GetHeartFullSprite(); } this.horizOffset[maxHealth] = this.horizOffset[maxHealth - 1] + 34; this.horizOffset[maxHealth + 1] = this.horizOffset[maxHealth] + 34; this.horizOffset[maxHealth + 2] = this.horizOffset[maxHealth + 1] + 200; this.powerUpViewer = SpriteFactory.GetPowerUpViewerSprite(); this.waterMeter0p = SpriteFactory.GetWaterMeter0pSprite(); this.waterMeter25p = SpriteFactory.GetWaterMeter25pSprite(); this.waterMeter50p = SpriteFactory.GetWaterMeter50pSprite(); this.waterMeter75p = SpriteFactory.GetWaterMeter75pSprite(); this.waterMeter100p = SpriteFactory.GetWaterMeter100pSprite(); this.sunscreen = SpriteFactory.GetSunscreenSprite(); this.invincibilityStar = SpriteFactory.GetInvincibilityStarSprite(); this.bubbleShield = SpriteFactory.GetBubbleShieldSprite(); }
//Handle what happens to the collidable when it collides with an item private static void RespondToIEnemyCollision(IEnemy enemy, AbstractCharacter character) { if (enemy.IsAlive) { character.ChangeHealthLevel(enemy.Power); } }
private static void HandleCollectableCollisions(AbstractCharacter character, Vector2 newPosition) { List <ICollectable> collectableList = CollisionDetector.GetObjectsAtPosition <ICollectable>(character, newPosition); foreach (ICollectable collectable in collectableList) { RespondToICollectableCollision(collectable, character); } }
private static void HandleTerrainCollisions(AbstractCharacter character, Vector2 newPosition) { /*List<LavaTerrain> terrainList = CollisionDetector.GetObjectsAtPosition<LavaTerrain>(character, newPosition); * * foreach (LavaTerrain terrain in terrainList) * { * RespondToTerrainCollision(terrain, character); * }*/ }
private static void HandleEnemyCollisions(AbstractCharacter character, Vector2 newPosition) { List <IEnemy> enemyList = CollisionDetector.GetObjectsAtPosition <IEnemy>(character, newPosition); foreach (IEnemy enemy in enemyList) { RespondToIEnemyCollision(enemy, character); } }
private static void HandleItemCollisions(AbstractCharacter character, Vector2 newPosition) { List <IItem> itemList = CollisionDetector.GetObjectsAtPosition <IItem>(character, newPosition); HandlePushing(character, newPosition, itemList); foreach (IItem item in itemList) { RespondToIItemCollision(item, character); } }
private static void GetLevel() { currentLevel.StopMusic(); if (levelIndex > Constants.MAX_NUM_OF_LEVELS) { Finished = true; } else { currentLevel = LevelFactory.GetLevel(controllers, levelIndex); character = (AbstractCharacter)currentLevel.characterList[0]; } }
private static void RespondToICollectableCollision(ICollectable powerUp, AbstractCharacter character) { if (!powerUp.HasBeenConsumed) { SoundFactory.PlayCollectibleCollectedSound(); powerUp.SetCharacter(character); if (character.CurrentPowerup != null) { ICollectable current = character.CurrentPowerup; current.Destroy(); } character.CurrentPowerup = powerUp; powerUp.Consume(); } }
//Handle what happens to the collidable when it collides with the item private static void RespondToIItemCollision(IItem item, AbstractCharacter character) { if (item is Door) { Door door = (Door)item; if (door.MessageToReceivers.Equals(Constants.NORM_LEVEL_STRING) && character.CurrentItem is PickupItem) { door.HandleCollisionWithCharacter(); LevelManager.SendEvent(EventFactory.GetDefaultLevelCompleteEvent()); } else if (door.MessageToReceivers.Equals(Constants.SUB_LEVEL_STRING)) { door.HandleCollisionWithCharacter(); LevelManager.SendEvent(EventFactory.GetDefaultSubLevelTransitionEvent()); } } }
private static void HandlePushing(AbstractCharacter character, Vector2 newPosition, List <IItem> pushList) { if (character.StateManager.IsInAir || character.CurrentItem != null) { return; } foreach (IItem item in pushList) { if (item.IsItemPushable() && character.Position.Y + character.Size.Y > item.Position.Y) { Vector2 oldItemVelocity = item.Velocity; item.Velocity = character.Velocity; IItemCollisionManager.HandleMovement(item); item.Velocity = oldItemVelocity; character.StateManager.IsCollidingWithPushableObject = true; } } }
public void SetCharacter(AbstractCharacter player) { character = player; }
public CharacterDrawingManager(AbstractCharacter character) { this.character = character; this.hud = new HUD(character); }
public static void HandleMovementAndCollisions(AbstractCharacter character) { character.Velocity = new Vector2(character.Velocity.X, character.Velocity.Y + Constants.G_CONST); Vector2 newPosition = new Vector2(character.Position.X + character.Velocity.X, character.Position.Y + character.Velocity.Y); Vector2 finalPosition = newPosition; Vector2 itemNewPosition; Vector2 itemFinalPosition; List <ICollidable> ignoreList; ignoreList = new List <ICollidable>(); if (character.CurrentItem != null) { ignoreList.Add(character); ignoreList.Add(character.CurrentItem); } if (CollisionDetector.IsPositionFree(character, new Vector2(character.Position.X, character.Position.Y + 1))) { character.GoToAir(); } Vector2 testPosition = new Vector2(newPosition.X, character.Position.Y); HandleItemCollisions(character, testPosition); HandleCollectableCollisions(character, testPosition); HandleEnemyCollisions(character, testPosition); HandleTerrainCollisions(character, newPosition); if (!CollisionDetector.IsPositionFree(character, newPosition, ignoreList)) { finalPosition = CollisionHelper.GetNewPosition(character, newPosition, ignoreList); if (finalPosition.Y < newPosition.Y) { character.LandOnGround(); } if (finalPosition.Y > newPosition.Y) { character.HitBlockFromBelow(); } } if (character.CurrentItem != null) { itemNewPosition = Vector2.Add(character.CurrentItem.Position, Vector2.Subtract(finalPosition, character.Position)); itemFinalPosition = itemNewPosition; if (!CollisionDetector.IsPositionFree(character.CurrentItem, itemNewPosition, ignoreList)) { itemFinalPosition = CollisionHelper.GetNewPosition(character.CurrentItem, itemNewPosition, ignoreList); if (itemFinalPosition.Y < itemNewPosition.Y) { character.LandOnGround(); } if (itemFinalPosition.Y > itemNewPosition.Y) { character.HitBlockFromBelow(); } } float itemDistance = Vector2.Distance(itemFinalPosition, character.CurrentItem.Position); float characterDistance = Vector2.Distance(finalPosition, character.Position); if (characterDistance > itemDistance) { finalPosition = Vector2.Add(character.Position, Vector2.Subtract(itemFinalPosition, character.CurrentItem.Position)); } } character.Position = finalPosition; character.UpdateItemPosition(); }
public static void Start() { currentLevel = LevelFactory.GetLevel(controllers, levelIndex); character = (AbstractCharacter)currentLevel.characterList[0]; levelHasStarted = true; }