Exemplo n.º 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            player      = new playerShip();
            enemySprite = new Texture2D[3];

            enemies   = new enemyShip[25];
            enemyGrid = new Vector2[5, 5];

            screenDim = new float[] { GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height };

            //initializes the array of positions
            float holdX = 0;
            float holdY = 0;

            for (int x = 0; x < 5; x++)
            {
                for (int y = 0; y < 5; y++)
                {
                    holdX          += (screenDim[0] / 5);
                    enemyGrid[x, y] = new Vector2(holdX, holdY);
                }
                holdX  = 0;
                holdY += (10 + (50 * (x + 1)));
            }

            int currentShip = 0;

            //assigns positions to ships and makes them idle
            for (int x = 0; x < 5; x++)
            {
                for (int y = 0; y < 5; y++)
                {
                    enemies[currentShip] = new enemyShip(enemyGrid[x, y], enemySprite[0]);
                    enemies[currentShip].setStance(enemyShip.stance.idling);

                    currentShip += 1;
                }
            }



            speed = 5;
            timer = 0;

            player.setPlayerPos(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height - 60);



            base.Initialize();
        }
Exemplo n.º 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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            timer += 1;

            currentState = Keyboard.GetState();
            pressedKeys  = currentState.GetPressedKeys();
            enemies[0]   = new enemyShip(enemyGrid[2, 4], enemySprite[0]);


            if (pressedKeys.Length != 0)
            {
                switch (pressedKeys[pressedKeys.Length - 1])
                {
                case Keys.D:
                    player.setPlayerPos(player.getPlayerPos().X + speed, player.getPlayerPos().Y);
                    break;

                case Keys.A:
                    player.setPlayerPos(player.getPlayerPos().X - speed, player.getPlayerPos().Y);
                    break;

                case Keys.Space:

                    break;
                }
                //Check to make sure the user didn't overstep his damn bounds
            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }