public void CreateUnit(Team team, Vector2 pos, UnitTextures tex, SoundEffect sound, Color color, float depth, float speed, float attackSpeed, float bulletSpeed, float health, float radius, bool flipped) { GameObject unit = new GameObject(pos, flipped ? tex.Left : tex.Right); unit.Depth = depth; unit.Components.Add(new Unit(unit, team, sound, color, speed, attackSpeed, bulletSpeed, tex)); unit.Components.Add(new Health(unit, health)); unit.Components.Add(new CircleCollider(unit, radius)); team.AddUnit(unit); }
public Unit(GameObject GO, Team team, SoundEffect sound, Color color, float movespeed, float attackSpeed, float projectileDistance, UnitTextures textures) : base(GO) { Speed = movespeed; this.color = color; CooldownToAttack = attackSpeed; AttackSpeed = attackSpeed; Team = team; ProjectileDistance = projectileDistance; Sound = sound; UnitTexture = textures; }
public ControlTimer(Team conquerer) { this.conquerer = conquerer; }
public override void Update(float dtime) { //AttachedTo.Renderer.SetTexture(Textures.checkpoint); bool teamAInRange = false; bool teamBInRange = false; Team controlTeam = null; // Find nearby units foreach (GameObject obj in GameObject.GameObjects) { Unit unit = obj.GetComponent<Unit>(); if (unit != null && Vector2.Distance(AttachedTo.Position, obj.Position) <= controlDistance) { if (unit.Team.TeamNumber == 1) { teamAInRange = true; controlTeam = unit.Team; } else if (unit.Team.TeamNumber == 2) { teamBInRange = true; controlTeam = unit.Team; } } } // .. if ((teamAInRange && !teamBInRange) || (teamBInRange && !teamAInRange)) { //if (controller == null) //{ if (controlTimer == null && controlTeam != controller) { controlTimer = new ControlTimer(controlTeam); } else if (controlTimer != null && controlTimer.Conquerer == controlTeam) { controlTimer.Time += dtime; if (controlTimer.Time >= ControlTimer.maxTime) { controller = controlTeam; controlTimer = null; controller.Sound.Play(); } } else if (controlTimer != null && controlTimer.Conquerer != controlTeam) { controlTimer = new ControlTimer(controlTeam); } //} } if (controller != null) { if (controller.TeamNumber == 1) { AttachedTo.Renderer.SetTexture(Textures.checkpointA); } else if (controller.TeamNumber == 2) { AttachedTo.Renderer.SetTexture(Textures.checkpointB); } } else { AttachedTo.Renderer.SetTexture(Textures.checkpoint); } addPoints(dtime); }
private void checkForWinner() { if (teamA.Points >= 100f || teamB.Units.TrueForAll(go => go.GetComponent<Health>().IsDead)){ gameOver = true; winner = teamA; } else if (teamB.Points >= 100f || teamA.Units.TrueForAll(go => go.GetComponent<Health>().IsDead)) { gameOver = true; winner = teamB; } }
private static void SelectedUnitAttack(Team team, PlayerIndex index) { if (team.SelectedUnit != null) { var dir = InputManager.ThumbMovement(GamePad.GetState(index, GamePadDeadZone.None).ThumbSticks.Right); /*if (GamePad.GetState(index).Buttons.RightShoulder == ButtonState.Pressed) {*/ if (dir != Vector2.Zero) { dir.Normalize(); dir.Y *= -1.0f; team.SelectedUnit.AttackDir = dir; team.SelectedUnit.ShouldFire = true; } else { team.SelectedUnit.ShouldFire = false; } //} } }
public void StartGame() { InputManager.playerOneState = GamePad.GetState(PlayerIndex.One); InputManager.playerTwoState = GamePad.GetState(PlayerIndex.Two); teamA = new Team(); teamA.TeamNumber = 1; teamA.Sound = Sounds.conquerA; teamB = new Team(); teamB.TeamNumber = 2; teamB.Sound = Sounds.conquerB; float attackSpeed = 0.15f; float bulletSpeed = 400f; float speed = 100.0f; float size = 32.0f; CreateUnit(teamA, new Vector2(175, 75), Textures.RobotYellow, Sounds.shootA, Color.Yellow, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, false); CreateUnit(teamA, new Vector2(175, 175), Textures.RobotRed, Sounds.shootB, Color.Red, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, false); CreateUnit(teamA, new Vector2(175, 275), Textures.RobotGreen, Sounds.shootC, Color.Green, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, false); CreateUnit(teamA, new Vector2(175, 375), Textures.RobotBlue, Sounds.shootD, Color.Blue, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, false); CreateUnit(teamB, new Vector2(1105, 345), Textures.AlienBlue, Sounds.shootA, Color.Blue, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, true); CreateUnit(teamB, new Vector2(1105, 445), Textures.AlienRed, Sounds.shootB, Color.Red, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, true); CreateUnit(teamB, new Vector2(1105, 545), Textures.AlienGreen, Sounds.shootC, Color.Green, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, true); CreateUnit(teamB, new Vector2(1105, 645), Textures.AlienYellow, Sounds.shootD, Color.Yellow, 0.2f, speed, attackSpeed, bulletSpeed, 100.0f, size, true); GameObject checkpointA = new GameObject(new Vector2(860, 250), Textures.checkpoint); checkpointA.Components.Add(new Checkpoint(checkpointA, 100.0f)); GameObject checkpointB = new GameObject(new Vector2(640, 360), Textures.checkpoint); checkpointB.Components.Add(new Checkpoint(checkpointB, 100.0f)); GameObject checkpointC = new GameObject(new Vector2(420, 470), Textures.checkpoint); checkpointC.Components.Add(new Checkpoint(checkpointC, 100.0f)); // Walls GameObject wall = new GameObject(new Vector2(0, 640), null); wall.Components.Add(new SquareCollider(wall, 230, 1280)); wall = new GameObject(new Vector2(1280, 640), null); wall.Components.Add(new SquareCollider(wall, 230, 1280)); wall = new GameObject(new Vector2(0, 0), null); wall.Components.Add(new SquareCollider(wall, 640, 40)); wall = new GameObject(new Vector2(655, 0), null); wall.Components.Add(new SquareCollider(wall, 200, 40)); wall = new GameObject(new Vector2(1280, 0), null); wall.Components.Add(new SquareCollider(wall, 640, 40)); wall = new GameObject(new Vector2(655, 720), null); wall.Components.Add(new SquareCollider(wall, 200, 40)); wall = new GameObject(new Vector2(0, 720), null); wall.Components.Add(new SquareCollider(wall, 640, 40)); wall = new GameObject(new Vector2(1280, 720), null); wall.Components.Add(new SquareCollider(wall, 640, 40)); wall = new GameObject(new Vector2(1280, 720), null); wall.Components.Add(new SquareCollider(wall, 230, 1280)); // Obstacles GameObject box = new GameObject(new Vector2(375, 540), Textures.horizontalBlock); box.Components.Add(new SquareCollider(box, 142, 50)); box = new GameObject(new Vector2(905, 180), Textures.horizontalBlock); box.Components.Add(new SquareCollider(box, 142, 50)); box = new GameObject(new Vector2(320, 200), Textures.verticalBlock); //box.Depth = 0.6f; box.Components.Add(new SquareCollider(box, 50, 142)); box = new GameObject(new Vector2(960, 520), Textures.verticalBlock); box.Components.Add(new SquareCollider(box, 50, 142)); box = new GameObject(new Vector2(510, 360), Textures.squareBlock); box.Components.Add(new SquareCollider(box, 100, 100)); box = new GameObject(new Vector2(770, 360), Textures.squareBlock); box.Components.Add(new SquareCollider(box, 100, 100)); /* box = new GameObject(new Vector2(450, 350), Textures.box); box.Components.Add(new SquareCollider(box, 128, 64)); box = new GameObject(new Vector2(650, 360), Textures.box); box.Components.Add(new SquareCollider(box, 128, 64)); box = new GameObject(new Vector2(900, 600), Textures.box); box.Components.Add(new SquareCollider(box, 128, 64)); */ //MediaPlayer.Play(Sounds.gameMusic); //MediaPlayer. music = Sounds.gameMusic.CreateInstance(); music.Play(); }