public override void Update() { _numberFrameFireballCurrent++; if (_numberFrameFireballCurrent >= _numberFrameFireball) { _numberFrameFireballCurrent = 0; _numberFrameFireball = 50 + new Random().Next(1, 50); Entity fireball = CreateFireball(); _actionManager.ActionAddEntity(fireball); } }
private void Dead() { _actionManager.ActionPlaySound("playerDead.wav"); _life = 3; Entity life = _actionManager.ActionGetCurrentScene().findEntityWithName("life"); ((RenderComponent)life.GetComponentOfType(typeof(RenderComponent))).image = "life3.png"; _actionManager.ActionRemoveEntity(life); _actionManager.ActionAddEntity(life); ((RenderComponent)GetEntity().GetComponentOfType(typeof(RenderComponent))).image = "mario.png"; ((PositionComponent)GetEntity().GetComponentOfType(typeof(PositionComponent))).position = new Vector2(50, 350); }
public override void OnCollision(CollisionEvent collisionEvent) { // Collision with floor -> reset jump if (collisionEvent.OtherEntity.GetName().Contains("Floor")) { _canJump = true; } // Collision with enemy else if (collisionEvent.OtherEntity.GetName().Contains("Enemy") && _canBeHurt && (collisionEvent.CollisionSide == CollisionSide.FROM_RIGHT_SIDE || collisionEvent.CollisionSide == CollisionSide.FROM_LEFT_SIDE)) { // Lost a life _life--; if (_life > 0 && collisionEvent.CollisionSide != CollisionSide.FROM_TOP_SIDE) { _canBeHurt = false; Entity life = _actionManager.ActionGetCurrentScene().findEntityWithName("life"); ((RenderComponent)life.GetComponentOfType(typeof(RenderComponent))).image = "life" + _life + ".png"; ((RenderComponent)GetEntity().GetComponentOfType(typeof(RenderComponent))).image = "marioHurt.png"; _actionManager.ActionPlaySound("lostAlife.wav"); if (collisionEvent.CollisionSide == CollisionSide.FROM_RIGHT_SIDE) { _pc._forces.Add(new Vector2(1000000, 0)); } else if (collisionEvent.CollisionSide == CollisionSide.FROM_LEFT_SIDE) { _pc._forces.Add(new Vector2(-1000000, 0)); } } // dead else { _actionManager.ActionPlaySound("playerDead.wav"); _life = 3; Entity life = _actionManager.ActionGetCurrentScene().findEntityWithName("life"); ((RenderComponent)life.GetComponentOfType(typeof(RenderComponent))).image = "life3.png"; _actionManager.ActionRemoveEntity(life); _actionManager.ActionAddEntity(life); ((RenderComponent)GetEntity().GetComponentOfType(typeof(RenderComponent))).image = "mario.png"; ((PositionComponent)GetEntity().GetComponentOfType(typeof(PositionComponent))).position = new Vector2(0, 550); } } // Kill an ennemy if (collisionEvent.OtherEntity.GetName().Contains("Enemy") && collisionEvent.CollisionSide == CollisionSide.FROM_TOP_SIDE) { _pc._forces.Add(new Vector2(0, -1000000)); _actionManager.ActionRemoveEntity(collisionEvent.OtherEntity); _enemyKilled++; _actionManager.ActionPlaySound("enemyDead.wav"); if (_enemyKilled == 2) { Entity door = _actionManager.ActionGetCurrentScene().findEntityWithName("door"); ((RenderComponent)door.GetComponentOfType(typeof(RenderComponent))).image = "door.png"; _actionManager.ActionPlaySound("doorOpen.wav"); } } }