private void UpdateBulletPositions(float moveSpeed)
        {
            for (int i = 0; i < bulletList.Count; i++)
            {
                Bullet currentBullet = bulletList[i];

                MoveForward(ref currentBullet.position, currentBullet.rotation, moveSpeed * 2.0f);
                bulletList[i] = currentBullet;

                BoundingSphere bulletSphere = new BoundingSphere(currentBullet.position, 0.05f);

                collisionType colType = CheckCollision(bulletSphere);
                if (colType != collisionType.None)
                {
                    bulletList.RemoveAt(i);
                    i--;

                    if (colType == collisionType.Target)
                    {
                        gameSpeed *= 1.05f;
                    }
                }
            }
        }
示例#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)
        {
            //killing and death

            BasicModel basic = enemyCollidingWith(chosen.box);

            if (basic != null)
            {
                collisionType type = collisionBoxToBox(chosen.box, basic.box);
                if (type == collisionType.TOP)
                {
                    //remove enemy
                    modelManager.models.Remove(basic);
                    score += 200;
                }
                else if (type != collisionType.TOP && type != collisionType.NO_COLLISION)
                {
                    reloadWorld();
                }
            }
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            if (!isLevelLoaded)
            {
                loadLevelBoxes();
                aStar    = new AStar(modelManager.widthOfMap, modelManager.heightOfMap, (int)modelManager.widthOfMap, (int)modelManager.heightOfMap, this);
                quadTree = new QuadTree(1, new BoundingBox(new Vector3(0, -modelManager.heightOfMap * 88.7f, 0), new Vector3(modelManager.widthOfMap * 117.3f, 0, 0)), this);

                if (isLevelLoaded)
                {
                    Components.Add(quadTree);
                    Components.Add(aStar);
                }
            }
            else
            {
                fpsTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                keyboard  = Keyboard.GetState();

                if (!prevKeyboard.IsKeyDown(Keys.Enter) && keyboard.IsKeyDown(Keys.Enter))
                {
                    if (aStar.state == AStar.SearchState.SEARCHING)
                    {
                        aStar.searchStep();
                    }
                }

                if (frameCount % 20 == 0 &&
                    aStar.state != AStar.SearchState.SEARCHING &&
                    follower.npcState.getCurrentState() != StateMachine.States.IDLE)
                {
                    aStar.reset();
                    aStar.openList.Add(aStar.setStartNode(follower));
                    aStar.endNode = aStar.nodeModelIn(chosen);
                    foreach (BasicModel bm in modelManager.models)
                    {
                        if (bm is GroundModel)
                        {
                            aStar.closedList.Add(aStar.nodeModelIn(bm));
                        }
                    }
                    aStar.state = AStar.SearchState.SEARCHING;
                }


                frameCount++;
                if (fpsTimer >= 1)
                {
                    FPS        = frameCount;
                    frameCount = 0;
                    fpsTimer   = 0;
                }
                //keyboard check for chosen character
                chosen.keyCheck();

                //bounds the PC's and enemies to gravity and the level
                chosen.checkCollision();
                follower.checkCollision();
                foreach (Enemy en in modelManager.models.OfType <Enemy>())
                {
                    en.Update(camera);
                    en.checkCollision();
                }

                //debug shnuff
                if (!prevKeyboard.IsKeyDown(Keys.Z) && keyboard.IsKeyDown(Keys.Z))
                {
                    Console.WriteLine("stateFollower: " + follower.npcState);
                    Console.WriteLine("newLine___" + chosen.ToString());
                }

                //Switch your character
                if (!prevKeyboard.IsKeyDown(Keys.E) && keyboard.IsKeyDown(Keys.E) && chosen is Human)
                {
                    foreach (Dwarf dwarf in modelManager.models.OfType <Dwarf>())
                    {
                        follower = chosen;
                        chosen   = dwarf;
                    }
                }

                else if (!prevKeyboard.IsKeyDown(Keys.E) && keyboard.IsKeyDown(Keys.E) && chosen is Dwarf)
                {
                    foreach (Human human in modelManager.models.OfType <Human>())
                    {
                        follower = chosen;
                        chosen   = human;
                    }
                }

                //toggle follow camera
                if (!prevKeyboard.IsKeyDown(Keys.X) && keyboard.IsKeyDown(Keys.X))
                {
                    if (!isFollowingPlayer)
                    {
                        isFollowingPlayer = true;
                    }
                    else
                    {
                        isFollowingPlayer = false;
                    }
                }

                //follow character maybe
                if (isFollowingPlayer)
                {
                    Vector3 tempCamPos = camera.position;
                    tempCamPos.X    = chosen.position.X;
                    tempCamPos.Y    = chosen.position.Y - 50;
                    camera.position = tempCamPos;
                }

                //reset characters to original position
                if (keyboard.IsKeyDown(Keys.R))
                {
                    reloadWorld();
                    SoundEffectInstance se = (SoundEffectInstance)soundManager.soundBank["dwarfStep"];
                    se.Play();
                }
                if (keyboard.IsKeyDown(Keys.T))
                {
                    SoundEffectInstance se = (SoundEffectInstance)soundManager.soundBank["humanStep"];
                    se.Play();
                }
                prevKeyboard = keyboard;
            }

            base.Update(gameTime);
        }