/* * Loads the specified level */ public void LoadLevel(ContentFactory factory, GameUnitController unit_controller, ItemController item_controller, int level_num) { CurLevel = factory.loadLevel(level_num); item_controller.Reset(); unit_controller.Reset(); unit_controller.SetLevel(CurLevel); }
/* * Reloads the current level */ public void ResetLevel(ContentFactory factory, GameUnitController unit_controller, ItemController item_controller) { LoadLevel(factory, unit_controller, item_controller, CurLevelNum); }
/* * Process item pickups */ public void ProcessItems(Player player, ItemController item_controller) { int x_indexp = (int)MathHelper.Clamp((player.Position.X / CELL_SIZE), 0, itemGrid.GetLength(1) - 1); int y_indexp = (int)MathHelper.Clamp((player.Position.Y / CELL_SIZE), 0, itemGrid.GetLength(0) - 1); List<Point> adjacent = getAdjacent(new Point(x_indexp, y_indexp)); foreach (Point loc in adjacent) { if (itemGrid[loc.Y, loc.X] != null) { foreach (Item it in itemGrid[loc.Y, loc.X]) { if (CheckItemCollision(player, it)) { item_controller.RemoveItem(it); } } } } }
/* * Calculates and processes all collisions that occur, * using the collision cell optimization structure */ public void Update(List<GameUnit> units, Player player, Level level, ItemController item_controller) { ConstructCollisionGrids(units, item_controller.Items, player, level); foreach (GameUnit unit in units) { ProcessCollisions(unit, level.Map); } if (player != null) { ProcessCollisions(player, level.Map); ProcessItems(player, item_controller); } }
/// <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; }