Пример #1
0
        public override void OnCollision(CollisionEvent collisionEvent)
        {
            if (collisionEvent.OtherEntity.GetName().Contains("Lava"))
            {
                _actionManager.ActionPlaySound("bowserDead.wav");

                Player3Script.Instance.SetCanMove(true);
                Entity door = _actionManager.ActionGetCurrentScene().findEntityWithName("door");
                ((RenderComponent)door.GetComponentOfType(typeof(RenderComponent))).image = "door.png";
                _actionManager.ActionRemoveEntity(GetEntity());
            }
        }
Пример #2
0
        public override void OnCollision(CollisionEvent collisionEvent)
        {
            // Collision with tile -> jump
            if (collisionEvent.OtherEntity.GetName().Contains("Tile"))
            {
                _canJump = true;
            }
            else if (collisionEvent.OtherEntity.GetName().Contains("Lava") ||
                     collisionEvent.OtherEntity.GetName().Contains("Fireball") ||
                     collisionEvent.OtherEntity.GetName().Contains("Bowser"))
            {
                if (_canBeHurt)
                {
                    LostAlife(collisionEvent);
                }
            }
            else if (collisionEvent.OtherEntity.GetName().Equals("Hammer"))
            {
                _actionManager.ActionPlaySound("hammer.wav");

                _actionManager.ActionRemoveEntity(_actionManager.ActionGetCurrentScene()
                                                  .findEntityWithName("Hammer"));
                _actionManager.ActionRemoveEntity(_actionManager.ActionGetCurrentScene()
                                                  .findEntityWithName("Tile5"));
                _actionManager.ActionRemoveEntity(collisionEvent.OtherEntity);

                ((VelocityComponent)GetEntity().GetComponentOfType(typeof(VelocityComponent))).velocity = new Vector2(0, 0);
                _canMove = false;

                Entity bowser = _actionManager.ActionGetCurrentScene().findEntityWithName("Bowser");
                ((VelocityComponent)bowser.GetComponentOfType(typeof(VelocityComponent))).velocity = new Vector2(0, -1000);
            }
            else if (collisionEvent.OtherEntity.GetName().Equals("door"))
            {
                _actionManager.ActionChangeCurrentScene(4);
            }
        }
Пример #3
0
 public override void OnCollision(CollisionEvent collisionEvent)
 {
     // Collision with coin -> collect it
     if (collisionEvent.OtherEntity.GetName().Contains("coin"))
     {
         _coins++;
         _actionManager.ActionRemoveEntity(collisionEvent.OtherEntity);
         _actionManager.ActionPlaySound("coinGetSound.wav");
         if (_coins == 5)
         {
             Entity door = _actionManager.ActionGetCurrentScene().findEntityWithName("door");
             ((RenderComponent)door.GetComponentOfType(typeof(RenderComponent))).image = "door.png";
             _actionManager.ActionPlaySound("doorOpen.wav");
         }
     }
     // Collision with coin -> collect it
     if (collisionEvent.OtherEntity.GetName().Contains("Floor"))
     {
         _canJump = true;
     }
 }
Пример #4
0
 public override void OnCollision(CollisionEvent collisionEvent)
 {
     _actionManager.ActionRemoveEntity(GetEntity());
 }
Пример #5
0
        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");
                }
            }
        }