Exemplo n.º 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));
        }
Exemplo n.º 2
0
        protected override void Initialize()
        {
            player = new Player();
            EnemyKnight badiey = new EnemyKnight();

            enemyKnights.Add(badiey);
            base.Initialize();
        }
Exemplo n.º 3
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                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  = 2000;
                    int   strikeRange = 125;
                    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);
                    }
                    // if(!badie.isSwinging)
                    //{
                    if ((Math.Abs(xDistance) < enemySight) && (Math.Abs(xDistance) > strikeRange) && (xDistance > 0))
                    {
                        badie.StepLeft(gameTime);
                    }
                    else if (Math.Abs(xDistance) < enemySight && Math.Abs(xDistance) > strikeRange)
                    {
                        badie.StepRight(gameTime);
                    }
                    else
                    {
                        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.stunnedCheck      = enemyKnights[0].stunned;
                platformerHUD.Update(gameTime);
                platformerHUD.colPointEnemy = enemyKnights[0].hitByPlayerPoint;
                camera.Update(player.position);
                //end of that

                //particle engine and new animation style update statements
                animatedSprite.Update();

                particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                particleEngine.Update();
                //end of those added form wander

                break;
            }

            case State.Gameover:
            {
                break;
            }
            }

            #endregion

            base.Update(gameTime);
        }