示例#1
0
        public void LoadContent(List <Tuple <int, int, int> > wallProperties, List <Tuple <int, int> > spikePositions, Vector2 startingPosition, Vector2 endingPosition)
        {
            NUM_CELLS_WIDTH  = (int)Math.Ceiling((double)game.GraphicsDevice.Viewport.Width / (double)CELL_SIZE);
            NUM_CELLS_HEIGHT = (int)Math.Ceiling((double)game.GraphicsDevice.Viewport.Height / (double)CELL_SIZE);
            cells            = new Cell[NUM_CELLS_WIDTH, NUM_CELLS_HEIGHT];

            var cracked_wall_texture = game.Content.Load <Texture2D>("cracked_wall");
            var normal_wall_texture  = game.Content.Load <Texture2D>("wall");
            var spike_texture        = game.Content.Load <Texture2D>("spike");
            var exposedSFX           = game.Content.Load <SoundEffect>("spikeSFX");

            //Change upper to load textures once & pass to initializers

            for (int i = 0; i < wallProperties.Count(); i++)
            {
                Texture2D wall_texture;
                bool      isBombable = false;
                switch (wallProperties[i].Item3)
                {
                case 0:
                    wall_texture = normal_wall_texture;
                    break;

                case 1:
                    wall_texture = cracked_wall_texture;
                    isBombable   = true;
                    break;

                default:
                    wall_texture = normal_wall_texture;
                    break;
                }
                Wall wall = new Wall(game, wall_texture);
                wall.Initialize(new Vector2(wallProperties[i].Item1 * 50,
                                            wallProperties[i].Item2 * 50),
                                isBombable);
                walls.Add(wall);
                collidables.Add(wall);
            }
            for (int i = 0; i < spikePositions.Count(); i++)
            {
                Spike spike = new Spike(game, spike_texture, exposedSFX);
                spike.Initialize(new Vector2(spikePositions[i].Item1 * 50,
                                             spikePositions[i].Item2 * 50));
                spikes.Add(spike);
                collidables.Add(spike);
            }
            this.startingPosition = startingPosition;
            this.endingPosition   = endingPosition;

            for (int j = 0; j < NUM_CELLS_HEIGHT; j++)
            {
                for (int i = 0; i < NUM_CELLS_WIDTH; i++)
                {
                    cells[i, j] = new Cell(this, new BoundingRectangle(i * CELL_SIZE, j * CELL_SIZE, CELL_SIZE, CELL_SIZE));
                }
            }
        }
示例#2
0
 public void Initialize(List <Tuple <int, int> > wallPositions, List <Tuple <int, int> > spikePositions, Vector2 startingPosition)
 {
     for (int i = 0; i < wallPositions.Count(); i++)
     {
         Wall wall = new Wall(game);
         wall.Initialize(new Vector2(wallPositions[i].Item1 * 50,
                                     wallPositions[i].Item2 * 50),
                         false);
         walls.Add(wall);
     }
     for (int i = 0; i < spikePositions.Count(); i++)
     {
         Spike spike = new Spike(game);
         spike.Initialize(new Vector2(spikePositions[i].Item1 * 50,
                                      spikePositions[i].Item2 * 50));
         spikes.Add(spike);
     }
     this.startingPosition = startingPosition;
 }
