public void Initialize(OpenTK.GameWindow window) { Window = window; window.ClientSize = new Size(15 * TILE_SIZE, 7 * TILE_SIZE); TextureManager.Instance.UseNearestFiltering = true; hero = new PlayerCharacter(heroSheet); currentMap = new Map(startingMap,hero); projectiles = new List<Bullet>(); }
public void Update(float dt) { currentMap = currentMap.ResolveDoors(hero); hero.Update(dt); cursorTile = new Point(InputManager.Instance.MousePosition.X/TILE_SIZE, InputManager.Instance.MousePosition.Y / TILE_SIZE); if (InputManager.Instance.MousePosition.X / TILE_SIZE < currentMap[0].Length ) { if (InputManager.Instance.MousePressed(OpenTK.Input.MouseButton.Left) || InputManager.Instance.KeyPressed(OpenTK.Input.Key.M)) { if (currentMap[cursorTile.Y][cursorTile.X].Walkable) { hero.SetTargetTile(cursorTile); } } } if (InputManager.Instance.KeyPressed(OpenTK.Input.Key.Space)) { Console.WriteLine("Fire!"); PointF velocity = new PointF(0.0f, 0.0f); if (hero.currentSprite == "up") { velocity.Y -= 100.0f; } else if (hero.currentSprite == "down") { velocity.Y += 100.0f; } if (hero.currentSprite == "left") { velocity.X -= 100.0f; } else if (hero.currentSprite == "right") { velocity.X += 100.0f; } Console.WriteLine("Direction shot: " + hero.currentSprite); Console.WriteLine("Added bullet, velocity: " + velocity); projectiles.Add(new Bullet(hero.Center, velocity)); } for (int i = projectiles.Count - 1; i >= 0; i--) { projectiles[i].Update(dt); } currentMap.Update(dt, hero,projectiles); }
public Map ResolveDoors(PlayerCharacter hero) { Map result = this; for (int row = 0; row < tileMap.Length; row++) { for (int col = 0; col < tileMap[row].Length; col++) { if (tileMap[row][col].IsDoor) { //get doors bouding rectangle Rectangle doorRect = new Rectangle(col * 30, row * 30, 30, 30); //get a small rectangle in center of the player Rectangle playerCenter = new Rectangle((int)hero.Center.X - 2, (int)hero.Center.Y - 2, 4, 4); //look for an intersection Rectangle intersection = Intersections.Rect(doorRect, playerCenter); if (intersection.Width * intersection.Height > 0) { this.Destroy(); result = new Map(tileMap[row][col].DoorPath,hero); hero.Position.X = nextRoom[tileMap[row][col].DoorPath].X * Game.TILE_SIZE; hero.Position.Y = nextRoom[tileMap[row][col].DoorPath].Y * Game.TILE_SIZE; hero.SetTargetTile(new Point((int)hero.Position.X/Game.TILE_SIZE,(int)hero.Position.Y/Game.TILE_SIZE)); } } } } return result; }