Ejemplo n.º 1
0
 public void Update(GameTime gameTime, GraphicsDevice graphicsDevice)
 {
     if (IsPlayerCollision())
     {
         MainCharacter.isPoweredUp = true;
         LittleTiggy.powerUpSound.Play();
         MainCharacter.changeSkin();
         MainCharacter.powerUpTimer = DateTime.Now.AddSeconds(GameConstants.powerUpTimeSeconds);
         this.X = -16;
         this.Y = -16;
     }
 }
Ejemplo n.º 2
0
        void LoadGame()
        {
            gameBorder          = new GameBorder();
            character           = new MainCharacter(GraphicsDevice);
            touchControlOverlay = new ControlOverlay(GraphicsDevice);
            virtualThumbstick   = new VirtualThumbstick(GraphicsDevice);
            songBGM             = Content.Load <Song>("BackgroundMusic");
            MediaPlayer.Play(songBGM);
            MediaPlayer.IsRepeating = true;

            powerUpSound   = Content.Load <SoundEffect>("powerup");
            winGameSound   = Content.Load <SoundEffect>("wingame");
            loseGameSound  = Content.Load <SoundEffect>("losegame");
            killEnemySound = Content.Load <SoundEffect>("killenemy");

            LoadLevel(level);
        }
Ejemplo n.º 3
0
        public void LoadLevel(int level)
        {
            if (level > 1 && !string.IsNullOrEmpty(playerName) && !bDisableNetworkCalls)
            {
                SubmitScore(level);
                bGetScoresRequested = false; // Allow the player to get the latest leaderboard scores if they've won a level
            }

            // main character start position
            MainCharacter.X          = 1;
            MainCharacter.Y          = 1;
            character.isMovingToTile = false;

            // Loop until valid start conditions from random generation are met.

            // numberOfPlacedWalls = 0; //Used for debugging only
            // numberOfRandomWalls = 0; //Used for debugging only

            do
            {
                // Place 10 walls randomly (aligned to a GameConstants.tileSizexGameConstants.tileSize grid) around level.

                Random randomNumber = new Random();

                for (int i = 0; i < 10; i++)
                {
                    int gridAlignedX = randomNumber.Next(0, GameConstants.gameWidth);
                    int gridAlignedY = randomNumber.Next(0, GameConstants.gameHeight);

                    gridAlignedX = gridAlignedX - (gridAlignedX % GameConstants.tileSize);
                    gridAlignedY = gridAlignedY - (gridAlignedY % GameConstants.tileSize);

                    walls[i] = new EnvironmentBlock(this.GraphicsDevice, gridAlignedX, gridAlignedY);
                    // numberOfRandomWalls++; //Used for debugging only
                }

                // Randomly place more walls (grid aligned) adjacent to other walls to create a maze-ish level.  This works but is confusing - should have commented it more when I wrote it.

                int f = 0;

                for (int i = 10; i < walls.Length; i++) // Keep going until we have a position for every wall
                {
                    int gridAlignedX = 0;
                    int gridAlignedY = 0;

                    for (int c = 0; c < GameConstants.gameWidth; c = c + GameConstants.tileSize)                                  //Assess each grid square a column at a time
                    {
                        for (int d = 0; d < GameConstants.gameHeight; d = d + GameConstants.tileSize)                             // See above
                        {
                            for (int e = f; e < i; e++)                                                                           // Used to count between previously generated walls? & the total number of placed walls
                            {
                                if ((walls[e].X == (c - GameConstants.tileSize)) || (walls[e].Y == (d - GameConstants.tileSize))) // If any previously generated walls exists above or to the left of the current tile being evaluated
                                {
                                    if (randomNumber.Next(1, 100) == 15)                                                          // This is only True 1% of the time however as each grid square gets evaluated for every wall to be allocated, it gets a lot of attempts.
                                    {
                                        gridAlignedX = c;
                                        gridAlignedY = d;
                                        f            = e;
                                        f++;
                                        walls[i] = new EnvironmentBlock(this.GraphicsDevice, gridAlignedX, gridAlignedY);
                                        // numberOfPlacedWalls++; // Used for debugging only
                                        break; // We've assigned a wall, so exit the loop
                                    }
                                }
                            }
                            if (gridAlignedX > 0 || gridAlignedY > 0) // If we assigned a wall, exit loop
                            {
                                break;
                            }
                        }
                        if (gridAlignedX > 0 || gridAlignedY > 0) // If we assigned a wall, exit loop
                        {
                            break;
                        }
                    }

                    if (!(gridAlignedX > 0 || gridAlignedY > 0)) // If the above code did not generate a wall adjacent to an already existing wall based on chance, place a random wall.
                    {
                        gridAlignedX = randomNumber.Next(0, GameConstants.gameWidth);
                        gridAlignedY = randomNumber.Next(0, GameConstants.gameHeight);

                        gridAlignedX = gridAlignedX - (gridAlignedX % GameConstants.tileSize);
                        gridAlignedY = gridAlignedY - (gridAlignedY % GameConstants.tileSize);

                        walls[i] = new EnvironmentBlock(this.GraphicsDevice, gridAlignedX, gridAlignedY);
                        // numberOfRandomWalls++; // Used for debugging only
                    }
                }

                // spawn other elements on map now that walls have been created

                enemies = new List <Enemy>();
                for (int noOfEnemiesToSpawn = 0; noOfEnemiesToSpawn < level; noOfEnemiesToSpawn++)
                {
                    Enemy enemy = new Enemy(this.GraphicsDevice, walls);
                    enemies.Add(enemy);
                }

                powerUps = new List <PowerUp>();
                for (int noOfPowerUpsToSpawn = 0; noOfPowerUpsToSpawn < (level / 2); noOfPowerUpsToSpawn++)
                {
                    PowerUp powerUp = new PowerUp(this.GraphicsDevice, walls);
                    powerUps.Add(powerUp);
                }

                pathfinder = new Pathfinder(this.GraphicsDevice);

                // Loop until player can get to bottom of map & the enemy is in a position to get to the player.
            } while (pathfinder.IsRoutable(new Vector2(0, 0), new Vector2(496, 496), walls) == false || MainCharacter.IsEnvironmentCollision(walls, new Vector2(1, 1)));
        }