示例#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 || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            updateable = new List <iUpdateable>();

            oldkeyboardState = keyboardState;
            keyboardState    = Keyboard.GetState();
            if (keyboardState.IsKeyDown(Keys.P) && !oldkeyboardState.IsKeyDown(Keys.P))
            {
                NextLevel();
            }
            if (keyboardState.IsKeyDown(Keys.Q) && !oldkeyboardState.IsKeyDown(Keys.Q))
            {
                PreviousLevel();
            }
            if (keyboardState.IsKeyDown(Keys.E) && !oldkeyboardState.IsKeyDown(Keys.E))
            {
                player.curPosition = current_maze.endingPosition;
            }
            if (keyboardState.IsKeyDown(Keys.S) && !oldkeyboardState.IsKeyDown(Keys.S))
            {
                player.curPosition = current_maze.startingPosition;
            }

            if (!win && !game_over)
            {
                if (player.Bounds.X > graphics.GraphicsDevice.Viewport.Width)
                {
                    NextLevel();
                    return;
                }

                current_maze = levels[current_level];

                // TODO: Add your update logic here
                updateable.Add(player);
                foreach (Spike spike in current_maze.spikes)
                {
                    updateable.Add(spike);
                }
                foreach (Cell cell in current_maze.cells)
                {
                    updateable.Add(cell);
                }
                foreach (iUpdateable obj in updateable)
                {
                    obj.Update(gameTime);
                }

                foreach (Cell cell in current_maze.getNearCells(player))
                {
                    foreach (iCollidable collidable in cell.collidables)
                    {
                        Wall  wall  = collidable as Wall;
                        Spike spike = collidable as Spike;
                        if (wall != null)
                        {
                            if (player.Bounds.CollidesWith(wall.Bounds) && !wall.destroyed)
                            {
                                float delta;
                                switch (player.state)
                                {
                                case State.East:
                                    delta = (player.Bounds.X + player.Bounds.Width) - wall.Bounds.X;
                                    player.curPosition.X = wall.Bounds.X - player.Bounds.Width - delta;
                                    break;

                                case State.North:
                                    delta = (wall.Bounds.Y + wall.Bounds.Height) - player.Bounds.Y;
                                    player.curPosition.Y = wall.Bounds.Y + wall.Bounds.Height + delta;
                                    break;

                                case State.West:
                                    delta = (wall.Bounds.X + wall.Bounds.Width) - player.Bounds.X;
                                    player.curPosition.X = wall.Bounds.X + wall.Bounds.Width + delta + 1;
                                    break;

                                case State.South:
                                    delta = (player.Bounds.Y + player.Bounds.Height) - wall.Bounds.Y;
                                    player.curPosition.Y = wall.Bounds.Y - player.Bounds.Height - delta;
                                    break;
                                }
                            }
                            if (player.bomb.Explosion.CollidesWith(wall.Bounds) && player.bomb.detonated && !wall.destroyed)
                            {
                                if (wall.isBombable)
                                {
                                    wall.Bounds.X = -50;
                                    wall.Bounds.Y = -50;
                                }
                            }
                        }
                        if (spike != null)
                        {
                            if (player.Bounds.CollidesWith(spike.Bounds) && spike.on)
                            {
                                player.ouchSFX.Play(1, 0, 0);
                                GameOverDeath();
                            }
                            if (player.bomb.Explosion.CollidesWith(spike.Bounds) && player.bomb.detonated && spike.on)
                            {
                                spike.destroyed = true;
                            }
                        }
                    }
                }
                foreach (Cell cell in current_maze.getNearCells(player.bomb))
                {
                    foreach (iCollidable collidable in cell.collidables)
                    {
                        Wall  wall  = collidable as Wall;
                        Spike spike = collidable as Spike;
                        if (wall != null)
                        {
                            if (player.bomb.Explosion.CollidesWith(wall.Bounds) && player.bomb.detonated && !wall.destroyed)
                            {
                                if (wall.isBombable)
                                {
                                    wall.Bounds.X = -50;
                                    wall.Bounds.Y = -50;
                                }
                            }
                        }
                        if (spike != null)
                        {
                            if (player.bomb.Explosion.CollidesWith(spike.Bounds) && player.bomb.detonated && spike.on)
                            {
                                spike.destroyed = true;
                            }
                        }
                    }
                }
                if (player.Bounds.CollidesWith(player.bomb.Explosion) && player.bomb.detonated)
                {
                    player.ouchBombSFX.Play(1, 0, 0);
                    GameOverDeath();
                }

                score--;

                base.Update(gameTime);
            }
        }
