Beispiel #1
0
        public override void Update(GameTime gameTime)
        {
            if (player == null || !player.IsActiv)
            {
                player = EntityManager.ActivEntityManager.GetEntityByType <Player>();
            }

            if (collidables == null)
            {
                collidables = EntityManager.ActivEntityManager.GetEntitiesByType <CollidAble>();
            }

            if (health == null)
            {
                health = GetComponent <DamageAbleObject>();
                if (health != null)
                {
                    health.OnHealthChanging += Health_OnHealthChanging;
                    health.OnHealthChanged  += Health_OnHealthChanged;
                }
            }

            if (attacked)
            {
                elasedTimeSinceAttacked += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (elasedTimeSinceAttacked > 5000f)
                {
                    attacked = false;
                }
            }

            Think((float)gameTime.ElapsedGameTime.TotalMilliseconds);
            base.Update(gameTime);
        }
Beispiel #2
0
        private void Dmg_OnDeath(object sender, HealthChangedArgs e)
        {
            DamageAbleObject dmg = sender as DamageAbleObject;

            npcs.Remove(dmg.Parent as NPC);
            elapsedTimeSinceContact = 10000;
            attacked = false;
            elasedTimeSinceAttacked = 10000f;
        }
Beispiel #3
0
        private void DmgNPC_OnDeath(object sender, HealthChangedArgs e)
        {
            DamageAbleObject dmgObj = sender as DamageAbleObject;

            if (dmgObj != null && dmgObj.Parent != null && dmgObj.Parent is NPC)
            {
                enemies.Remove(dmgObj.Parent as NPC);
            }

            if (enemies.Count == 0)
            {
                enmiesAreDead = true;
            }
        }
Beispiel #4
0
        private float GetPlayerHealth()
        {
            float health = 0f;

            if (player != null)
            {
                DamageAbleObject healthContainer = player.GetComponent <DamageAbleObject>();
                if (healthContainer != null && healthContainer.Health > 0)
                {
                    health = healthContainer.Health;
                }
            }
            return(health);
        }
Beispiel #5
0
 public void Init(Entity owner, Vector2 spawnPosition, Vector2 direction, int teamId, bool suspressed, Entity possibleVictim = null)
 {
     this.owner      = owner;
     this.suspressed = suspressed && suspressedDamage > 0;
     Position        = spawnPosition - new Vector2(texture.Width / 2, texture.Height / 2);
     this.direction  = direction;
     this.teamId     = teamId;
     elapsedLifeTime = 0;
     if (possibleVictim != null && rayCastShot)
     {
         DamageAbleObject dmg = possibleVictim.GetComponent <DamageAbleObject>();
         if (dmg != null)
         {
             dmg.ChangeHealth(this, suspressed ? -suspressedDamage : -damage);
         }
     }
 }
Beispiel #6
0
        public override void Update(GameTime gameTime)
        {
            if (npcs == null)
            {
                npcs = new List <NPC>(EntityManager.ActivEntityManager.GetEntitiesByType <NPC>());
                for (int i = 0; i < npcs.Count; i++)
                {
                    DamageAbleObject dmg = npcs[i].GetComponent <DamageAbleObject>();
                    if (dmg != null)
                    {
                        dmg.OnDeath += Dmg_OnDeath;
                    }
                }
            }

            if (collidables == null)
            {
                collidables = EntityManager.ActivEntityManager.GetEntitiesByType <CollidAble>();
            }

            if (health == null)
            {
                health = GetComponent <DamageAbleObject>();
                if (health != null)
                {
                    health.OnHealthChanged += Health_OnHealthChanged;
                }
            }

            if (attacked)
            {
                elasedTimeSinceAttacked += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (elasedTimeSinceAttacked > 5000f)
                {
                    attacked = false;
                }
            }

            Think((float)gameTime.ElapsedGameTime.TotalMilliseconds);
            BaseUpdate(gameTime);
        }
Beispiel #7
0
        private void Projectile_OnTriggerEnter(object sender, CollisionArgs e)
        {
            if (e.CollisionObject != Owner && e.CollisionObject.Blocking)
            {
                if (!rayCastShot)
                {
                    DamageAbleObject health = e.CollisionObject.GetComponent <DamageAbleObject>();
                    if (health != null)
                    {
                        health.ChangeHealth(this, suspressed ? -suspressedDamage :  -damage);
                    }

                    if (e.CollisionObject.Name != "Cover")
                    {
                        Destroy();
                    }
                    else
                    {
                        crossedCover = true;
                    }
                }
            }
        }
Beispiel #8
0
        public void ResetLevel()
        {
            entityManager = new EntityManager();
            EntityManager.ActivEntityManager = entityManager;
            level   = new Level(levelPath, 50, this);
            enemies = null;

            playerIsDead  = false;
            enmiesAreDead = false;
            level.Spawn();
            if (gameMode == GameMode.PlayAble)
            {
                player = new Player(level.PlayerInfo.Speed, level.PlayerInfo.RotationSpeed, true, loadedTextures["player"], 0, level.PlayerInfo.Rotation, Vector2.One, Color.White, "Player", new Vector2(level.PlayerInfo.ColumnIndex * 50, level.PlayerInfo.RowIndex * 50), true, true, level.PlayerInfo.TeamId);
            }
            else
            {
                float y = level.PlayerInfo.RowIndex * 50;
                float x = level.PlayerInfo.ColumnIndex * 50;
                if (waypoints != null)
                {
                    //waypoints add hostage
                    Entity[] hostages = EntityManager.ActivEntityManager.GetEntitiesByName("Hostage");
                    if (hostages != null)
                    {
                        for (int i = 0; i < hostages.Length; i++)
                        {
                            waypoints.Insert(1, (hostages[i] as Character).Center);
                        }
                    }

                    x = waypoints[0].X;
                    waypoints[waypoints.Count - 1] = new Vector2(waypoints[waypoints.Count - 1].X, y);
                }
                PlayerController ki = new PlayerController(level, waypoints, level.PlayerInfo.Speed, level.PlayerInfo.RotationSpeed, true, loadedTextures["player"], 0, level.PlayerInfo.Rotation, Vector2.One, Color.White, "Player", new Vector2(x, y), true, true, level.PlayerInfo.TeamId);
                player = ki;
            }

            if (primaryWeaponName == null && level.PrimaryWeapons.Length > 0)
            {
                player.PickupWeapon(level.PrimaryWeapons[Helpers.Rand.Next(0, level.PrimaryWeapons.Length)]);
            }
            else
            {
                player.PickupWeapon(Level.GetWeapon(level.PrimaryWeapons, primaryWeaponName, primarySuspressed));
            }

            if (secondaryWeaponName == null && level.SecondaryWeapons.Length > 0)
            {
                player.PickupWeapon(level.SecondaryWeapons[Helpers.Rand.Next(0, level.SecondaryWeapons.Length)]);
            }
            else
            {
                player.PickupWeapon(Level.GetWeapon(level.SecondaryWeapons, secondaryWeaponName, secondarySuspressed));
            }

            DamageAbleObject dmg = new DamageAbleObject(player, "health", 1000, 1000);

            player.AddComponent(dmg);
            dmg.OnDeath += Dmg_OnDeath;

            if (enemies == null)
            {
                enemies = entityManager.GetEntitiesByType <NPC>().ToList();
                for (int i = 0; i < enemies.Count; i++)
                {
                    DamageAbleObject dmgNPC = enemies[i].GetComponent <DamageAbleObject>();
                    dmgNPC.OnDeath += DmgNPC_OnDeath;
                }
            }
        }