public override void Update(GameTime gameTime) { for (int index = 0; index < EntityManager.Entities.Count; index++) { var entity = EntityManager.Entities[index]; if (entity is Soldier) { Vector2 distance1 = new Vector2(this.GetComponent<Component.Transform>().Grid.Position.X, this.GetComponent<Component.Transform>().Grid.Position.Y); Vector2 distance2 = new Vector2(entity.GetComponent<Component.Transform>().Grid.Position.X, entity.GetComponent<Component.Transform>().Grid.Position.Y); if (Vector2.Distance(distance1, distance2) < wakingDistance && TurnManager.currentTurn >= wakingTurn/* && Vector2.Distance(distance1, distance2) > sleepingDistance*/) { var enemy = new SmallEnemy(ref swarm); if (type == "BUB") { enemy.LoadBoss(); } enemy.X = this.X; enemy.Y = this.Y; swarm.Add(enemy); this.Remove(); break; } } } }
public override void Update(GameTime gameTime) { for (int index = 0; index < EntityManager.Entities.Count; index++) { var entity = EntityManager.Entities[index]; if (entity is Soldier) { Vector2 distance1 = new Vector2(this.GetComponent <Component.Transform>().Grid.Position.X, this.GetComponent <Component.Transform>().Grid.Position.Y); Vector2 distance2 = new Vector2(entity.GetComponent <Component.Transform>().Grid.Position.X, entity.GetComponent <Component.Transform>().Grid.Position.Y); if (Vector2.Distance(distance1, distance2) < wakingDistance && TurnManager.currentTurn >= wakingTurn /* && Vector2.Distance(distance1, distance2) > sleepingDistance*/) { var enemy = new SmallEnemy(ref swarm); if (type == "BUB") { enemy.LoadBoss(); } enemy.X = this.X; enemy.Y = this.Y; swarm.Add(enemy); this.Remove(); break; } } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); lightShader = Content.Load <Effect>("shaders/LightEffect"); lightRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); sceneRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); Map = Content.Load <Map>("maps/prototyp2"); //Map = Content.Load<Map>("maps/Aztek.Test"); //Map = Content.Load<Map>("maps/Cave.Level1"); // Load map objects Map.ParseObjects(this); Squad[0].Name = "Dean H. Jones"; Squad[0].Transform.World.Rotation = -MathHelper.PiOver2; Squad[1].Name = "Walter L. Verville"; Squad[1].Transform.World.Rotation = -MathHelper.PiOver2; Squad[2].Name = "Patrick Y. Southerland"; Squad[2].Transform.World.Rotation = -MathHelper.PiOver2; Squad[3].Name = "Andrew C. Friend"; Squad[3].Transform.World.Rotation = -MathHelper.PiOver2; Squad[4].Name = "Gary B. Whitley"; Squad[4].Transform.World.Rotation = -MathHelper.PiOver2; // Center the camera on a unit Camera.Position = Squad[0].Transform.World.Position * -1 + new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); GroupManager = new DynamicGroupManager(Squad.Cast <Entity>().ToList(), (float)Grid.TileSize * 3.5f); Interface.CreateUnitFrames(Squad); // TODO: use this.Content to load your game content here Soldier.LoadContent(); //SmallEnemy.LoadContent(); //Shot.LoadContent(); MouseInput = new MouseInput(this); MouseInput.LoadContent(); KeyboardInput = new KeyboardInput(this); TestMonster = new SmallEnemy(ref Swarm); TestMonster.X = 12; TestMonster.Y = 4; Swarm.Add(TestMonster); // Load Lua scripts after everything is created Lua.LoadScripts(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); lightShader = Content.Load<Effect>("shaders/LightEffect"); lightRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents); sceneRenderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); Map = Content.Load<Map>("maps/prototyp2"); //Map = Content.Load<Map>("maps/Aztek.Test"); //Map = Content.Load<Map>("maps/Cave.Level1"); // Load map objects Map.ParseObjects(this); Squad[0].Name = "Dean H. Jones"; Squad[0].Transform.World.Rotation = -MathHelper.PiOver2; Squad[1].Name = "Walter L. Verville"; Squad[1].Transform.World.Rotation = -MathHelper.PiOver2; Squad[2].Name = "Patrick Y. Southerland"; Squad[2].Transform.World.Rotation = -MathHelper.PiOver2; Squad[3].Name = "Andrew C. Friend"; Squad[3].Transform.World.Rotation = -MathHelper.PiOver2; Squad[4].Name = "Gary B. Whitley"; Squad[4].Transform.World.Rotation = -MathHelper.PiOver2; // Center the camera on a unit Camera.Position = Squad[0].Transform.World.Position * -1 + new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2); GroupManager = new DynamicGroupManager(Squad.Cast<Entity>().ToList(), (float)Grid.TileSize * 3.5f); Interface.CreateUnitFrames(Squad); // TODO: use this.Content to load your game content here Soldier.LoadContent(); //SmallEnemy.LoadContent(); //Shot.LoadContent(); MouseInput = new MouseInput(this); MouseInput.LoadContent(); KeyboardInput = new KeyboardInput(this); TestMonster = new SmallEnemy(ref Swarm); TestMonster.X = 12; TestMonster.Y = 4; Swarm.Add(TestMonster); // Load Lua scripts after everything is created Lua.LoadScripts(); }
public void Update(GameTime gameTime) { KeyboardState ks = Keyboard.GetState(); // Brightness if (ks.IsKeyUp(Keys.Up) && lastKeyboardState.IsKeyDown(Keys.Up)) core.Brightness = (int)MathHelper.Clamp(core.Brightness + 5, 0, 254); if (ks.IsKeyUp(Keys.Down) && lastKeyboardState.IsKeyDown(Keys.Down)) core.Brightness = (int)MathHelper.Clamp(core.Brightness - 5, 0, 254); // Debug test: grouping if (ks.IsKeyUp(Keys.K) && lastKeyboardState.IsKeyDown(Keys.K)) { if (groupManager == null) groupManager = new DynamicGroupManager(core.Squad.Cast<Entity>().ToList(), Grid.TileSize * 1.5f); groupManager.UpdateGroups(); //var groups = GetGroups(core.Squad, (float)Grid.TileSize * 1.5f); var groups = groupManager.Groups; foreach (var group in groups) { Debug.WriteLine("Group #" + groups.IndexOf(group) + " Panic: " + group.Panic); foreach (var entity in group.Entities) { var soldier = (Soldier)entity; Debug.WriteLine(soldier.Name + " " + soldier.GetHashCode()); } } } // Next turn if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter)) { if (core.TurnManager.CurrentTurn == core.TurnManager["Player"]) { foreach (var unit in core.Squad) { unit.AP = unit.MaxActionPoints; unit.Fired = false; } core.TurnManager.EndTurn(); } if (core.TurnManager.CurrentTurn == core.TurnManager["Computer"]) { foreach (var enemy in core.Swarm) { enemy.step = 0; enemy.AttackedThisTurn = false; Point target = Point.Zero; float distance = 7000; foreach (var unit in core.Squad) { Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y); Vector2 monster = new Vector2(enemy.Transform.Grid.X, enemy.Transform.Grid.Y); float newDistance = Vector2.Distance(soldier, monster); if (newDistance < distance) { target = unit.Transform.Grid; distance = newDistance; } } enemy.GetComponent<Component.PathFinder>().Goal = target; distance = 7000; } core.TestMonster.step = 0; Point testTarget = Point.Zero; float testDistance = 7000; foreach (var unit in core.Squad) { Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y); Vector2 monster = new Vector2(core.TestMonster.Transform.Grid.X, core.TestMonster.Transform.Grid.Y); float newDistance = Vector2.Distance(soldier, monster); if (newDistance < testDistance) { testTarget = unit.Transform.Grid; testDistance = newDistance; } } core.TestMonster.GetComponent<Component.PathFinder>().Goal = testTarget; testDistance = 7000; core.TurnManager.EndTurn(); } } if (ks.IsKeyDown(Keys.A)) { /*foreach (var unit in core.Swarm) { unit.X = 200; unit.Y = 200; }*/ core.TestMonster.X = 12; core.TestMonster.Y = 4; } if (ks.IsKeyUp(Keys.O) && lastKeyboardState.IsKeyDown(Keys.O)) { try { EntityManager.GetEntities<Door>()[0].Toggle(); } catch { } } if (ks.IsKeyUp(Keys.P) && lastKeyboardState.IsKeyDown(Keys.P)) { try { var pos = core.GroupManager.Groups[1].Entities[0].Transform.World.Position; var enemy = new SmallEnemy(ref core.Swarm); enemy.Transform.World.Position = pos + new Vector2(0, Grid.TileSize*3); core.Swarm.Add(enemy); } catch { } } if (ks.IsKeyDown(Keys.S) || ks.IsKeyDown(Keys.R)) { foreach (var soldier in core.Squad) { if (soldier.Selected == true && soldier.Fired == false) { bool enoughActionPoints = true; int cost = 0; string type = ""; if (ks.IsKeyDown(Keys.S)) { cost = bulletCost; type = "bullet"; } else if (ks.IsKeyDown(Keys.R)) { cost = rocketCost; type = "Rocket"; } if (soldier.AP >= cost) { core.Volley.Add(new Shot(soldier.GetComponent<Component.Stat>(), type)); soldier.AP -= cost; soldier.Fired = true; } else { enoughActionPoints = false; } if (enoughActionPoints == true) { foreach (var shot in core.Volley) { if (shot.select == false) { shot.select = true; shot.X = soldier.X; shot.Y = soldier.Y; //shot.Transform.World.Position += soldier.Transform.World.Origin; //shot.Transform.World.X += Grid.TileSize / 2; //shot.Transform.World.Y += Grid.TileSize / 2; } if (shot.direction == Vector2.Zero) { double directionX = Math.Cos(soldier.Transform.World.Rotation); double directionY = Math.Sin(soldier.Transform.World.Rotation); shot.direction = new Vector2((float)directionX, (float)directionY); shot.Transform.World.Rotation = soldier.Transform.World.Rotation; Vector2 yo = soldier.Transform.World.Position; shot.Stat.Remember = yo; } } } } } } if (ks.IsKeyDown(Keys.C)) { foreach (var soldier in core.Squad) { if (soldier.Selected == true && soldier.Fired == false) { Point checker = Point.Zero; double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation); double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation); Vector2 direction = new Vector2((int)directionX, (int)directionY); int range = 120; int current = 0; bool hit = false; checker = new Point((int)soldier.Transform.World.Origin.X, (int)soldier.Transform.World.Origin.Y); do { checker.X += (int)direction.X * checkerSpeed; checker.Y += (int)direction.Y * checkerSpeed; foreach (var creature in core.Swarm) { if (creature.GetComponent<Component.Collision>().Rectangle.Contains(checker)) { hit = true; } } if (core.TestMonster.GetComponent<Component.Collision>().Rectangle.Contains(checker)) { } current++; } while (hit == false && current < range); current = 0; if (soldier.Selected == true && soldier.Fired == false && hit == true) { core.Volley.Add(new Shot(soldier.GetComponent<Component.Stat>(), "Bullet")); soldier.Fired = true; foreach (var shot in core.Volley) { if (shot.select == false) { shot.select = true; shot.X = soldier.X; shot.Y = soldier.Y; //shot.Transform.World.X += Grid.TileSize / 2; //shot.Transform.World.Y += Grid.TileSize / 2; } if (shot.direction == Vector2.Zero) { shot.direction = new Vector2((float)directionX, (float)directionY); shot.Transform.World.Rotation = soldier.Transform.World.Rotation; } } } hit = false; } } } lastKeyboardState = ks; }
public void Update(GameTime gameTime) { KeyboardState ks = Keyboard.GetState(); // Brightness if (ks.IsKeyUp(Keys.Up) && lastKeyboardState.IsKeyDown(Keys.Up)) { core.Brightness = (int)MathHelper.Clamp(core.Brightness + 5, 0, 254); } if (ks.IsKeyUp(Keys.Down) && lastKeyboardState.IsKeyDown(Keys.Down)) { core.Brightness = (int)MathHelper.Clamp(core.Brightness - 5, 0, 254); } // Debug test: grouping if (ks.IsKeyUp(Keys.K) && lastKeyboardState.IsKeyDown(Keys.K)) { if (groupManager == null) { groupManager = new DynamicGroupManager(core.Squad.Cast <Entity>().ToList(), Grid.TileSize * 1.5f); } groupManager.UpdateGroups(); //var groups = GetGroups(core.Squad, (float)Grid.TileSize * 1.5f); var groups = groupManager.Groups; foreach (var group in groups) { Debug.WriteLine("Group #" + groups.IndexOf(group) + " Panic: " + group.Panic); foreach (var entity in group.Entities) { var soldier = (Soldier)entity; Debug.WriteLine(soldier.Name + " " + soldier.GetHashCode()); } } } // Next turn if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter)) { if (core.TurnManager.CurrentTurn == core.TurnManager["Player"]) { foreach (var unit in core.Squad) { unit.AP = unit.MaxActionPoints; unit.Fired = false; } core.TurnManager.EndTurn(); } if (core.TurnManager.CurrentTurn == core.TurnManager["Computer"]) { foreach (var enemy in core.Swarm) { enemy.step = 0; enemy.AttackedThisTurn = false; Point target = Point.Zero; float distance = 7000; foreach (var unit in core.Squad) { Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y); Vector2 monster = new Vector2(enemy.Transform.Grid.X, enemy.Transform.Grid.Y); float newDistance = Vector2.Distance(soldier, monster); if (newDistance < distance) { target = unit.Transform.Grid; distance = newDistance; } } enemy.GetComponent <Component.PathFinder>().Goal = target; distance = 7000; } core.TestMonster.step = 0; Point testTarget = Point.Zero; float testDistance = 7000; foreach (var unit in core.Squad) { Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y); Vector2 monster = new Vector2(core.TestMonster.Transform.Grid.X, core.TestMonster.Transform.Grid.Y); float newDistance = Vector2.Distance(soldier, monster); if (newDistance < testDistance) { testTarget = unit.Transform.Grid; testDistance = newDistance; } } core.TestMonster.GetComponent <Component.PathFinder>().Goal = testTarget; testDistance = 7000; core.TurnManager.EndTurn(); } } if (ks.IsKeyDown(Keys.A)) { /*foreach (var unit in core.Swarm) * { * unit.X = 200; * unit.Y = 200; * }*/ core.TestMonster.X = 12; core.TestMonster.Y = 4; } if (ks.IsKeyUp(Keys.O) && lastKeyboardState.IsKeyDown(Keys.O)) { try { EntityManager.GetEntities <Door>()[0].Toggle(); } catch { } } if (ks.IsKeyUp(Keys.P) && lastKeyboardState.IsKeyDown(Keys.P)) { try { var pos = core.GroupManager.Groups[1].Entities[0].Transform.World.Position; var enemy = new SmallEnemy(ref core.Swarm); enemy.Transform.World.Position = pos + new Vector2(0, Grid.TileSize * 3); core.Swarm.Add(enemy); } catch { } } if (ks.IsKeyDown(Keys.S) || ks.IsKeyDown(Keys.R)) { foreach (var soldier in core.Squad) { if (soldier.Selected == true && soldier.Fired == false) { bool enoughActionPoints = true; int cost = 0; string type = ""; if (ks.IsKeyDown(Keys.S)) { cost = bulletCost; type = "bullet"; } else if (ks.IsKeyDown(Keys.R)) { cost = rocketCost; type = "Rocket"; } if (soldier.AP >= cost) { core.Volley.Add(new Shot(soldier.GetComponent <Component.Stat>(), type)); soldier.AP -= cost; soldier.Fired = true; } else { enoughActionPoints = false; } if (enoughActionPoints == true) { foreach (var shot in core.Volley) { if (shot.select == false) { shot.select = true; shot.X = soldier.X; shot.Y = soldier.Y; //shot.Transform.World.Position += soldier.Transform.World.Origin; //shot.Transform.World.X += Grid.TileSize / 2; //shot.Transform.World.Y += Grid.TileSize / 2; } if (shot.direction == Vector2.Zero) { double directionX = Math.Cos(soldier.Transform.World.Rotation); double directionY = Math.Sin(soldier.Transform.World.Rotation); shot.direction = new Vector2((float)directionX, (float)directionY); shot.Transform.World.Rotation = soldier.Transform.World.Rotation; Vector2 yo = soldier.Transform.World.Position; shot.Stat.Remember = yo; } } } } } } if (ks.IsKeyDown(Keys.C)) { foreach (var soldier in core.Squad) { if (soldier.Selected == true && soldier.Fired == false) { Point checker = Point.Zero; double directionX = Math.Cos(soldier.GetComponent <Component.Transform>().World.Rotation); double directionY = Math.Sin(soldier.GetComponent <Component.Transform>().World.Rotation); Vector2 direction = new Vector2((int)directionX, (int)directionY); int range = 120; int current = 0; bool hit = false; checker = new Point((int)soldier.Transform.World.Origin.X, (int)soldier.Transform.World.Origin.Y); do { checker.X += (int)direction.X * checkerSpeed; checker.Y += (int)direction.Y * checkerSpeed; foreach (var creature in core.Swarm) { if (creature.GetComponent <Component.Collision>().Rectangle.Contains(checker)) { hit = true; } } if (core.TestMonster.GetComponent <Component.Collision>().Rectangle.Contains(checker)) { } current++; } while (hit == false && current < range); current = 0; if (soldier.Selected == true && soldier.Fired == false && hit == true) { core.Volley.Add(new Shot(soldier.GetComponent <Component.Stat>(), "Bullet")); soldier.Fired = true; foreach (var shot in core.Volley) { if (shot.select == false) { shot.select = true; shot.X = soldier.X; shot.Y = soldier.Y; //shot.Transform.World.X += Grid.TileSize / 2; //shot.Transform.World.Y += Grid.TileSize / 2; } if (shot.direction == Vector2.Zero) { shot.direction = new Vector2((float)directionX, (float)directionY); shot.Transform.World.Rotation = soldier.Transform.World.Rotation; } } } hit = false; } } } lastKeyboardState = ks; }