Exemplo n.º 1
1
 public abstract void MasterInsert(GameObject newObject);
Exemplo n.º 2
0
        public GameObject GetArrow(GameObject shooter, GameObject target, int id = -1)
        {
            var arrowContainerObject = new GameObject();
            arrowContainerObject.ConstructionStamp = "Arrow";
            arrowContainerObject.Team = shooter.Team;
            arrowContainerObject.ID = id == -1 ? MechanicSingleton.Instance.GetNextObjectCountValue() : id;
            arrowContainerObject.CurrentFrame = AssetRepository.Instance.ArrowAnimations(arrowContainerObject.Scale).CurrentAnimatedRectangle.CurrentFrame;

            arrowContainerObject.UsedInPathing = false;
            arrowContainerObject.SetPhysics(new NonCollidingPhysics(arrowContainerObject, gameRef.Level.Bounds));
            //arrow.SetRenderer(new RenderBase(arrow, AssetRepository.Instance.ArrowTexture, AssetRepository.Instance.ArrowAnimations));
            arrowContainerObject.SetBrain(new ArrowBrain(arrowContainerObject, target));
            arrowContainerObject.SetMover(new ProjectileMover(arrowContainerObject));
            arrowContainerObject.SetSkills(new SkillsComponent(arrowContainerObject));

            var arrowWeapon = new AlwaysAttackingWeapon(arrowContainerObject.Skills, arrowContainerObject);

            //DOTHIS figure out arrow sitch
            //arrowWeapon.EquipEffect(new BasicDamageEffect(durationMS: 250, damageRating: 25));
            arrowWeapon.SetRenderer((new RenderBase(arrowWeapon, AssetRepository.Instance.ArrowTexture, AssetRepository.Instance.ArrowAnimations(arrowContainerObject.Scale))));
            arrowContainerObject.EquipWeapon(arrowWeapon);

            arrowContainerObject.CurrentState = Constants.ACTOR_STATE_IDLE;
            arrowContainerObject.Position = shooter.Position;

            gameRef.container.AddObject(arrowContainerObject);

            return arrowContainerObject;
        }
Exemplo n.º 3
0
        public StatusCluster(GameObject watched)
        {
            //TODO: invent definitions for ui spritesheets
            Observing = watched;
            HealthBar = new UIBar(AssetRepository.Instance.UIBars, new Rectangle(30,30, 256,32), new Rectangle(0,8,64,8), new Rectangle(0,0,64,8));

            watched.Health.OnValueChanged += HandleHealthChange;
        }
Exemplo n.º 4
0
        public void RemoveObject(GameObject removeObject)
        {
#warning we cannot rely on local remove, sometimes this isn't valid mid update
            var removed = removeObject.CurrentQuad.Remove(removeObject); 
            removed = removed && LinearReference.Remove(removeObject);
            removed = removed && IndexedReference.Remove(removeObject.ID);
            if (!removed)
            {
                throw new Exception("Object containers out of sync");
            }
        }
Exemplo n.º 5
0
        public GameObject GetEnemyFootSoldier(int id = -1)
        {
            var enemy = new GameObject();
            enemy.ConstructionStamp = "EnemyFootSoldier";

            enemy.ID = id == -1 ? MechanicSingleton.Instance.GetNextObjectCountValue() : id;

            enemy.SetPhysics(new CollidingPhysics(enemy, gameRef.Level.Bounds));
            enemy.Position = new Vector2(MechanicSingleton.Instance.rand.Next(100, 500));
            //var renderer = new RenderBase(enemy, AssetRepository.Instance.Slime, AssetRepository.Instance.SlimeAnimations);

            enemy.Scale = 2f;
            var renderer = new RenderBase(enemy, AssetRepository.Instance.HeroTexture, AssetRepository.Instance.HeroAnimations(enemy.Scale));
            //var renderer = new RenderBase(enemy, AssetRepository.Instance.Slime, AssetRepository.Instance.SlimeAnimations(enemy.Scale));

            enemy.SetRenderer(renderer);

            var mover = new WalkingMover(enemy);
            mover.SetMovementNoMu(100, 75);
            enemy.SetMover(mover);
            enemy.SetEngine(new WalkerEngine(enemy));

            if (id == -1)
            {
                enemy.SetBrain(new FootSoldierBrain(enemy, gameRef.container.GetObjectById(0)));
            }
            else
            {
                enemy.SetBrain(new NetworkPlayerBrain(enemy));
            }

            enemy.SetCombat(new CombatBase(enemy));
            enemy.SetSkills(new SkillsComponent(enemy));

            // wire up the events between components
            enemy.EquipWeapon(GetSword(enemy));

            gameRef.container.AddObject(enemy);

            if (id == -1)
            {
                NetCommander.CreatedObject(enemy);
            }

            enemy.SpeedAccel = 25f;
            enemy.Team = 1;

            return enemy;
        }
