/* * Update all units */ public void Update(Level level, InputController input_controller) { ConstructCombatGrid(level); //Pathfinder.findPath(level.Map, Player.Front, Player.Front, PLAYER_PATHFIND_FIELD_SIZE, true); //playerLocationField = Pathfinder.pointLocMap; //lostUnits.Clear(); // Handle player logic bool playerFrontBlocked = false; if (Player != null) { playerFrontBlocked = level.Map.rayCastHasObstacle(Player.Position, Player.Front, Map.TILE_SIZE / 3); CheckPlayerInput(input_controller); moveUnit(Player); UpdatePlayer(); } // Handle lost units /* if (lostUnits.Count != 0) { GameUnit captain = lostUnits.First(); captain.Target = Player.Position; //findTarget(captain, Player.Position, level.Map, 100); foreach (GameUnit unit in lostUnits) { if (unit != captain) { unit.Lost = true; unit.Target = captain.Position; unit.NextMove = unit.Target; } } }*/ // Execute moves and actions foreach (GameUnit unit in Units) { setNextMove(unit, level, playerFrontBlocked); // Set next moves setVelocity(unit); moveUnit(unit); ProcessCombat(unit); UpdateUnit(unit, level); } // Convert units foreach (GameUnit unit in ConvertedUnits) { Convert(unit); } ConvertedUnits.Clear(); // Dispose of dead units foreach (GameUnit unit in DeadUnits) { if (unit.Type == UnitType.PLAYER) { Player.Exists = false; Player = null; } else Units.Remove(unit); } DeadUnits.Clear(); }
/* * Process player input and apply to player object */ private void CheckPlayerInput(InputController input_controller) { Vector2 vel = Player.Vel; if (input_controller.Left) { vel.X -= Player.Accel; } if (input_controller.Right) { vel.X += Player.Accel; } if (input_controller.Up) { vel.Y -= Player.Accel; } if (input_controller.Down) { vel.Y += Player.Accel; } // Clamp values to max speeds if (vel.Length() > Player.Speed) { vel.Normalize(); vel *= Player.Speed; } Player.Vel = vel; if (input_controller.Converting) { PlayerInfect(); } else { Player.Infecting = null; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { if (firstLoop) factory.LoadAllContent(); canvas.Initialize(this); // Game starts at the main menu game_state = GameState.MAIN_MENU; // Initialize controllers input_controller = new InputController(); collision_controller = new CollisionController(); level_controller = new LevelController(); unit_controller = new GameUnitController(factory); item_controller = new ItemController(); // TEST HUD_display = factory.createHUD(unit_controller.Player); level_controller.NextLevel(factory, unit_controller, item_controller); unit_controller.SetLevel(level_controller.CurLevel); bool test = level_controller.CurLevel.Map.rayCastHasObstacle( new Vector2(0*Map.TILE_SIZE, 0*Map.TILE_SIZE), new Vector2(20*Map.TILE_SIZE, 11*Map.TILE_SIZE), Map.TILE_SIZE); System.Diagnostics.Debug.WriteLine(test); base.Initialize(); firstLoop = false; }