Exemplo n.º 1
0
        public void updategame(float gtime)
        {
            // Main game code
            if (!gameover)
            {
                // Game is being played
                robot.moveme(pad[0], gtime, 70);

                // Allow robot to jump
                if (pad[0].Buttons.RightShoulder == ButtonState.Pressed)
                {
                    robot.jump(50);
                }

                // Set the camera to first person
                gamecamera.setFPor3P(robot.position, robot.direction, new Vector3(0, 0, 0), -60, 300, 60, 45);
                // Set side on camera view
                gamecamera.setsideon(robot.position, robot.rotation, 500, 50);
                // Set overhead camera view
                gamecamera.setoverhead(robot.position, 1000);
                // Set the camera to third person
                gamecamera.setFPor3P(robot.position, robot.direction, robot.velocity, 300, 100, 100, 60);


                // Allow the camera to look up and down
                gamecamera.position.Y += (pad[0].ThumbSticks.Right.Y * 140);

                // Spin flying saucer object
                tree[51].rotation.Y += 0.1f;

                if (keys.IsKeyDown(Keys.Escape) || pad[0].Buttons.Back == ButtonState.Pressed)
                {
                    gameover = true;    // End Game
                }
            }
            else
            {
                // Game is over

                // Allow game to return to the main menu
                if (keys.IsKeyDown(Keys.Escape) || pad[0].Buttons.B == ButtonState.Pressed)
                {
                    // SORT HIGH SCORE TABLE
                    Array.Sort(highscores, highscorenames);
                    Array.Reverse(highscores);
                    Array.Reverse(highscorenames);

                    gamestate = -1;
                }
            }
        }
Exemplo n.º 2
0
        public void updategame(float gtime)
        {
            // Main game code
            if (!gameover)
            {
                // Game is being played
                if (pad[0].Buttons.Back == ButtonState.Pressed)
                {
                    gameover = true;                                             // Allow user to quit game
                }
                // Check for touch over a menu option
                Vector2         dirtomove   = new Vector2(0, 0);
                float           turnamount  = 0;
                TouchCollection tcoll       = TouchPanel.GetState();
                BoundingSphere  touchsphere = new BoundingSphere(new Vector3(0, 0, 0), 1);
                foreach (TouchLocation t1 in tcoll)
                {
                    if (t1.State == TouchLocationState.Pressed || t1.State == TouchLocationState.Moved)
                    {
                        touchsphere = new BoundingSphere(new Vector3(t1.Position.X, t1.Position.Y, 0), 1);
                        if (touchsphere.Intersects(up.bbox))
                        {
                            dirtomove.Y = 1;
                        }
                        if (touchsphere.Intersects(down.bbox))
                        {
                            dirtomove.Y = -1;
                        }
                        if (touchsphere.Intersects(left.bbox))
                        {
                            dirtomove.X = 1;
                        }
                        if (touchsphere.Intersects(right.bbox))
                        {
                            dirtomove.X = -1;
                        }
                        if (touchsphere.Intersects(left2.bbox))
                        {
                            turnamount = 1;
                        }
                        if (touchsphere.Intersects(right2.bbox))
                        {
                            turnamount = -1;
                        }
                    }
                }

                // Move Robot based on user input
                uservehicle.moveme(dirtomove, turnamount, gtime, 70);

                // Spin and move UFOS
                for (int i = 0; i < ufos.Count(); i++)
                {
                    // Spin UFOs
                    ufos[i].rotation.Y += 0.5f;

                    // Move UFOs
                    Vector3 ufovelocity = new Vector3(30, 0, 40);
                    ufos[i].position += ufovelocity;
                }

                //  if (pad[0].Buttons.A == ButtonState.Pressed) robot1.jump(100, gtime);

                // Set the camera to first person
                //gamecamera.setFPor3P(robot.position, robot.direction, new Vector3(0, 0, 0), -60, 300, 60, 45);
                // Set side on camera view
                //gamecamera.setsideon(robot.position, robot.rotation, 500, 50);
                // Set overhead camera view
                //gamecamera.setoverhead(robot.position, 1000);

                // Set the camera to third person
                gamecamera.setFPor3P(uservehicle.position, uservehicle.direction, uservehicle.velocity, 300, 100, 100, 60);

                // Allow the camera to look up and down
                //gamecamera.position.Y += (pad[0].ThumbSticks.Right.Y * 140);

                if (pad[0].Buttons.Back == ButtonState.Pressed)
                {
                    gameover = true;    // End Game
                }
            }
            else
            {
                // Game is over, allow game to return to the main menu
                if (pad[0].Buttons.Back == ButtonState.Pressed)
                {
                    // SORT HIGHSCORE TABLE
                    Array.Sort(highscores);
                    Array.Reverse(highscores);

                    gamestate = -1; // Allow user to quit game
                }
            }
        }