Exemplo n.º 6
0
        public static void CreatedObject(GameObject player)
        {
            var parms = new CreateParameters()
            {
                ConstructorId = player.ConstructionStamp,
                ID = player.ID,
                Position = player.Position
            };

            SendCommand(new GameObjectCommand()
            {
                CommandType = GameObjectCommandType.Create,
                Parameters = parms,
            });
        }
Exemplo n.º 7
0
        public GameObject GetFriendlyAOEHealingTower(bool fromNetwork = false, int id = -1)
        {
            var tower = new GameObject();
            tower.ConstructionStamp = "FriendlyAOEHealingTower";
            tower.Team = 0;
            tower.ID = id == -1 ? MechanicSingleton.Instance.GetNextObjectCountValue() : id;
            tower.CurrentFrame = AssetRepository.Instance.TowerAnimations(tower.Scale).CurrentAnimatedRectangle.CurrentFrame;

            tower.UsedInPathing = true;
            tower.SetPhysics(new CollidingPhysics(tower, gameRef.Level.Bounds));
            tower.SetRenderer(new RenderBase(tower, AssetRepository.Instance.TowerTexture, AssetRepository.Instance.TowerAnimations(tower.Scale)));
            tower.SetBrain(new HealingAOETowerBrain(tower,
                new TowerPlacingInput(gameRef, tower.PhysicsCollisionBox)));

            tower.SetSkills(new SkillsComponent(tower));

            //DOTHIS this weapon needs to be tower specific, doing the healing on it's own
            //var healingAOEWeapon = new WeaponBase(tower.Skills, tower);

            if (fromNetwork)
            {
                tower.CurrentState = Constants.ACTOR_STATE_IDLE;
            }
            else
            {
                tower.CurrentState = Constants.ACTOR_STATE_PLACING;
            }

            tower.SetCombat(new CombatBase(tower));

            gameRef.container.AddObject(tower);

            if (!fromNetwork)
            {
                NetCommander.CreatedObject(tower);
            }

            return tower;
        }
Exemplo n.º 8
0
        public GameObject GetArrowTower(bool fromNetwork = false, int id = -1)
        {
            var tower = new GameObject();
            tower.ConstructionStamp = "ArrowTower";
            tower.Team = 0;
            tower.ID = id == -1 ? MechanicSingleton.Instance.GetNextObjectCountValue() : id;
            tower.CurrentFrame = AssetRepository.Instance.TowerAnimations(tower.Scale).CurrentAnimatedRectangle.CurrentFrame;

            tower.UsedInPathing = true;
            tower.SetPhysics(new CollidingPhysics(tower, gameRef.Level.Bounds));
            tower.SetRenderer(new RenderBase(tower, AssetRepository.Instance.TowerTexture, AssetRepository.Instance.TowerAnimations(tower.Scale)));
            tower.SetBrain(new ArrowTowerBrain(tower,
                new TowerPlacingInput(gameRef, tower.PhysicsCollisionBox)));
            tower.SetSkills(new SkillsComponent(tower));

            var emptyWeapon = new AlwaysAttackingWeapon(tower.Skills, tower);
            tower.EquipWeapon(emptyWeapon);

            if (fromNetwork)
            {
                tower.CurrentState = Constants.ACTOR_STATE_IDLE;
            }
            else
            {
                tower.CurrentState = Constants.ACTOR_STATE_PLACING;
            }

            tower.SetCombat(new CombatBase(tower));

            gameRef.container.AddObject(tower);

            if (!fromNetwork)
            {
                NetCommander.CreatedObject(tower);
            }

            return tower;
        }
