예제 #1
0
        protected Vector2 enemyHitFinal()
        {
            Matrix playerWeaponMat = Matrix.CreateTranslation(13, 120, 0)
                                     * Matrix.CreateRotationZ(player.weaponRotation)
                                     * Matrix.CreateTranslation(player.weaponPosition.X, player.weaponPosition.Y, 0);

            for (int i = 0; i < enemyKnights.Count; i++)
            {
                EnemyKnight badie = enemyKnights[i];

                if (badie.isAlive)
                {
                    Color[,] enemyBodyData = badie.enemyColorArray;
                    int xPos = (int)badie.position.X;
                    int yPos = (int)badie.position.Y;

                    Matrix  enemyBodyMat        = Matrix.CreateTranslation(xPos, yPos, 0);
                    Vector2 enemyCollisionPoint = TexturesCollide(playerWeaponData, playerWeaponMat, enemyBodyData, enemyBodyMat);

                    //Code for what happens if there is a collision bwtween player weapon and enemy
                    if (enemyCollisionPoint.X > -1)
                    {
                        badie.hitByPlayerPoint = enemyCollisionPoint;
                        return(enemyCollisionPoint);
                    }
                }
            }
            return(new Vector2(-1, -1));
        }
예제 #2
0
        protected override void Initialize()
        {
            player = new Player();
            EnemyKnight badiey = new EnemyKnight();

            enemyKnights.Add(badiey);
            base.Initialize();
        }
예제 #3
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //From Ship
            #region Ship stuff

            switch (gameState)
            {
            case State.Playing:
            {
                foreach (EnemyPirate e in enemyList)
                {
                    //add collision fool
                    if (e.boundingBox.Intersects(playerShip.boundingBox))
                    {
                        //playerShip.health -= 40;

                        e.isVisible = false;

                        gameState = State.Boarding;
                    }

                    //bullet collision
                    for (int i = 0; i < e.ballList.Count; i++)
                    {
                        if (playerShip.boundingBox.Intersects(e.ballList[i].boundingBox))
                        {
                            playerShip.health      -= enemyBallDamage;
                            e.ballList[i].isVisible = false;
                        }
                    }

                    for (int i = 0; i < playerShip.ballList.Count; i++)
                    {
                        if (playerShip.ballList[i].boundingBox.Intersects(e.boundingBox))
                        {
                            playerShip.ballList[i].isVisible = false;
                            e.speed = 0;
                        }
                    }

                    e.Update(gameTime);
                }



                backGround.speed = 2;
                playerShip.Update(gameTime);
                backGround.Updtae(gameTime);
                HUD.Update(gameTime);

                break;
            }

            case State.Menu:
            {
                KeyboardState keyState = Keyboard.GetState();
                if (keyState.IsKeyDown(Keys.Enter))
                {
                    gameState = State.Playing;
                }

                backGround.Updtae(gameTime);
                backGround.speed = 1;
                break;
            }

                #endregion
                #region action stuff
            case State.Boarding:
            {
                //GameTry2 original update
                if (Keyboard.GetState().IsKeyDown(Keys.Up))
                {
                    camera.Zoom += 0.01f;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Down))
                {
                    camera.Zoom -= 0.01f;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    camera.Rotation += 0.01f;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    camera.Rotation -= 0.01f;
                }

                player.Update(gameTime);
                if (enemyKnights.Count == 0)
                {
                    EnemyKnight badiey = new EnemyKnight();
                    enemyKnights.Add(badiey);
                }
                foreach (EnemyKnight badie in enemyKnights)
                {
                    badie.Update(gameTime);
                }

                foreach (CollisionTiles tile in drawMap.CollisionTiles)
                {
                    player.Collision(tile.Rectangle, levelSheet.Width * 64, levelSheet.Height * 64);
                    foreach (EnemyKnight badie in enemyKnights)
                    {
                        badie.Collision(tile.Rectangle, levelSheet.Width * 64, levelSheet.Height * 64);
                    }
                }

                #region Enemy AI Updates
                enemyHitFinal();

                foreach (EnemyKnight badie in enemyKnights)
                {
                    int   enemySight  = 1000;
                    int   strikeRange = 100;
                    float xDistance   = badie.Position.X - player.Position.X;
                    float yDistance   = player.Position.Y - badie.Position.Y;

                    if (badie.hitByPlayerPoint.X > -1)
                    {
                        badie.velocity.X = 0f;
                        badie.isSwinging = false;
                        badie.stunned    = 60;
                        //badie.hitByPlayerPoint = new Vector2(-1, -1);
                    }
                    else
                    {
                        if (xDistance < enemySight && xDistance > strikeRange)
                        {
                            badie.StepLeft(gameTime);
                        }
                        if (xDistance > -enemySight && xDistance < -strikeRange)
                        {
                            badie.StepRight(gameTime);
                        }
                        if (Math.Abs(xDistance) < strikeRange)
                        {
                            badie.Swing(gameTime);
                        }
                    }
                }
                #endregion

                platformerHUD.playerPos.X       = player.position.X;
                platformerHUD.playerPos.Y       = player.position.Y;
                platformerHUD.playerWeaponPos.X = player.weaponPosition.X;
                platformerHUD.playerWeaponPos.Y = player.weaponPosition.Y;
                platformerHUD.HUDweaponRotation = player.weaponRotation;
                platformerHUD.enemyPos.X        = enemyKnights[0].position.X;
                platformerHUD.enemyPos.Y        = enemyKnights[0].position.Y;
                platformerHUD.Update(gameTime);
                platformerHUD.colPointEnemy = enemyKnights[0].hitByPlayerPoint;
                camera.Update(player.Position);
                //end of that

                break;
            }

            case State.Gameover:
            {
                break;
            }
            }

            #endregion

            base.Update(gameTime);
        }