예제 #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CadetBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, myBackground.translation(xPos + desiredBBWidth / 2, yPos + desiredBBHeight / 2));

            //draws backgrounds
            //myBackground.Draw(spriteBatch);
            //spriteBatch.Draw(background, new Rectangle(-lvlX, 0, backgroundWidth, backgroundWidth), Color.White);
            //spriteBatch.Draw(background, new Rectangle(-lvlX, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
            //spriteBatch.Draw(background, destinationRectangle: new Rectangle(GraphicsDevice.Viewport.Width - lvlX, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), color: Color.White, effects: SpriteEffects.FlipHorizontally);
            //spriteBatch.Draw(background, new Rectangle(2 * GraphicsDevice.Viewport.Width - lvlX, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);

            //draw all the tiles in the list of tiles (the current map)
            foreach (var item in tiles)
            {
                spriteBatch.Draw(item.texture, item.bounds, Color.White);
                if (item is LeapZoneTile)
                {
                    LeapZoneTile thisTile = (LeapZoneTile)item;
                    spriteBatch.DrawString(font, thisTile.id.ToString() + "; " + thisTile.linkedZonesString(), new Vector2(item.bounds.X, item.bounds.Y), Color.Purple);
                }
            }


            Point gridCoord = getGridCoord(Mouse.GetState().X + lvlX, Mouse.GetState().Y + lvlY);

            //draw hovering tile at the cursor
            if (currentType == ObjectType.Player)
            {
                spriteBatch.Draw(tileDict[currentType], new Rectangle(getGridCoord(Mouse.GetState().X + lvlX, Mouse.GetState().Y - GRID_SIZE + lvlY), new Point(GRID_SIZE, GRID_SIZE * 2)), Color.White);
            }

            else if (currentType == ObjectType.Enemy)
            {
                spriteBatch.Draw(tileDict[currentType], new Rectangle(gridCoord, new Point((int)(GRID_SIZE * 1.5), (int)(GRID_SIZE * 1.5))), Color.White);
            }

            else if (currentType == ObjectType.Boss)
            {
                spriteBatch.Draw(tileDict[currentType], new Rectangle(gridCoord, new Point(GRID_SIZE * 4, (int)(GRID_SIZE * 1.5))), Color.White);
            }

            else if (currentType == ObjectType.BossLeapZone)
            {
                spriteBatch.Draw(tileDict[currentType], new Rectangle(gridCoord, new Point(GRID_SIZE * 4, GRID_SIZE)), Color.White);
            }

            else if (currentType == ObjectType.Link)
            {
                spriteBatch.Draw(tileDict[currentType], new Rectangle(gridCoord, new Point(GRID_SIZE, GRID_SIZE)), Color.White);
            }

            else if (currentType == ObjectType.Rock)
            {
                spriteBatch.Draw(tileDict[currentType], new Rectangle(gridCoord, new Point(GRID_SIZE * 2, GRID_SIZE)), Color.White);
            }

            else if (currentType != ObjectType.Delete)
            {
                spriteBatch.Draw(tileDict[currentType], new Rectangle(gridCoord, new Point(GRID_SIZE, GRID_SIZE)), Color.White);
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }
예제 #2
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)
        {
            //define keyboard and mouse states
            previousKbState = kbState;
            kbState         = Keyboard.GetState();
            previousMState  = mState;
            mState          = Mouse.GetState();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            //Get directiona vector based on keyboard input
            if (kbState.IsKeyDown(Keys.W))
            {
                yPos -= camSpeed;
                lvlY -= camSpeed;
            }

            else if (kbState.IsKeyDown(Keys.S))
            {
                yPos += camSpeed;
                lvlY += camSpeed;
            }

            if (kbState.IsKeyDown(Keys.A))
            {
                xPos -= camSpeed;
                lvlX -= camSpeed;
            }

            else if (kbState.IsKeyDown(Keys.D))
            {
                xPos += camSpeed;
                lvlX += camSpeed;
            }

            //scrolling background
            // The time since Update was called last.
            //float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            // TODO: Add your game logic here.
            //myBackground.Update(elapsed * 100);

            //change currently selected object type with up/down arrow keys
            //list order loops in order of coded case sequence
            switch (currentType)
            {
            case ObjectType.Delete:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.Rock;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.TopBrick;
                }
                break;

            case ObjectType.TopBrick:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.Delete;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.PlainBrick;
                }
                break;

            case ObjectType.PlainBrick:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.TopBrick;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.Player;
                }
                break;

            case ObjectType.Player:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.PlainBrick;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.Enemy;
                }
                break;

            case ObjectType.Enemy:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.Player;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.Boss;
                }
                break;

            case ObjectType.Boss:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.Enemy;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.BossLeapZone;
                }
                break;

            case ObjectType.BossLeapZone:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.Boss;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.Link;
                }
                break;

            case ObjectType.Link:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.BossLeapZone;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.Rock;
                }
                break;

            case ObjectType.Rock:
                if (SingleKeyPress(Keys.Up))
                {
                    currentType = ObjectType.Link;
                }
                if (SingleKeyPress(Keys.Down))
                {
                    currentType = ObjectType.Delete;
                }
                break;

            default:
                currentType = ObjectType.Delete;
                break;
            }

            //on single mouse click, add a new tile object to the selected location
            //if there is a tile already there, delete it before adding the new one
            if (SingleMouseClick())
            {
                //current coordinates of mouse click
                Point currentCoord = getGridCoord(Mouse.GetState().X + lvlX, Mouse.GetState().Y + lvlY);

                if (!linkState)
                {
                    //set to link state when link is selected and is hovering over leap zone tile
                    if (currentType == ObjectType.Link)
                    {
                        foreach (LeapZoneTile tile in tiles.OfType <LeapZoneTile>())
                        {
                            Point checkPoint = getGridCoord(tile.bounds.X, tile.bounds.Y);
                            if (currentCoord == checkPoint)
                            {
                                linkState = true;
                                linkTile  = tile;
                                break;
                            }
                        }
                    }

                    //remove any tile already in that space
                    foreach (Tile tile in tiles)
                    {
                        Point checkPoint = getGridCoord(tile.bounds.X, tile.bounds.Y);
                        if (currentCoord == checkPoint && !linkState)
                        {
                            tiles.Remove(tile);
                            break;
                        }
                    }


                    //add object to list of tiles
                    if (currentType == ObjectType.Player)
                    {
                        tiles.Add(new Tile(new Rectangle(new Point(currentCoord.X, currentCoord.Y - GRID_SIZE), new Point(GRID_SIZE, GRID_SIZE * 2)), tileDict[currentType], currentType));
                    }

                    else if (currentType == ObjectType.Enemy)
                    {
                        tiles.Add(new Tile(new Rectangle(new Point(currentCoord.X, currentCoord.Y - GRID_SIZE / 2), new Point((int)(GRID_SIZE * 1.5), (int)(GRID_SIZE * 1.5))), tileDict[currentType], currentType));
                    }

                    else if (currentType == ObjectType.Boss)
                    {
                        tiles.Add(new Tile(new Rectangle(new Point(currentCoord.X, currentCoord.Y - GRID_SIZE / 2), new Point(GRID_SIZE * 4, (int)(GRID_SIZE * 1.5))), tileDict[currentType], currentType));
                    }

                    else if (currentType == ObjectType.Rock)
                    {
                        tiles.Add(new Tile(new Rectangle(new Point(currentCoord.X, currentCoord.Y), new Point(GRID_SIZE * 2, GRID_SIZE)), tileDict[currentType], currentType));
                    }

                    //add a leap zone tile
                    else if (currentType == ObjectType.BossLeapZone)
                    {
                        currentID++;
                        tiles.Add(new LeapZoneTile(new Rectangle(new Point(currentCoord.X, currentCoord.Y), new Point(GRID_SIZE * 4, GRID_SIZE)), tileDict[currentType], currentType, currentID));
                    }

                    //add any other tiles if anything but delete
                    else if (currentType != ObjectType.Delete && currentType != ObjectType.Link)
                    {
                        tiles.Add(new Tile(new Rectangle(currentCoord, new Point(GRID_SIZE, GRID_SIZE)), tileDict[currentType], currentType));
                    }
                }
                else
                {
                    //if in link state, link the two tiles
                    foreach (LeapZoneTile tile in tiles.OfType <LeapZoneTile>())
                    {
                        Point checkPoint = getGridCoord(tile.bounds.X, tile.bounds.Y);
                        if (currentCoord == checkPoint)
                        {
                            ((LeapZoneTile)(tiles.Find(t => t == linkTile))).linkedZones.Add(tile.id);
                            tile.linkedZones.Add(linkTile.id);
                            linkTile  = null;
                            linkState = false;
                            break;
                        }
                    }
                }
            }

            //saves current list of Tiles into JungleScape's Content folder
            if (SingleKeyPress(Keys.Enter))
            {
                StreamWriter joutput = new StreamWriter("../../../../../JungleScape/Content/level.json");
                joutput.WriteLine(JsonConvert.SerializeObject(tiles, settings));
                joutput.Close();
            }

            base.Update(gameTime);
        }