Exemplo n.º 3
0
        public void updategame(float gtime)
        {
            // Main game code
            if (!gameover)
            {
                score = (int)(gameruntime / 1000);

                // Game is being played
                float   turnamount = MathHelper.ToRadians(0);
                Vector2 dirtomove  = new Vector2(0, 0);
                dirtomove.X = -pad[0].ThumbSticks.Left.X;
                dirtomove.Y = pad[0].ThumbSticks.Left.Y;

                // Move Robot based on touch control input
                robot.moveme(dirtomove, turnamount, gtime, 70);

                // Check for collisions between your vehicle and trees
//                for (int i = 0; i < numberoftrees; i++)
//                {
//                    if (uservehicle.bsphere.Intersects(tree[i].bsphere))
//                        gameover = true;
//                }

                // Allow robot to jump
                if (pad[0].Buttons.RightShoulder == ButtonState.Pressed)
                {
                    robot.jump(50);
                }

                // Set a minimum speed for the robot
                if (robot.velocity.Z < 10)
                {
                    robot.velocity.Z = 10;
                }

                // Set limits for the robots movements
                int wall_limits = 822;
                if (robot.position.X < -wall_limits)
                {
                    robot.position.X = -wall_limits;
                }
                if (robot.position.X > wall_limits)
                {
                    robot.position.X = wall_limits;
                }

                // Move ground & wall panels forward once you pass them
                for (int i = 0; i < numberofgrounds; i++)
                {
                    if (robot.position.Z > ground[i].position.Z + (500 * ground[i].size))
                    {
                        ground[i].position.Z   += (800 * ground[i].size * (numberofgrounds - 1));
                        leftwall[i].position.Z  = ground[i].position.Z;
                        rightwall[i].position.Z = ground[i].position.Z;
                    }
                }

                // Set the camera to first person
                //gamecamera.setFPor3P(robot.position, robot.direction, new Vector3(0, 0, 0), -60, 300, 60, 45);
                // Set side on camera view
                //gamecamera.setsideon(robot.position, robot.rotation, 1000, 50);
                // Set overhead camera view
                //gamecamera.setoverhead(robot.position, 1000);

                // Set the camera to third person
                gamecamera.setFPor3P(robot.position, robot.direction, robot.velocity, 300, 100, 100, 60);

                if (keys.IsKeyDown(Keys.Escape) || pad[0].Buttons.Back == ButtonState.Pressed)
                {
                    gameover = true;    // End Game
                }
            }
            else
            {
                // Game is over
                // Allow game to return to the main menu
                if (keys.IsKeyDown(Keys.Escape) || pad[0].Buttons.B == ButtonState.Pressed)
                {
                    if (score > highscores[9])
                    {
                        highscores[9] = score;
                    }

                    // SORT HIGHSCORE TABLE
                    Array.Sort(highscores);
                    Array.Reverse(highscores);


                    gamestate = -1;
                }
            }
        }
