public override void Update(GameTime gameTime) { base.Update(gameTime); if (!breaking) { inNetwork = false; randomTimer += gameTime.ElapsedGameTime.TotalSeconds; if (randomTimer > 10) { randomTimer = 0; this.Velocity = new Vector2(WifiWars.Random.Next(-50, 51), WifiWars.Random.Next(-50, 51)); } GameObjectList level = this.parent.Parent as GameObjectList; GameObjectList TowerList = level.Find("towerlist") as GameObjectList; List <GameObject> Towers = TowerList.Objects; foreach (Tower tower in Towers) { if (Math.Sqrt(Math.Pow((this.position.X - tower.Position.X - tower.Center.X), 2) + Math.Pow((this.position.Y - tower.Position.Y - tower.Center.Y), 2)) < 100) { inNetwork = true; } } if (!inNetwork) { velocity = -velocity; outsidetimeout += 1; } if (outsidetimeout >= 5) { remove = true; } GameObjectList packetList = level.Find("packetList") as GameObjectList; List <GameObject> packets = packetList.Objects; foreach (Packet packet in packets) { if (Math.Sqrt(Math.Pow((this.position.X - packet.Position.X - packet.Center.X), 2) + Math.Pow((this.position.Y - packet.Position.Y - packet.Center.Y), 2)) < 100) { Vector2 direction = new Vector2(packet.Position.X - this.position.X, packet.Position.Y - this.position.Y); direction.Normalize(); this.Velocity = direction * 50; } if (this.CollidesWith(packet)) { packet.remove = true; remove = true; } } } else { this.PlayAnimation("breaking"); if (this.Current.AnimationEnded) { remove = true; } } }
public void OnDeserialization(object sender) { tempSeenBy.OnDeserialization(sender); seenBy.OnDeserialization(sender); foreach (KeyValuePair <string, float> kvp in tempSeenBy) { Living l = (tempLocal.GetGameObjectByGUID(Guid.Parse(kvp.Key)) ?? onTile.Find(obj => obj.GUID == Guid.Parse(kvp.Key))) as Living; seenBy.Add(l, kvp.Value); } tempSeenBy = null; tempLocal = null; }
public override void Update(GameTime gameTime) { base.Update(gameTime); inNetwork = false; randomTimer += gameTime.ElapsedGameTime.TotalSeconds; if (randomTimer > 10) { randomTimer = 0; this.Velocity = new Vector2(WifiWars.Random.Next(-50, 51), WifiWars.Random.Next(-50, 51)); } GameObjectList level = this.parent as GameObjectList; GameObjectList TowerList = level.Find("towerlist") as GameObjectList; List <GameObject> Towers = TowerList.Objects; foreach (Tower tower in Towers) { if (Math.Sqrt(Math.Pow((this.position.X - tower.Position.X - tower.Center.X), 2) + Math.Pow((this.position.Y - tower.Position.Y - tower.Center.Y), 2)) < 100) { inNetwork = true; } } if (!inNetwork) { velocity = -velocity; outsidetimeout += 1; } if (outsidetimeout >= 5) { remove = true; } GameObjectList pirateList = level.Find("pirateList") as GameObjectList; List <GameObject> pirates = pirateList.Objects; foreach (PirateShip pirate in pirates) { if (Math.Sqrt(Math.Pow((this.position.X - pirate.Position.X - pirate.Center.X), 2) + Math.Pow((this.position.Y - pirate.Position.Y - pirate.Center.Y), 2)) < 150) { Vector2 direction = new Vector2(pirate.Position.X - this.position.X, pirate.Position.Y - this.position.Y); direction.Normalize(); this.Velocity = direction * 75; } if (this.CollidesWith(pirate)) { pirate.remove = true; remove = true; } } }
public override void HandleInput(InputHelper inputHelper) { base.HandleInput(inputHelper); if (inputHelper.MousePosition.X < this.Position.X + 58 && inputHelper.MousePosition.X > this.Position.X + 22 && inputHelper.MousePosition.Y < this.Position.Y + 15 && inputHelper.MousePosition.Y > this.Position.Y) { if (inputHelper.MouseLeftButtonPressed()) { GameObjectList level = this.parent as GameObjectList; UI ui = level.Find("ui") as UI; if (!active) { this.Sprite = new SpriteSheet("Sprites/homeActive", 0); active = true; SpriteGameObject buffer = ui.Find("buffer") as SpriteGameObject; buffer.Visible = false; GameEnvironment.AssetManager.PlaySound("Sounds/snd_switch"); } else { this.Sprite = new SpriteSheet("Sprites/home", 0); active = false; SpriteGameObject buffer = ui.Find("buffer") as SpriteGameObject; buffer.Visible = true; GameEnvironment.AssetManager.PlaySound("Sounds/snd_switch"); } } } }
public override void Update(GameTime gameTime) { if (centerObjectID != null) { //Set position so that centerObject is in middle and camera does not cross level borders. GameObjectList parentList = (GameObjectList)parent; GameObject centerObject = parentList.Find(centerObjectID); position = centerObject.Position - GameEnvironment.Screen.ToVector2() / 2; //Check if new position is out of bounds, if so correct. if (position.X < limitBB.Left) { position.X = limitBB.Left; } else if (position.X > limitBB.Right - BoundingBox.Width) { position.X = limitBB.Right - BoundingBox.Width; } if (position.Y > limitBB.Bottom - BoundingBox.Height) { position.Y = limitBB.Bottom - BoundingBox.Height; } else if (position.Y < limitBB.Top) { position.Y = limitBB.Top; } } }
public override void HandleInput(InputHelper inputHelper) { base.HandleInput(inputHelper); if (makePacket) { int rand = GameEnvironment.Random.Next(15); GameObjectList level = this.parent as GameObjectList; SpriteGameObject home = GameWorld.Find("home") as SpriteGameObject; GameObjectList TowerList = GameWorld.Find("towerlist") as GameObjectList; if ((rand == 1 || rand == 2) && spawnVirus == true) { Virus virus = new Virus(this.position + this.Center, this, TowerList, home); level.Add(virus); } else if (rand == 3 && spawnTrojan == true) { Trojan trojan = new Trojan(this.position + this.Center, this, TowerList, home); level.Add(trojan); } else { Packet packet = new Packet(this.position + this.Center, serverColor, type, this, TowerList, home); GameObjectList packetList = level.Find("packetList") as GameObjectList; packetList.Add(packet); } makePacket = false; } }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (active) { GameObjectList level = this.parent.Parent as GameObjectList; UI ui = level.Find("ui") as UI; if (ui.Money >= 0.01) { ui.Money -= 0.01f; } else { this.Sprite = new SpriteSheet("Sprites/AntiPirateHideout", 0); active = false; GameEnvironment.AssetManager.PlaySound("Sounds/snd_switch"); } pirateTimer += gameTime.ElapsedGameTime.TotalSeconds; } if (pirateTimer > 4) { pirateTimer = 0; makeAntiPirate = true; } }
/// <summary>Update the follower.</summary> public override void Update(GameTime gameTime) { GameObjectList gameWorld = Root as GameObjectList; Player player = gameWorld.Find("player") as Player; float direction = player.Position.X - position.X; if (Math.Sign(direction) != Math.Sign(velocity.X) && player.Velocity.X != 0.0f && velocity.X != 0.0f) { TurnAround(); } base.Update(gameTime); }
public override void HandleInput(InputHelper inputHelper) { base.HandleInput(inputHelper); if (makePirate) { GameObjectList level = this.parent.Parent as GameObjectList; PirateShip pirate = new PirateShip(position + new Vector2(70, 50), 1010, "pirate"); GameObjectList pirateList = level.Find("pirateList") as GameObjectList; pirateList.Add(pirate); makePirate = false; } }
public GameObject Find(string id) { foreach (GameObject obj in gameObjects) { if (obj.ID == id) { return(obj); } if (obj is GameObjectList) { GameObjectList objlist = obj as GameObjectList; GameObject subobj = objlist.Find(id); if (subobj != null) { return(subobj); } } } return(null); }
/// <summary> /// Find an object among children with a given condition /// </summary> /// <param name="del"></param> /// <returns></returns> public virtual GameObject Find(Func <GameObject, bool> del) { if (inventory != null) { if (del.Invoke(inventory)) // Check if the inventory fits "del" { return(inventory); } GameObject invResult = inventory.Find(del); // Find the object matching "del" among the children of inventory if (invResult != null) { return(invResult); } } if (equipmentSlots != null) { if (del.Invoke(equipmentSlots)) // Check if equipmentSlots fits "del" { return(equipmentSlots); } GameObject eqResult = equipmentSlots.Find(del); // Find the object matching "del" among the children of equipmentSlots if (eqResult != null) { return(eqResult); } } if (skillList != null) { if (del.Invoke(skillList)) // Check if equipmentSlots fits "del" { return(skillList); } GameObject slResult = skillList.Find(del); // Find the object matching "del" among the children of equipmentSlots if (slResult != null) { return(slResult); } } return(null); }
public override void Update(GameTime gameTime) { GameObjectList gameWorld = Root as GameObjectList; Player player = gameWorld.Find("player") as Player; direction = player.Position - position; //calculates the vector the enemy needs to travel float distance = direction.Length(); direction.Normalize(); //calculates the normalized vector movement = speed * (float)gameTime.ElapsedGameTime.TotalSeconds; if (player.Position != position) { movement += 5 * direction; //makes the movement of the enemy more towards the direction between the enemy and the endpoint position += movement; } if (CollidesWith(player)) { Player.Health -= 10; health -= 2; } GameObjectList friendlyBullets = GameWorld.Find("friendlyBullets") as GameObjectList; for (int i = friendlyBullets.children.Count - 1; i >= 0; i--) { SpriteGameObject friendlyBullet = friendlyBullets.children[i] as SpriteGameObject; if (CollidesWith(friendlyBullet)) { friendlyBullets.children[i].health--; this.health--; if (this.health < 0) { TextGameObject kills = GameWorld.Find("killsText") as TextGameObject; kills.health++; } } } }