示例#4
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 || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            updateable = new List <iUpdateable>();

            if (viewState == ViewState.IDLE)
            {
                oldkeyboardState = keyboardState;
                keyboardState    = Keyboard.GetState();
                if (keyboardState.IsKeyDown(Keys.P) && !oldkeyboardState.IsKeyDown(Keys.P))
                {
                    NextLevel();
                }
                if (keyboardState.IsKeyDown(Keys.Q) && !oldkeyboardState.IsKeyDown(Keys.Q))
                {
                    PreviousLevel();
                }
                if (keyboardState.IsKeyDown(Keys.E) && !oldkeyboardState.IsKeyDown(Keys.E))
                {
                    player.curPosition = current_maze.endingPosition;
                }
                if (keyboardState.IsKeyDown(Keys.S) && !oldkeyboardState.IsKeyDown(Keys.S))
                {
                    player.curPosition = current_maze.startingPosition;
                }
                if (keyboardState.IsKeyDown(Keys.B) && !oldkeyboardState.IsKeyDown(Keys.B))
                {
                    if (current_level == 1)
                    {
                        player.curPosition = new Vector2(551, 451);
                    }
                    if (current_level == 2)
                    {
                        player.curPosition = new Vector2(951, 401);
                    }
                }

                if (!win && !game_over)
                {
                    if (player.Bounds.X > graphics.GraphicsDevice.Viewport.Width)
                    {
                        NextLevel();
                        return;
                    }

                    current_maze = levels[current_level];

                    // TODO: Add your update logic here
                    updateable.Add(player);
                    foreach (Spike spike in current_maze.spikes)
                    {
                        updateable.Add(spike);
                    }
                    foreach (Cell cell in current_maze.cells)
                    {
                        updateable.Add(cell);
                    }
                    foreach (iUpdateable obj in updateable)
                    {
                        obj.Update(gameTime);
                    }

                    foreach (Cell cell in current_maze.getNearCells(player))
                    {
                        foreach (iCollidable collidable in cell.collidables)
                        {
                            if (collidable is Wall wall)
                            {
                                if (player.Bounds.CollidesWith(wall.Bounds) && !wall.destroyed)
                                {
                                    float delta;
                                    switch (player.moving_state)
                                    {
                                    case MovingState.East:
                                        delta = (player.Bounds.X + player.Bounds.Width) - wall.Bounds.X;
                                        player.curPosition.X = wall.Bounds.X - player.Bounds.Width - delta;
                                        break;

                                    case MovingState.North:
                                        delta = (wall.Bounds.Y + wall.Bounds.Height) - player.Bounds.Y;
                                        player.curPosition.Y = wall.Bounds.Y + wall.Bounds.Height + delta;
                                        break;

                                    case MovingState.West:
                                        delta = (wall.Bounds.X + wall.Bounds.Width) - player.Bounds.X;
                                        player.curPosition.X = wall.Bounds.X + wall.Bounds.Width + delta + 1;
                                        break;

                                    case MovingState.South:
                                        delta = (player.Bounds.Y + player.Bounds.Height) - wall.Bounds.Y;
                                        player.curPosition.Y = wall.Bounds.Y - player.Bounds.Height - delta;
                                        break;
                                    }
                                }
                                if (player.bomb.Explosion.CollidesWith(wall.Bounds) && player.bomb.detonated && !wall.destroyed)
                                {
                                    if (wall.isBombable)
                                    {
                                        // Wall crumble apart particle system implemented here
                                        wallParticleSystem = newWallParticleSystem(graphics.GraphicsDevice, 100, particle, wall.Position());
                                        wall.Bounds.X      = -50;
                                        wall.Bounds.Y      = -50;
                                        score += 5000;
                                    }
                                }
                            }
                            if (collidable is Spike spike)
                            {
                                if (player.Bounds.CollidesWith(spike.Bounds) && spike.on)
                                {
                                    player.ouchSFX.Play(1, 0, 0);
                                    GameOverDeath();
                                }
                                if (player.bomb.Explosion.CollidesWith(spike.Bounds) && player.bomb.detonated && spike.on)
                                {
                                    spike.destroyed = true;
                                    score          += 2000;
                                }
                            }
                            if (collidable is Exit exit)
                            {
                                if (player.Bounds.CollidesWith(exit.Bounds))
                                {
                                    NextLevelExit();    // Change to Transition Slide
                                    return;
                                }
                            }
                        }
                    }
                    foreach (Cell cell in current_maze.getNearCells(player.bomb))
                    {
                        foreach (iCollidable collidable in cell.collidables)
                        {
                            Wall  wall  = collidable as Wall;
                            Spike spike = collidable as Spike;
                            if (wall != null)
                            {
                                if (player.bomb.Explosion.CollidesWith(wall.Bounds) && player.bomb.detonated && !wall.destroyed)
                                {
                                    if (wall.isBombable)
                                    {
                                        // Wall crumble apart particle system implemented here
                                        wallParticleSystem = newWallParticleSystem(graphics.GraphicsDevice, 100, particle, wall.Position());
                                        wall.Bounds.X      = -50;
                                        wall.Bounds.Y      = -50;
                                        score += 5000;
                                    }
                                }
                            }
                            if (spike != null)
                            {
                                if (player.bomb.Explosion.CollidesWith(spike.Bounds) && player.bomb.detonated && spike.on)
                                {
                                    spike.destroyed = true;
                                    score          += 2000;
                                }
                            }
                        }
                    }
                    if (player.Bounds.CollidesWith(player.bomb.Explosion) && player.bomb.detonated)
                    {
                        player.ouchBombSFX.Play(1, 0, 0);
                        GameOverDeath();
                    }

                    score--;
                }

                wallTimer += gameTime.ElapsedGameTime;
                if (wallTimer.TotalMilliseconds > wallTimeLimit)
                {
                    wallParticleSystem = newWallParticleSystem(graphics.GraphicsDevice, 1, particle, Vector2.Zero);
                }
                wallParticleSystem.Update(gameTime);
            }
            else if (viewState == ViewState.TRANSITION_RIGHT)
            {
            }
            base.Update(gameTime);
        }