Exemplo n.º 4
0
        public void updategame(float gtime)
        {
            music.Play();

            // Main game code
            if (!gameover)
            {
                if (bulletcount <= 0)
                {
                    bulletcount = 0;
                }


                if (health <= 0)
                {
                    gameover = true;
                }

                for (int i = 0; i < numberofbullets; i++)
                {
                    if (playerbullet[i].visible)
                    {
                        playerbullet[i].velocity.Z += playerchar.velocity.Z * 2;
                        playerbullet[i].updateobject();

                        if (playerbullet[i].position.Z > playerchar.position.Z + 10000)
                        {
                            playerbullet[i].visible = false;
                        }

                        // Check for bullet hitting zombies
                        for (int j = 0; j < numberofzombs; j++)
                        {
                            if (playerbullet[i].bsphere.Intersects(zombies[j].bbox))
                            {
                                zombiehit.Play();
                                score += 10;
                                playerbullet[i].visible = false;
                                spawnzombie(j, playerchar.position.Z);
                            }
                        }
                    }
                }
                for (int i = 0; i < numberofzombs; i++)
                {
                    if (zombies[i].position.Z <= playerchar.position.Z - 1000)
                    {
                        spawnzombie(i, playerchar.position.Z);
                    }
                }



                // Game is being played
                if (pad[0].Buttons.Back == ButtonState.Pressed)
                {
                    gameover = true;                                             // Allow user to quit game
                }
                // Check for touch presses on arrow keys
                Vector2         dirtomove   = new Vector2(0, 0);
                float           turnamount  = MathHelper.ToRadians(0);
                TouchCollection tcoll       = TouchPanel.GetState();
                BoundingSphere  touchsphere = new BoundingSphere(new Vector3(0, 0, 0), 1);
                foreach (TouchLocation t1 in tcoll)
                {
                    if (t1.State == TouchLocationState.Pressed || t1.State == TouchLocationState.Moved)
                    {
                        touchsphere = new BoundingSphere(new Vector3(t1.Position.X, t1.Position.Y, 0), 1);

                        if (touchsphere.Intersects(up.bbox))
                        {
                            dirtomove.Y = 1;
                        }
                        if (touchsphere.Intersects(down.bbox))
                        {
                            dirtomove.Y = -1;
                        }
                        if (touchsphere.Intersects(left.bbox))
                        {
                            dirtomove.X = 1;
                        }
                        if (touchsphere.Intersects(right.bbox))
                        {
                            dirtomove.X = -1;
                        }

                        if (touchsphere.Intersects(firebut.bbox) && bulletcount <= 0)
                        {
                            playerfire();
                        }
                    }
                }

                // Move Robot based on touch control input
                playerchar.moveme(dirtomove, turnamount, gtime, 70);


                // Check for collisions between player and zombies
                for (int i = 0; i < numberofzombs; i++)
                {
                    zombies[i].updateobject();
                    if (playerchar.bbox.Intersects(zombies[i].bbox) && zombies[i].visible)
                    {
                        playerhit.Play();
                        zombies[i].visible = false;
                        health--;
                        playerchar.velocity.Z = -playerchar.velocity.Z;
                        spawnzombie(i, playerchar.position.Z);
                    }
                }

                // Move Robot based on accelerometer
                dirtomove = new Vector2(0, 0);

                AccelerometerState accelsen = accelerometer1.Accelerometer.GetState();
                if (accelsen.IsActive)
                {
                    acc         = accelsen.Acceleration;
                    dirtomove.X = accelsen.Acceleration.Y * 2;
                    if (TouchPanel.DisplayOrientation == DisplayOrientation.LandscapeRight)
                    {
                        dirtomove.X = -dirtomove.X;
                    }
                }
                // Move Robot based on accelerometer input
                playerchar.moveme(dirtomove, turnamount, gtime, 70);

                if (playerchar.velocity.Z < 5)
                {
                    playerchar.velocity.Z = 5;                            // Set a minimum speed for the robot
                }
                // Set limits for the robots movements
                int wall_limits = 822;
                if (playerchar.position.X < -wall_limits)
                {
                    playerchar.position.X = -wall_limits;
                }
                if (playerchar.position.X > wall_limits)
                {
                    playerchar.position.X = wall_limits;
                }

                // Read flick gestures
                TouchPanel.EnabledGestures = GestureType.Flick;
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gs = TouchPanel.ReadGesture();
                    if (gs.GestureType == GestureType.Flick)
                    {
                        playerchar.jump(Math.Abs(gs.Delta.Y / 175));   // Jump robot based on the Y flick gesture amount
                    }
                }

                // Move ground & wall panels forward once you pass them
                for (int i = 0; i < numberofgrounds; i++)
                {
                    if (playerchar.position.Z > ground[i].position.Z + (500 * ground[i].size))
                    {
                        ground[i].position.Z   += (800 * ground[i].size * (numberofgrounds - 1));
                        leftwall[i].position.Z  = ground[i].position.Z;
                        rightwall[i].position.Z = ground[i].position.Z;
                    }
                }

                // Set side on camera view
                //gamecamera.setsideon(uservehicle.position, uservehicle.rotation, 1000, 100, 400);
                // Set the camera to first person
                //gamecamera.setFPor3P(uservehicle.position, uservehicle.direction, new Vector3(0, 0, 0), 100, 300, 60, 45);
                // Set overhead camera view
                //gamecamera.setoverhead(playerchar.position, 2000);
                // Set the camera to third person
                gamecamera.setFPor3P(playerchar.position, playerchar.direction, playerchar.velocity, 100, 100, 150, 100);
                // Allow the camera to look up and down
                //cameraposition.Y += (pad[0].ThumbSticks.Right.Y * 140);
            }
            else
            {
                //Stop music if its playing
                if (music.State == SoundState.Playing)
                {
                    music.Stop();
                }

                // Game is over, allow game to return to the main menu
                if (pad[0].Buttons.Back == ButtonState.Pressed)
                {
                    if (score > highscores[9] && score > 0)
                    {
                        highscores[9] = score;
                    }

                    // SORT HIGHSCORE TABLE
                    Array.Sort(highscores);
                    Array.Reverse(highscores);

                    gamestate = -1; // Allow user to quit game
                }
            }
        }