Exemplo n.º 9
0
 public void BuildHUDForPlayer(GameObject player)
 {
     var playerbars = new StatusCluster(player);
     AddControl(playerbars);
 }
Exemplo n.º 10
0
 public void SetReceiver(GameObject receiver)
 {
     this.Receiver = receiver;
 }
Exemplo n.º 11
0
 public void SetCameraTackingObject(GameObject target)
 {
     this.target = target;
 }
Exemplo n.º 12
0
 public abstract bool Remove(GameObject removeObject);
Exemplo n.º 13
0
        //direct copy, was already robust enough
        private void InflateBoundry(GameObject newObject)
        {
            float currentXInflation = (queryBounds.Width - hardBounds.Width) / 2;
            float currentYInflation = (queryBounds.Height - hardBounds.Height) / 2;

            float inflateXBy = 0;
            float inflateYBy = 0;

            if (currentXInflation < newObject.PhysicsCollisionBox.Width / 2)
            {
                inflateXBy = (int)((float)newObject.CurrentFrame.DrawRectangle.Width / 1.5f) - currentXInflation;
            }

            if (currentYInflation < newObject.PhysicsCollisionBox.Height / 2)
            {
                inflateYBy = (int)((float)newObject.CurrentFrame.DrawRectangle.Height / 1.5f) - currentYInflation;
            }

            queryBounds.Inflate(inflateXBy, inflateYBy);
        }
Exemplo n.º 14
0
        public GameObject GetPlayer(Vector2? position = null)
        {
            var player = new GameObject();
            player.ConstructionStamp = "Player";
            player.Team = 0;

            player.Scale = 2f;

            player.ID = MechanicSingleton.Instance.GetNextObjectCountValue();

            var mover = new WalkingMover(player);
            mover.SetMovementNoF(200, .5f);

            player.SetPhysics(new CollidingPhysics(player, gameRef.Level.Bounds));
            if (position == null)
            {
                position = new Vector2(MechanicSingleton.Instance.rand.Next(1, 100));
            }

            player.Position = position.Value;

            var renderer = new RenderBase(player, AssetRepository.Instance.HeroTexture, AssetRepository.Instance.HeroAnimations(player.Scale));
            player.SetRenderer(renderer);
            player.SetBrain(new PlayerBrain(player, new PlayerControlInput()));
            player.SetMover(mover);
            player.SetEngine(new WalkerEngine(player));
            player.SetCombat(new CombatBase(player));
            player.SetSkills(new SkillsComponent(player));

            player.EquipWeapon(GetSword(player));
            player.EquipRage(GetRage(player));
            player.Skills.SetBoost(new SimpleBoostSkill(player.Skills, player));

            gameRef.container.AddObject(player);

            var parms = new CreateParameters()
            {
                ConstructorId = player.ConstructionStamp,
                ID = player.ID,
                Position = player.Position
            };

            NetCommander.CreatedObject(player);

            gameRef.controlManager.BuildHUDForPlayer(player);

            return player;
        }
Exemplo n.º 15
0
        public WeaponBase GetSword(GameObject owner)
        {
            var sword = new SwordWeapon(owner.Skills, owner);

            var swordRenderer = new RenderBase(sword, AssetRepository.Instance.SwordTexture, AssetRepository.Instance.SwordAnimations(owner.Scale));
            sword.SetRenderer(swordRenderer);

            return sword;
        }
Exemplo n.º 16
0
 public abstract bool Insert(GameObject newObject);
