Beispiel #1
0
 public void setGuiControls(IMovableItem movableItem)
 {
     if (movableItem is BackgroundItemStruct)
     {
         BackgroundItemStruct backgroundItemStruct = (BackgroundItemStruct)movableItem;
         backgroundRotationText.Text = backgroundItemStruct.rotation.ToString();
         backgroundScaleField.Text   = backgroundItemStruct.scale.ToString();
         backgroundTextureField.Text = backgroundItemStruct.texturePath;
     }
     if (movableItem is GameItem)
     {
         GameItem item = (GameItem)movableItem;
         itemPolygonType.SelectedItem = item.polygonType.ToString();
         itemTextureBox.Text          = item.name;
         itemWeightBox.Text           = item.weight.ToString();
         itemRadiusText.Text          = item.polygonType == PhysicsPolygonType.Circle ? item.radius.ToString() :
                                        item.sideLengths.X.ToString() + "," + item.sideLengths.Y.ToString();
         itemRotationTextBox.Text = item.rotation.ToString();
         itemDepthSlider.Value    = (int)item.startdepth;
         itemWidthSlider.Value    = (int)item.width;
         itemImmovableBox.Checked = item.immovable;
     }
     if (movableItem is SpawnPoint)
     {
         SpawnPoint spawn = (SpawnPoint)movableItem;
         enemyCountBox.Text       = spawn.count.ToString();
         enemyTypeText.Text       = spawn.type.ToString();
         enemyLevelTextfield.Text = spawn.weight.ToString();
     }
 }
        private void backgroundSpawnButton_Click(object sender, EventArgs e)
        {
            BackgroundItemStruct str = new BackgroundItemStruct();

            str.texturePath = backgroundTextureLabel.Text;
            str.location    = gameref.currentLocation;
            str.rotation    = float.Parse(backgroundRotationText.Text);
            str.scale       = float.Parse(backgroundScaleField.Text);
            gameref.CurrentLevel.backgroundItems.Add(str);
        }
Beispiel #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            switch (currentState)
            {
                #region Leveleditor
            case Enums.State.Leveleditor:
                Vector2 currentLocation = new Vector2(Mouse.GetState().X + offset.X, resolution.ScreenHeight - (Mouse.GetState().Y + offset.Y));
                #region Moving gameitem
                if (ButtonState.Pressed == Mouse.GetState().LeftButton&&
                    ButtonState.Pressed != previousMouseState.LeftButton &&
                    Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
                {
                    this.currentLocation = currentLocation;
                    control.updateCurrentPositionLabel();
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                    {
                        movingItem = CurrentLevel.getGameItemAtLocation(currentLocation.X, currentLocation.Y);
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
                    {
                        movingSpawn = CurrentLevel.getSpawnAtLocation(currentLocation.X, currentLocation.Y, this);
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                    {
                        BackgroundItemStruct?str = CurrentLevel.getBackgroundItemAtLocation(currentLocation.X, currentLocation.Y, this);
                        if (str.HasValue)
                        {
                            movingBackgroundItem = str.Value;
                        }
                    }
                }
                if (ButtonState.Pressed == Mouse.GetState().LeftButton&&
                    Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
                {
                    if (movingItem != null)
                    {
                        movingItem.loc = currentLocation;
                    }
                    if (movingSpawn != null)
                    {
                        movingSpawn.loc = currentLocation;
                    }
                    movingBackgroundItem.location = currentLocation;
                }
                if (ButtonState.Pressed != Mouse.GetState().LeftButton&&
                    ButtonState.Pressed == previousMouseState.LeftButton &&
                    Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
                {
                    movingItem  = null;
                    movingSpawn = null;
                }
                #endregion
                #region Remove level item
                if (ButtonState.Pressed == Mouse.GetState().RightButton&&
                    ButtonState.Pressed != previousMouseState.RightButton &&
                    Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                    {
                        GameItem item = CurrentLevel.getGameItemAtLocation(currentLocation.X, currentLocation.Y);
                        if (item != null)
                        {
                            CurrentLevel.items.Remove(item);
                            control.setGuiControls(item);
                        }
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
                    {
                        SpawnPoint spawn = CurrentLevel.getSpawnAtLocation(currentLocation.X, currentLocation.Y, this);
                        if (spawn != null)
                        {
                            CurrentLevel.spawns.Remove(spawn);
                            control.setGuiControls(spawn);
                        }
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
                    {
                        BackgroundItemStruct?str = CurrentLevel.getBackgroundItemAtLocation(currentLocation.X, currentLocation.Y, this);
                        if (str.HasValue)
                        {
                            CurrentLevel.backgroundItems.Remove(str.Value);
                            control.setGuiControls(str.Value);
                        }
                    }
                }
                #endregion
                break;

                #endregion
                #region Worldeditor
            case Enums.State.Worldeditor:
                //if clicked on a level, choose that, otherwise make a new one
                Vector2 point = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                int     indexOfClosestLevel = -1;
                float   distance            = float.MaxValue;
                foreach (Level level in levels)
                {
                    float newdistance = Vector2.Distance(level.loc, point);
                    if (newdistance < distance)
                    {
                        distance            = newdistance;
                        indexOfClosestLevel = level.number;
                    }
                }
                if (ButtonState.Pressed == Mouse.GetState().LeftButton&&
                    ButtonState.Pressed != previousMouseState.LeftButton &&
                    Mouse.GetState().X > 0 && Mouse.GetState().Y > 0)
                {
                    if (distance < DISTANCE_FOR_SELECTION)
                    {
                        control.setLevelInfo(levels[indexOfClosestLevel].loc.X, levels[indexOfClosestLevel].loc.Y,
                                             levels[indexOfClosestLevel].adjacent, levels[indexOfClosestLevel].prereq,
                                             levels[indexOfClosestLevel].name, levels[indexOfClosestLevel].number,
                                             levels[indexOfClosestLevel].autoProgress);
                        if (Keyboard.GetState().IsKeyDown(Keys.LeftControl))
                        {
                            levels.RemoveAt(indexOfClosestLevel);
                            foreach (Level level in levels)
                            {
                                if (level.number >= indexOfClosestLevel)
                                {
                                    --level.number;
                                }
                                for (int i = 0; i < level.adjacent.Count; i++)
                                {
                                    if (level.adjacent[i] == indexOfClosestLevel)
                                    {
                                        level.adjacent.RemoveAt(i);
                                    }
                                }
                            }
                            selectedLevelIndex = 0;
                        }
                        else if (selectedLevelIndex == indexOfClosestLevel)
                        {
                            switchState();
                        }
                        else
                        {
                            selectedLevelIndex = indexOfClosestLevel;
                        }
                    }
                    else
                    {
                        addLevel();
                    }
                }
                break;
                #endregion
            }
            previousMouseState = Mouse.GetState();
            base.Update(gameTime);
        }
 public void setGuiControls(BackgroundItemStruct backgroundItemStruct)
 {
     backgroundRotationText.Text = backgroundItemStruct.rotation.ToString();
     backgroundScaleField.Text   = backgroundItemStruct.scale.ToString();
     backgroundTextureField.Text = backgroundItemStruct.texturePath;
 }