protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); EntityManager.Update(gameTime, currentGameState); switch (currentGameState) { case GameState.Ingame: break; case GameState.LevelEditing: Vector2 mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); if (InputState.mouseLeftClick.Evaluate()) { if (tileButtonClickable.isWithinRectangle(mousePosition)) { foreach (DrawableComponent drawable in sceneryToolSprites) drawable.Visible = false; foreach (DrawableComponent drawable in tileToolSprites) drawable.Visible = true; foreach (DrawableComponent drawable in objectiveToolSprites) drawable.Visible = false; currentToolState = ToolState.Tile; tileButtonSprite.Color = Color.White; objectiveButtonSprite.Color = new Color(100, 100, 100); sceneryButtonSprite.Color = new Color(100, 100, 100); } if (sceneryButtonClickable.isWithinRectangle(mousePosition)) { foreach (DrawableComponent drawable in sceneryToolSprites) drawable.Visible = true; foreach (DrawableComponent drawable in tileToolSprites) drawable.Visible = false; foreach (DrawableComponent drawable in objectiveToolSprites) drawable.Visible = false; currentToolState = ToolState.Scenery; tileButtonSprite.Color = new Color(100, 100, 100); objectiveButtonSprite.Color = new Color(100, 100, 100); sceneryButtonSprite.Color = Color.White; } if (objectiveButtonClickable.isWithinRectangle(mousePosition)) { foreach (DrawableComponent drawable in sceneryToolSprites) drawable.Visible = false; foreach (DrawableComponent drawable in tileToolSprites) drawable.Visible = false; foreach (DrawableComponent drawable in objectiveToolSprites) drawable.Visible = true; currentToolState = ToolState.Objectives; tileButtonSprite.Color = new Color(100, 100, 100); objectiveButtonSprite.Color = Color.White; sceneryButtonSprite.Color = new Color(100, 100, 100); } switch (currentToolState) { case ToolState.Tile: if (floorRadioClickable.isWithinRectangle(mousePosition)) { currentTileType = TileType.Floor; floorRadioSprite.Color = Color.Yellow; windowRadioSprite.Color = Color.White; wallRadioSprite.Color = Color.White; wallPaperRadioSprite.Color = Color.White; placingTileSprite.setCurrentFrameX(2); } if (wallRadioClickable.isWithinRectangle(mousePosition)) { currentTileType = TileType.Wall; floorRadioSprite.Color = Color.White; windowRadioSprite.Color = Color.White; wallRadioSprite.Color = Color.Yellow; wallPaperRadioSprite.Color = Color.White; placingTileSprite.setCurrentFrameX(1); } if (wallPaperRadioClickable.isWithinRectangle(mousePosition)) { currentTileType = TileType.Wallpaper; floorRadioSprite.Color = Color.White; windowRadioSprite.Color = Color.White; wallRadioSprite.Color = Color.White; wallPaperRadioSprite.Color = Color.Yellow; placingTileSprite.setCurrentFrameX(4); } if (windowRadioClickable.isWithinRectangle(mousePosition)) { currentTileType = TileType.Glass; floorRadioSprite.Color = Color.White; windowRadioSprite.Color = Color.Yellow; wallRadioSprite.Color = Color.White; wallPaperRadioSprite.Color = Color.White; placingTileSprite.setCurrentFrameX(3); } if (!toolbarClickable.isWithinRectangle(mousePosition)) { Entity tile = new Entity(tileLayer, GameState.LevelEditing); SpriteSheetComponent tileSprite = new SpriteSheetComponent(new Rectangle((int)placingTileSprite.Destination.X, (int)placingTileSprite.Destination.Y, 50, 50), tileSpriteSheet); tile.AddComponent(tileSprite); switch (currentTileType) { case TileType.Floor: tileSprite.setCurrentFrameX(2); break; case TileType.Wall: tileSprite.setCurrentFrameX(1); break; case TileType.Grass: tileSprite.setCurrentFrameX(0); break; case TileType.Wallpaper: tileSprite.setCurrentFrameX(4); break; case TileType.Glass: tileSprite.setCurrentFrameX(3); break; } TileComponent tileTile = new TileComponent(currentTileType); tile.AddComponent(tileTile); tiles.Add(tile); EntityManager.AddEntity(tile); } break; case ToolState.Scenery: if (upLayerClickable.isWithinRectangle(mousePosition)) { if (currentLayer < maxEditableLayer - 1) { currentLayer++; layerNumberText.Text = "Layer: " + currentLayer.ToString(); UpdateLayerColor(); } } else if (downLayerClickable.isWithinRectangle(mousePosition)) { if (currentLayer > 0) { currentLayer--; layerNumberText.Text = "Layer: " + currentLayer.ToString(); UpdateLayerColor(); } } else if (upSceneryClickable.isWithinRectangle(mousePosition)) { if (currentSceneryOption < sceneryOptions.Count - 1) { currentSceneryOption++; sceneryPreviewSprite.Texture = sceneryOptions[currentSceneryOption]; placingScenerySprite.Texture = sceneryOptions[currentSceneryOption]; placingScenerySprite.SpriteWidth = sceneryOptions[currentSceneryOption].Width; placingScenerySprite.SpriteHeight = sceneryOptions[currentSceneryOption].Height; } } else if (downSceneryClickable.isWithinRectangle(mousePosition)) { if (currentSceneryOption > 0) { currentSceneryOption--; sceneryPreviewSprite.Texture = sceneryOptions[currentSceneryOption]; placingScenerySprite.Texture = sceneryOptions[currentSceneryOption]; placingScenerySprite.SpriteWidth = sceneryOptions[currentSceneryOption].Width; placingScenerySprite.SpriteHeight = sceneryOptions[currentSceneryOption].Height; } } else if (!toolbarClickable.isWithinRectangle(mousePosition)) { //We arent clicking wihtin the toolbar Entity scenery = new Entity(currentLayer, GameState.LevelEditing); SpriteComponent scenerySprite = new SpriteComponent(new Rectangle( (int)mousePosition.X + (int)Camera.Pos.X, (int)mousePosition.Y + (int)Camera.Pos.Y, sceneryOptions[currentSceneryOption].Width, sceneryOptions[currentSceneryOption].Height), sceneryOptions[currentSceneryOption]); scenery.AddComponent(scenerySprite); layersOfScenery[currentLayer].Add(scenerySprite); EntityManager.AddEntity(scenery); UpdateLayerColor(); } break; case ToolState.Objectives: if (playerSpawnRadioClickable.isWithinRectangle(mousePosition)) { visitorSpawnRadioSprite.Color = Color.White; playerSpawnRadioSprite.Color = Color.Yellow; objectiveToolState = ObjectiveToolState.PlayerSpawn; } else if (visitorSpawnRadioClickable.isWithinRectangle(mousePosition)) { objectiveToolState = ObjectiveToolState.VisitorSpawn; visitorSpawnRadioSprite.Color = Color.Yellow; playerSpawnRadioSprite.Color = Color.White; } else if (!toolbarClickable.isWithinRectangle(mousePosition)) { //If you are not pressing the toolbar if (objectiveToolState == ObjectiveToolState.PlayerSpawn) { playerSpawnText.Destination = new Vector2(mousePosition.X + Camera.Pos.X, mousePosition.Y + Camera.Pos.Y); } else if (objectiveToolState == ObjectiveToolState.VisitorSpawn) { visitorSpawnText.Destination = new Vector2(mousePosition.X + Camera.Pos.X, mousePosition.Y + Camera.Pos.Y); } } break; default: break; } } if (InputState.upHold.Evaluate() && InputState.downHold.Evaluate()) { } if (InputState.leftHold.Evaluate() && InputState.rightHold.Evaluate()) { } if (InputState.upClick.Evaluate()) { Camera.Move(new Vector2(0, -10)); } if (InputState.rightClick.Evaluate()) { Camera.Move(new Vector2(10, 0)); } if (InputState.downClick.Evaluate()) { Camera.Move(new Vector2(0, 10)); } if (InputState.leftClick.Evaluate()) { Camera.Move(new Vector2(-10, 0)); } //Moving the current selection switch (currentToolState) { case ToolState.Tile: placingTileSprite.Destination = new Vector2((mousePosition.X + Camera.Pos.X) - ((mousePosition.X + Camera.Pos.X) % 50f), (mousePosition.Y + Camera.Pos.Y) - ((mousePosition.Y + Camera.Pos.Y) % 50)); break; case ToolState.Scenery: placingScenerySprite.Destination = new Vector2(mousePosition.X + Camera.Pos.X, mousePosition.Y + Camera.Pos.Y); break; case ToolState.Objectives: break; } break; } base.Update(gameTime); }
static Entity PopulateTile(uint color, int x, int y, int width, int height, int layer) { Entity tileEntity = new Entity(layer + 2, GameState.Ingame); SpriteComponent sprite; TileComponent tile; switch (color) { case LevelKey.Grass: sprite = new SpriteComponent(new Rectangle(x * width, y * height, width, height), Game1.grassTexture); tile = new TileComponent(TileType.Grass); break; case LevelKey.Floor: sprite = new SpriteComponent(new Rectangle(x * width, y * height, width, height), Game1.floorTexture); tile = new TileComponent(TileType.Floor); break; case LevelKey.Wall: sprite = new SpriteComponent(new Rectangle(x * width, y * height, width, height), Game1.wallTexture); tile = new TileComponent(TileType.Wall); break; case LevelKey.Wallpaper: sprite = new SpriteComponent(new Rectangle(x * width, y * height, width, height), Game1.wallpaperTexture); tile = new TileComponent(TileType.Wallpaper); break; case LevelKey.Glass: sprite = new SpriteComponent(new Rectangle(x * width, y * height, width, height), Game1.glassTexture); tile = new TileComponent(TileType.Glass); break; default: sprite = new SpriteComponent(new Rectangle(x * width, y * height, width, height), Game1.grassTexture); tile = new TileComponent(TileType.Glass); break; } tileEntity.AddComponent(sprite); tileEntity.AddComponent(tile); return tileEntity; }