Beispiel #1
0
        //spawns new enemies for the game
        private void spawnNewEnemies(int numEnemies)
        {
            int rand = randomNumber.Next(0,10);

            if (enemyObjects.Count < numEnemies)
            {
                EnemyObject testEnemy = new EnemyObject(playerTexture, 4, 4, (screenWidth - (playerTexture.Width / 4)) - 30 - rand * 48,
                                (gridHeight / 2) * 48, 100);
                testEnemy.playerID = "Enemy" + (enemyObjects.Count + 1);
                objects.Add(testEnemy);
                enemyObjects.Add(testEnemy);
            }
        }
Beispiel #2
0
        //initialise and start new game
        private void startNewSinglePlayerGame()
        {
            //setup grid landscape
            loadGridTiles();

            objects = new List<GameObject>();//keeps track of all objects in game
            enemyObjects = new List<EnemyObject>();//keeps track of all enemy objects
            currentMenuOption = 1;
            collisionDetector = new CollisionDetection();
            bombsLayed1 = new List<BombObject>();
            bombCount1 = 0;

            //keep track of all the scores
            player1Score = 0;
            player2Score = 0;
            highestEnemyScore = 0;

            //setup time variables
            startTime = System.Environment.TickCount;
            totalTime = 60;
            pausedTime = 0;
            elapsedPauseTime = 0;
            gamePaused = false;

            //initiailse map
            map = new GameMap(screenWidth, screenHeight, gridWidth, gridHeight, gridTileDimensions);
            map.initialiseMap(destructableTexture,indestructableTexture);

            //create player object positioned at the bottom, middle of screen
            //player1
            player1Obj = new Player(playerTexture, 4, 4, playerTexture.Width/4, (gridHeight/2)*48, 400);
            player1Obj.playerID = "Player1";
            player1Alive = true;
            objects.Add(player1Obj);
            player2Alive = false;
            //enemies
            for (int i = 0; i < 5; i++)
            {
                EnemyObject testEnemy = new EnemyObject(playerTexture, 4, 4, (screenWidth - (playerTexture.Width / 4)) - 30 - i*48,
                                (gridHeight / 2)*48, 200);
                testEnemy.playerID = "Enemy"+(i+1);
                objects.Add(testEnemy);
                enemyObjects.Add(testEnemy);
            }
        }
Beispiel #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            // initialize and fill list
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            _b1 = new BgObject(new Vector2(0, -1500), "scrollingbg.jpg");
            _b2 = new BgObject(new Vector2(0, -3550), "scrollingbg1.jpg");
            _p = new PlayerObject(new Vector2(300, 400), BgSpeed, "player.png");
            using (var fileStream = new FileStream("fail.jpg", FileMode.Open))
            {
                _fail = Texture2D.FromStream(Graphics.GraphicsDevice, fileStream);
            }
            using (var fileStream = new FileStream("menu.png", FileMode.Open))
            {
                _menuTex = Texture2D.FromStream(Graphics.GraphicsDevice, fileStream);
            }
            for (float i = 0; i < NumBullets; i++)
            {
                var bullet = new BulletObject("laser.png");
                _bulletList.Add(bullet);
            }
            for (float i = 0; i < NumBalloons; i++)
            {
                var balloon = new EnemyObject(new Vector2(150*i+200, 700), new Vector2(0,-1), 1, 100, "balloon.png");
                _enemyList.Add(balloon);
            }
            for (float i = 0; i < NumClover; i++)
            {
                var clover = new EnemyObject(new Vector2(i * 150 + 10, -100), new Vector2(1,1), 1, 150, "clover.png");
                _enemyList.Add(clover);

            }
            for (float i = 0; i < NumHearts; i++)
            {
                var heart = new EnemyObject(new Vector2(-100, 150 * i + 50), new Vector2(1, -.01f), 1, 200, "heart.png");
                _enemyList.Add(heart);
            }
            for (float i = 0; i < NumHorseShoe; i++)
            {
                var horseShoe = new EnemyObject(new Vector2(800, 150 * i + 50), new Vector2(-1, -.01f), 1, 250,"horseshoe.png");
                _enemyList.Add(horseShoe);

            }
            for (float i = 0; i < NumMoons; i++)
            {
                var moon = new EnemyObject(new Vector2(700 + i * 150, 700 + i * 150), new Vector2(-1, -1), 1, 300, "moon.png");
                _enemyList.Add(moon);

            }
            for (float i = 0; i < NumPotOGold; i++)
            {
                var potOGold = new EnemyObject(new Vector2(i * 100, 600 + i * 150), new Vector2(1, -1), 1, 350, "potOGold.png");
                _enemyList.Add(potOGold);

            }
            for (float i = 0; i < NumRainbows; i++)
            {
                var rainbow = new EnemyObject(new Vector2(500 + i * 150, -100), new Vector2(-1, 1), 1, 400, "rainbow.png");
                _enemyList.Add(rainbow);

            }
            for (float i = 0; i < NumStars; i++)
            {
                var star = new EnemyObject(new Vector2(-i * 40, 400 + i * 150), new Vector2(1, -1), 1, 450, "star.png");
                _enemyList.Add(star);

            }

            for (float i = 0; i < _enemyList.Count; i++)
            {
                var boom = new ExplosionObject(new Vector2(0, 0), "boom.png");
                _explosionList.Add(boom);
            }
            _checker = new CollisionChecker();

            // TODO: use this.Content to load your game content here
        }