Beispiel #1
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag != "PlayerComponent")
        {
            if (collision.tag != "Tank")
            {
                if (collision.tag != "Player")
                {
                    Enemy enemy = collision.GetComponent <Enemy>();
                    if (enemy != null)
                    {
                        enemy.TakeDamage(damege);
                    }

                    EnemyHelicopter enemyHelicopter = collision.GetComponent <EnemyHelicopter>();
                    if (enemyHelicopter != null)
                    {
                        enemyHelicopter.TakeDamage(damege);
                    }

                    GameObject clone = Instantiate(bulletImpactEffect, transform.position, transform.rotation);

                    Destroy(clone, 3f);

                    Destroy(gameObject);
                }
            }
        }
    }
        public void LoadContent(ContentManager content)
        {
            map         = content.Load <TiledMap>("Level2");
            mapRenderer = new TiledMapRenderer(GraphicsLocator.Graphics.GraphicsDevice);

            mapWidth  = map.WidthInPixels;
            mapHeight = map.HeightInPixels;
            tileSize  = new Vector2(16, 16);

            var tsx = (int)tileSize.X;
            var tsy = (int)tileSize.Y;

            var blockedLayer = map.GetLayer <TiledMapObjectLayer>("Block");

            if (blockedLayer != null)
            {
                foreach (var tile in blockedLayer.Objects)
                {
                    tileColliderBoxes.Add(new Rectangle((int)tile.Position.X * tsx, (int)tile.Position.Y * tsy, tsx, tsy));
                }
            }

            var instancesLayer = map.GetLayer <TiledMapObjectLayer>("Instances");

            if (instancesLayer != null)
            {
                foreach (var i in instancesLayer.Objects)
                {
                    EnemyBehaviour enemyBehaviour = new EnemyEmptyBehaviour();

                    switch (i.Type)
                    {
                    // ITEM
                    case "Antidote":
                        StateLocator.State.AddObject(new Antidote((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "Coin":
                        StateLocator.State.AddObject(new Coin((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "ItemMachinegun":
                        StateLocator.State.AddObject(new ItemMachinegun((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "ItemMisslegun":
                        StateLocator.State.AddObject(new ItemMisslegun((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "ItemShotgun":
                        StateLocator.State.AddObject(new ItemShotgun((int)i.Position.X, (int)i.Position.Y));
                        break;

                    // ENEMY
                    case "EnemyBear":
                        StateLocator.State.AddObject(new EnemyBird((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemyBird":
                        StateLocator.State.AddObject(new EnemyBird((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemyBomb":
                        enemyBehaviour = GetEnemyBehaviour(i);
                        EnemyBomb enemy = new EnemyBomb((int)i.Position.X, (int)i.Position.Y, enemyBehaviour, GetEnemyRange(i), GetEnemyGoingDown(i));
                        enemyBehaviour.Setup(enemy, i);
                        StateLocator.State.AddObject(enemy);
                        break;

                    case "EnemyDripper":
                        StateLocator.State.AddObject(new EnemyDripper((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemyFox":
                        StateLocator.State.AddObject(new EnemyFox((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemyFoxShock":
                        StateLocator.State.AddObject(new EnemyFoxShock((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemyHelicopter":
                        enemyBehaviour = GetEnemyBehaviour(i);
                        EnemyHelicopter enemyHelicopter = new EnemyHelicopter((int)i.Position.X, (int)i.Position.Y, enemyBehaviour, GetEnemyRange(i), GetEnemyGoingDown(i));
                        enemyBehaviour.Setup(enemyHelicopter, i);
                        StateLocator.State.AddObject(enemyHelicopter);
                        break;

                    case "EnemyHelicopterGun":
                        enemyBehaviour = GetEnemyBehaviour(i);
                        EnemyHelicopterGun enemyHelicopterGun = new EnemyHelicopterGun((int)i.Position.X, (int)i.Position.Y, enemyBehaviour, GetEnemyRange(i), GetEnemyGoingDown(i));
                        enemyBehaviour.Setup(enemyHelicopterGun, i);
                        StateLocator.State.AddObject(enemyHelicopterGun);
                        break;

                    case "EnemyMeteor":
                        StateLocator.State.AddObject(new EnemyMeteor((int)i.Position.X, (int)i.Position.Y, GetEnemyMeteorSize(i)));
                        break;

                    case "EnemyShell":
                        StateLocator.State.AddObject(new EnemyShell((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemyShield":
                        StateLocator.State.AddObject(new EnemyShield((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemySpace":
                        StateLocator.State.AddObject(new EnemySpace((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemySpike":
                        StateLocator.State.AddObject(new EnemySpike((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "EnemyZeppelin":
                        StateLocator.State.AddObject(new EnemyZeppelin((int)i.Position.X, (int)i.Position.Y));
                        break;

                    // BOSS
                    case "BossMeca":
                        StateLocator.State.AddObject(new BossMeca((int)i.Position.X, (int)i.Position.Y));
                        break;

                    case "BossCarrot":
                        StateLocator.State.AddObject(new BossCarrot((int)i.Position.X, (int)i.Position.Y));
                        break;
                    }
                }
            }
        }