Ejemplo n.º 1
0
        private void HandleCollisions()
        {
            foreach (var enemy in EnemyList)
            {
                if (PlayerInstance.CollideAgainst(enemy))
                {
                    PlayerInstance.Destroy();
                }

                if (enemy.CollideAgainst <Bullet>(BulletList))
                {
                    enemy.SetState("Die");
                    ScoreboardInstance.Score = ScoreboardInstance.Score + 1;
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void CollisionActivity()
        {
            //Player Against Tiles
            PlayerInstance.CollideAgainst(TileCollisionShapes, false);

            //Player Bullets
            for (int bullet = BulletList.Count - 1; bullet >= 0; bullet--)
            {
                //Against Tiles
                if (BulletList[bullet].Collision.CollideAgainst(TileCollisionShapes))
                {
                    BulletList[bullet].Destroy();
                }
                else
                {
                    //Against Corner Enemy
                    for (int corner = EnemyCornerList.Count - 1; corner >= 0; corner--)
                    {
                        if (BulletList[bullet].Collision.CollideAgainst(EnemyCornerList[corner].Collision))
                        {
                            BulletList[bullet].Destroy();
                            EnemyCornerList[corner].Health -= 10;
                        }
                    }
                    try
                    {
                        //Against ground enemy
                        for (int ground = GroundEnemyList.Count - 1; ground >= 0; ground--)
                        {
                            if (BulletList[bullet].Collision.CollideAgainst(GroundEnemyList[ground].Collision))
                            {
                                BulletList[bullet].Destroy();
                                GroundEnemyList[ground].Health -= 15;
                            }
                        }
                    }
                    catch { }
                }
            }

            //Player Against NextLevelEntity
            for (int next = NextLevelEntityList.Count - 1; next >= 0; next--)
            {
                if (PlayerInstance.Collision.CollideAgainst(NextLevelEntityList[next].Collision))
                {
                    SetLevelByName(NextLevelEntityList[next].nextLevelName);
                }
            }

            //Player Against Action Entity
            for (int Action = ActionEntityList.Count - 1; Action >= 0; Action--)
            {
                if (PlayerInstance.Collision.CollideAgainst(ActionEntityList[Action].Collision))
                {
                    if (ActionEntityList[Action].actionString == "takeOffFedora")
                    {
                        if (CanOpenMessage())
                        {
                            PlayerInstance.FedoraSprite.Visible = false;
                        }
                        else if (PlayerInstance.FedoraSprite.Visible)
                        {
                            PlayerInstance.Collision.CollideAgainstMove(ActionEntityList[Action].Collision, 0, 1);
                        }
                    }
                    else if (ActionEntityList[Action].actionString == "Kill")
                    {
                        if (PlayerInstance.Collision.CollideAgainst(ActionEntityList[Action].Collision))
                        {
                            GlobalData.PlayerData.health = 0;
                        }
                    }
                    else if (ActionEntityList[Action].actionString == "PutOnFedora")
                    {
                        if (PlayerInstance.Collision.CollideAgainst(ActionEntityList[Action].Collision))
                        {
                            PlayerInstance.FedoraSprite.Visible = true;
                        }
                    }
                    else if (ActionEntityList[Action].actionString == "TheEnd")
                    {
                        TheEnd = true;
                    }
                }
            }

            //Player Against Signs
            for (int sign = SignEntityList.Count - 1; sign >= 0; sign--)
            {
                if (PlayerInstance.Collision.CollideAgainst(SignEntityList[sign].Collision))
                {
                    if (CanOpenMessage())
                    {
                        SignEntityList[sign].OpenMessage();
                    }
                }
            }

            //Enemy Bullets
            for (int ebullet = EnemyBulletList.Count - 1; ebullet >= 0; ebullet--)
            {
                //Against Player
                if (PlayerInstance.Collision.CollideAgainst(EnemyBulletList[ebullet].Collision))
                {
                    EnemyBulletList[ebullet].Destroy();
                    GlobalData.PlayerData.health -= 1;
                }
                else
                {
                    //Against Tiles
                    if (EnemyBulletList[ebullet].Collision.CollideAgainst(TileCollisionShapes))
                    {
                        EnemyBulletList[ebullet].Destroy();
                    }
                }
            }

            //Ground Enemy
            for (int ground = GroundEnemyList.Count - 1; ground >= 0; ground--)
            {
                //Against Tiles
                GroundEnemyList[ground].Collision.CollideAgainstBounce(EnemyCollisionGround, 0, 1, 0.25f);
                if (GroundEnemyList[ground].Collision.CollideAgainstBounce(EntityCollisionShapes, 0, 1, 1))
                {
                    GroundEnemyList[ground].movementRight = !GroundEnemyList[ground].movementRight;
                }
                //Against Player
                else
                {
                    if (GroundEnemyList[ground].Collision.CollideAgainstBounce(PlayerInstance.Collision, 0, 1, 5))
                    {
                        GlobalData.PlayerData.health -= 2;
                    }
                }
            }
        }