Exemplo n.º 17
0
        //done
        public override bool Insert(GameObject newObject)
        {
            if (!hardBounds.ContainsInclusive(newObject.PhysicsCollisionBox.Center))
            {
                return false;
            }

            //moves an object over one to prevent perfect stacking and infinite splitting
            //if (heldObjects.Count() != 0 && heldObjects.Any(o => o.Position == newObject.Position && o != newObject))
            //{
            //    newObject.Position = new Vector2(newObject.Position.X + 1, newObject.Position.Y + 1);
            //    MasterInsert(newObject);
            //    return true;
            //}

            if (!isParent)
            {
                //if it's not a parent, add to this collection and set values
                heldObjects.Add(newObject);
                newObject.CurrentQuad = this;
                InflateBoundry(newObject);

                //if there are now too many object in this quad, split it
                if (heldObjects.Count() > ObjectLimit)
                {
                    Split();
                }
                return true;
            }
            else
            {
                InflateBoundry(newObject);
                if (NW.Insert(newObject)) return true;
                else if (NE.Insert(newObject)) return true;
                else if (SW.Insert(newObject)) return true;
                else if (SE.Insert(newObject)) return true;
                else
                {
                    throw new Exception("Quad insertion failure, this SHOULD never happen");
                }
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// removes a specified object from this node and 
 /// returns whether it was removed or not found
 /// </summary>
 /// <param name="newObject">Object to remove</param>
 /// <returns>if the object was removed/found</returns>
 public override bool Remove(GameObject newObject)
 {
     if (containedObject == newObject)
     {
         containedObject = null;
         queryBounds = bounds;
         return true;
     }
     return false;
 }
Exemplo n.º 19
0
        /// <summary>
        /// splits this node into 4 quads and places it's held object into the appropriate child
        /// </summary>
        private void Split()
        {
            //build em up
            //nw left top
            NW = new ElasticQuadTree(new RectangleFloat(bounds.Left, bounds.Top, bounds.Width / 2, bounds.Height / 2), this);
            //ne center, top
            NE = new ElasticQuadTree(new RectangleFloat(bounds.Left + bounds.Width / 2, bounds.Top, bounds.Width / 2, bounds.Height / 2), this);
            //sw left center
            SW = new ElasticQuadTree(new RectangleFloat(bounds.Left, bounds.Top + bounds.Height / 2, bounds.Width / 2, bounds.Height / 2), this);
            //se center center
            SE = new ElasticQuadTree(new RectangleFloat(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2, bounds.Width / 2, bounds.Height / 2), this);

            //semi dangerous assumption that it contains an object at this point
            var temp = containedObject;
            containedObject = null;

            if (NW.Insert(temp)) return;
            else if (SW.Insert(temp)) return;
            else if (NE.Insert(temp)) return;
            else if (SE.Insert(temp)) return;

            MasterInsert(temp);
        }
Exemplo n.º 20
0
        /// <summary>
        /// attempts to insert the object into this node
        /// if it's a parent, it delegates this task to each of it's children
        /// </summary>
        /// <param name="newObject">object to be inserted</param>
        /// <returns>returns true if it was inserted</returns>
        public override bool Insert(GameObject newObject)
        {
            //check if object is in the node
            if (!bounds.ContainsInclusive(newObject.Position))
            {
                return false;
            }

            if (containedObject != null && newObject.Position == containedObject.Position)
            {
                newObject.Position = new Vector2(newObject.Position.X + 1, newObject.Position.Y + 1);
                MasterInsert(newObject);
                return true;
            }

            //if it's null, set it to the object
            if (!IsParent)
            {
                if (containedObject == null)
                {
                    containedObject = newObject;
                    newObject.CurrentQuad = this;
                    if (parent != null)
                    {
                        InflateBoundry(newObject);
                    }
                    return true;
                }
            }

            //got here because it's not a parent and still has an object to insert
            if (!IsParent)
            {
                Split();
                if (parent != null)
                {
                    InflateBoundry(newObject);
                }
            }

            //insert it into children derp yes repeated code....
            if (NW.Insert(newObject))
            {
                InflateBoundry(newObject);
                return true;
            }
            else if (SW.Insert(newObject))
            {
                InflateBoundry(newObject);
                return true;
            }
            else if (NE.Insert(newObject))
            {
                InflateBoundry(newObject);
                return true;
            }
            else if (SE.Insert(newObject))
            {
                InflateBoundry(newObject);
                return true;
            }
            //very bad subdivision error, we should keep an eye out for this
            throw new Exception("couldn't insert into quadtree because it didn't fit into subquads");
        }
 private bool IsWithinRadius(GameObject collider)
 {
     return (collider.Position - Owner.Position).Length() <= Radius;
 }
 public RadiusProximityChecker(GameObject owner, int radius = 250)
 {
     Owner = owner;
     Radius = radius;
 }
Exemplo n.º 23
0
 public PhysicsBase(GameObject owner, Rectangle levelBounds)
 {
     this.owner = owner;
     LevelBounds = levelBounds;
 }
Exemplo n.º 24
0
 //done
 public override void MasterInsert(GameObject newObject)
 {
     if (parent != null)
     {
         parent.MasterInsert(newObject);
     }
     else
     {
         Insert(newObject);
     }
 }
Exemplo n.º 25
0
        public GameObject GetNetworkPlayer(int id = -1)
        {
            var player = new GameObject();
            player.ID = id == -1 ? MechanicSingleton.Instance.GetNextObjectCountValue() : id;
            player.Team = 0;
            player.Position = new Vector2(100, 100);

            player.SetPhysics(new CollidingPhysics(player, gameRef.Level.Bounds));
            var renderer = new RenderBase(player, AssetRepository.Instance.HeroTexture, AssetRepository.Instance.HeroAnimations(player.Scale));
            player.SetRenderer(renderer);
            player.SetBrain(new NetworkPlayerBrain(player));
            player.SetCombat(new COMBATPLACEHOLDER(player));
            player.SetMover(new WalkingMover(player));
            player.SetEngine(new WalkerEngine(player));
            player.EquipWeapon(GetSword(player));

            gameRef.container.AddObject(player);

            return player;
        }
Exemplo n.º 26
0
 //ehhhhh not quite done yet
 public override void NotifyOfMovement(GameObject ownedObject)
 {
     if (!hardBounds.ContainsInclusive(ownedObject.Position) || !heldObjects.Contains(ownedObject))
     {
         if (Remove(ownedObject))
         {
             MasterInsert(ownedObject);
         }
         Verify();
     }
 }
Exemplo n.º 27
0
        public RageBase GetRage(GameObject owner)
        {
            var rage = new RageExplosion(0, owner.Skills, owner);
            rage.Scale = 16f;
            var rageRenderer = new RenderBase(rage, AssetRepository.Instance.Rage2, AssetRepository.Instance.Rage2Animations(rage.Scale));
            rage.SetRenderer(rageRenderer);

            return rage;
        }
Exemplo n.º 28
0
        //done
        public override bool Remove(GameObject newObject)
        {
            var success = heldObjects.Remove(newObject);

            if (success)
            {
                queryBounds = hardBounds;
                foreach (var obj in heldObjects)
                {
                    InflateBoundry(obj);
                }
            }

            return success;
        }
Exemplo n.º 29
0
        /// <summary>
        /// folds up unused quads by checking this node and it's parent, and on up if it keeps finding empty nodes
        /// </summary>
        private void Verify()
        {
            if (IsParent)
            {
                //if it's 0, collapse check parent
                var children = ChildCount();
                if (children == 0)
                {
                    NW = SW = NE = SE = null;//ugly but it works better for this circumstance
                    parent.Verify();
                }
                else if (children == 1)
                {
                    var objects = GatherAll()[0];
                    NW = SW = NE = SE = null;
                    containedObject = objects;
                    objects.CurrentQuad = this;

                    if (parent != null) //doh, forgot that the master quad doesn't have a parent...
                    {
                        parent.Verify();
                    }
                }
                //if it's more than 1, do nothing
            }
            else
            {
                if (parent != null) //temp bug fix not sure why this was null...
                {
                    parent.Verify();
                }
            }
        }
Exemplo n.º 30
0
 public abstract void NotifyOfMovement(GameObject ownedObject);