Example #1
0
        public override void gameLogic()
        {
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.X))
            {
                ball2.applyImpulse(0, 0.01f);
            }

            //ball.move(1,1);
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                ball2.applyForce(0, -17);
                //soundBank.PlayCue("ring");
            }
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                ball2.applyForce(0, 17);
                //soundBank.PlayCue("ring");
            }
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                ball2.applyForce(-17, 0);
                //soundBank.PlayCue("ring");
            }
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                ball2.applyForce(17, 0);
                //soundBank.PlayCue("ring");
            }
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.D))
            {
                net.SignInGamer();
            }
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.C))
            {
                net.CreateSession();
            }
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.G))
            {
                net.FindSession();
            }


            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.A))
            {
                ball.getBody().IsStatic = true;

                //soundBank.PlayCue("ring");
            }


            if (getGamePadButtons(Microsoft.Xna.Framework.PlayerIndex.One, Microsoft.Xna.Framework.Input.Buttons.A))
            {
                ball2.applyForce(-1, -1);
            }

            if (ball.physicsCollide(ball2))
            {
                //ball.height = 10;
                //ball.width = 10;
            }

            if (ball.simpleCollidesWith(ball2))
            {
                //     ball.height =100;
                //     s1.play();
            }
        }
Example #2
0
        public override void gameLogic()
        {
            if (gameOver == false)
            {
                //time tracker
                timeElapsed = this.getElapsedTime();
                timer.changeText(Convert.ToString(timeElapsed) + " seconds");
            }
            //accelerate the car
            if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up) == true)
            {
                line1.applyForce(0, 25);
                line2.applyForce(0, 25);
                line3.applyForce(0, 25);
                line4.applyForce(0, 25);
                kid1.applyForce(0, 25);
                kid2.applyForce(0, 25);
                flag.applyForce(0, 25);
            }
            //reposition lines when they get off screen
            if (line1.getY() > 440)
            {
                line1.setPosition(145, -40);
            }
            else if (line2.getY() > 440)
            {
                line2.setPosition(145, -40);
            }
            else if (line3.getY() > 440)
            {
                line3.setPosition(145, -40);
            }
            else if (line4.getY() > 440)
            {
                line4.setPosition(145, -40);
            }
            if (kid1.getY() > 415)
            {
                kid1.setPosition(rX.Next(100, 200), rY.Next(-200, -100));
            }
            if (kid2.getY() > 415)
            {
                kid2.setPosition(rX.Next(100, 200), rY.Next(-200, -100));
            }

            //apply brakes
            if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Down) == true && line1.getVelocityDY() > 0)
            {
                line1.applyForce(0, -100);
                line2.applyForce(0, -100);
                line3.applyForce(0, -100);
                line4.applyForce(0, -100);
            }
            //move car left and right
            if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left) == true)
            {
                car.setVelocity(-55, 0);
            }
            else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right) == true)
            {
                car.setVelocity(55, 0);
            }
            else
            {
                car.setVelocity(0, 0);
            }


            //finish line
            if (car.getY() < flag.getY())
            {
                finalStatus.changeText("Race Completed in " + Convert.ToString(timeElapsed) + " seconds");
                gameOver = true;
            }
            //hitting pedestrians
            if (car.physicsCollide(kid1))
            {
                finalStatus.changeText("GAME OVER-Pedestrian Squashed!!!");
            }
        }