public override void Update(GameTime gameTime)
        {
            timepassed += (float)gameTime.ElapsedGameTime.TotalSeconds;

            touchcollection          = TouchPanel.GetState();
            TouchPanel.DisplayWidth  = 875;
            TouchPanel.DisplayHeight = 480;

            // TODO: Add your update logic here
            JoystickLeft.Update();
            JoystickRight.Update();
        }
Пример #2
0
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here

            JoystickLeft.Update();
            JoystickRight.Update();

            m_player.Update(gameTime, JoystickLeft.GetJoystickDirection(), JoystickRight.GetJoystickDirection());
            m_camera.UpdateCamera(GetViewport);

            //JoystickLeft.Update();
            //JoystickRight.Update();


            if (m_player.GetPlayerLifes() < 0)
            {
                GameStateManager.Instance.ChangeScreen(new SubmitScoreState(_graphics, m_player.GetPlayerScore()));
            }

            foreach (ParallaxBackground background in m_parallaxBackgrounds)
            {
                background.Update(gameTime, GetViewport, JoystickLeft.GetJoystickDirection());
            }



            for (int i = 0; i < m_deathparticles.Count; i++)
            {
                m_deathparticles[i].Update(gameTime);

                if (!m_deathparticles[i].isAlive())
                {
                    m_deathparticles.RemoveAt(i);
                }
            }



            foreach (EnemySpawner enemyspawner in m_enemyspawners)
            {
                enemyspawner.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            /* I dont know if this is really terrible but it works for now */
            m_totalobjects.Clear();

            m_totalobjects.Add(m_player);


            foreach (EnemySpawner enemyspawner in m_enemyspawners)
            {
                m_totalobjects.AddRange(enemyspawner.GetEnemies());
            }


            m_totalobjects.AddRange(m_player.m_bullets);

            m_border.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

            //This is just added to allow for numerical data collection



            #region ClearQuadtree to allow for updates
            QuadList.Clear();
            quadtree.clear();
            #endregion

            #region Assign Objects to Quadtree
            for (int i = 0; i < m_totalobjects.Count; i++)
            {
                quadtree.insert(m_totalobjects[i]);
                //Go through all the objects and insert them into there proper quadform
            }
            #endregion


            //If more then 5 objects instantiate
            #region Quadtree instantiation
            if (m_totalobjects.Count >= 5)
            {
                for (int i = 0; i < m_totalobjects.Count; i++)
                {
                    ReturnObjects.Clear();
                    quadtree.retrieve(ReturnObjects, m_totalobjects[i]);

                    for (int x = 0; x < ReturnObjects.Count; x++)
                    {
                        if (m_totalobjects[i].GetobjectTag().Equals("bullet"))
                        {
                            if (i == x)
                            {
                                break;
                            }
                            Distance = (m_totalobjects[i].GetPosition() - ReturnObjects[x].GetPosition()).Length();


                            if (Distance < 64 && string.Equals(ReturnObjects[x].GetobjectTag(), "enemy"))
                            {
                                m_deathparticles.Add(new DeathParticle(m_deathparticletexture, ReturnObjects[x].GetPosition()));
                                m_totalobjects[i].SetCollision(true);
                                ReturnObjects[x].SetCollision(true);
                            }
                        }

                        else if (string.Equals(m_totalobjects[i].GetobjectTag(), "player"))
                        {
                            Distance = (m_totalobjects[i].GetPosition() - ReturnObjects[x].GetPosition()).Length();
                            if (Distance < 64 && string.Equals(ReturnObjects[x].GetobjectTag(), "enemy"))
                            {
                                m_deathparticles.Add(new DeathParticle(m_deathparticletexture, ReturnObjects[x].GetPosition()));
                                m_player.LoseLife();
                                ReturnObjects[x].SetCollision(true);
                            }
                        }

                        //Run Collision etection algorithmn between objects here
                    }
                }
            }
            #endregion

            //This is for if the quadtree hasnt be instantiated yet,
            #region RawCollisionDetection
            else
            {
                for (int i = 0; i < m_totalobjects.Count; i++)
                {
                    for (int j = 0; j < m_totalobjects.Count; j++)
                    {
                        Distance = (m_totalobjects[i].GetPosition() - m_totalobjects[j].GetPosition()).Length();

                        if (m_totalobjects[i].GetobjectTag().Equals("bullet"))
                        {
                            if (i == j)
                            {
                                break;
                            }
                            Distance = (m_totalobjects[i].GetPosition() - ReturnObjects[j].GetPosition()).Length();


                            if (Distance < 64 && string.Equals(ReturnObjects[j].GetobjectTag(), "enemy"))
                            {
                                m_deathparticles.Add(new DeathParticle(m_deathparticletexture, ReturnObjects[j].GetPosition()));
                                m_totalobjects[i].SetCollision(true);
                                ReturnObjects[j].SetCollision(true);
                            }
                        }

                        else if (string.Equals(m_totalobjects[i].GetobjectTag(), "player"))
                        {
                            Distance = (m_totalobjects[i].GetPosition() - ReturnObjects[j].GetPosition()).Length();
                            if (Distance < 64 && string.Equals(ReturnObjects[j].GetobjectTag(), "enemy"))
                            {
                                m_deathparticles.Add(new DeathParticle(m_deathparticletexture, ReturnObjects[j].GetPosition()));
                                m_player.LoseLife();
                                ReturnObjects[j].SetCollision(true);
                            }
                        }
                    }
                }
                #endregion
            }
        }