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()
        {
            //control left shell
            if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.W) && Math.Round(leftShell.getVelocityDY()) == 0)
            {
                leftShell.setVelocity(leftShell.getVelocityDX(), -191f);
            }
            if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.A))
            {
                leftShell.setVelocity(-55, leftShell.getVelocityDY());
            }
            else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.D))
            {
                leftShell.setVelocity(55, leftShell.getVelocityDY());
            }
            else
            {
                leftShell.setVelocity(0, leftShell.getVelocityDY());
            }



            //control right shell
            if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up) && Math.Round(rightShell.getVelocityDY()) == 0)
            {
                rightShell.setVelocity(rightShell.getVelocityDX(), -191f);
            }
            if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                rightShell.setVelocity(-55, rightShell.getVelocityDY());
            }
            else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                rightShell.setVelocity(55, rightShell.getVelocityDY());
            }
            else
            {
                rightShell.setVelocity(0, rightShell.getVelocityDY());
            }

            //check ball state
            if (ball.physicsCollide(sand) && ball.getX() < 200)
            {
                //update score
                rightPoints++;
                //change score text to reflect this
                rightScore.changeText(Convert.ToString(rightPoints));
                //put ball above winner
                ball.setPosition(340, 100);
                //put both shells back at their start position
                rightShell.setPosition(340, 340);
                leftShell.setPosition(40, 340);
                //set ball's velocity to 0 so that it just falls down
                ball.setVelocity(0, 0);
            }
            if (ball.physicsCollide(sand) && ball.getX() > 200)
            {
                leftPoints++;
                leftScore.changeText(Convert.ToString(leftPoints));
                ball.setPosition(60, 100);
                rightShell.setPosition(340, 340);
                leftShell.setPosition(40, 340);
                ball.setVelocity(0, 0);
            }
        }
Example #3
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!!!");
            }
        }
Example #4
0
        public override void gameLogic()
        {
            if (stage == 0)
            {
                state.changeText("C-Create Session");
                state1.changeText("J-Join Session");
                if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.C))
                {
                    this.net.CreateSession();
                    //this.net.SignInGamer();
                }
                if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.J))
                {
                    //this.net.SignInGamer();
                    this.net.FindSession();
                }
                netState.changeText(this.net.Message);
                if (this.net.netState == 1)
                {//a state of means the player has joined is in play mode
                    stage = 3;
                }
            }
            else if (stage == 3)//game stage
            {
                state.changeText(net.Message);

                //control left shell
                if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.W) && Math.Round(leftShell.getVelocityDY()) == 0)
                {
                    leftShell.setVelocity(leftShell.getVelocityDX(), -191f);
                }
                if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.A))
                {
                    leftShell.setVelocity(-55, leftShell.getVelocityDY());
                }
                else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    leftShell.setVelocity(55, leftShell.getVelocityDY());
                }
                else
                {
                    leftShell.setVelocity(0, leftShell.getVelocityDY());
                }



                //control right shell
                if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up) && Math.Round(rightShell.getVelocityDY()) == 0)
                {
                    rightShell.setVelocity(rightShell.getVelocityDX(), -191f);
                }
                if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left))
                {
                    rightShell.setVelocity(-55, rightShell.getVelocityDY());
                }
                else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right))
                {
                    rightShell.setVelocity(55, rightShell.getVelocityDY());
                }
                else
                {
                    rightShell.setVelocity(0, rightShell.getVelocityDY());
                }

                //check ball state
                if (ball.physicsCollide(sand) && ball.getX() < 200)
                {
                    //update score
                    rightPoints++;
                    //change score text to reflect this
                    rightScore.changeText(Convert.ToString(rightPoints));
                    //put ball above winner
                    ball.setPosition(340, 100);
                    //put both shells back at their start position
                    rightShell.setPosition(340, 340);
                    leftShell.setPosition(40, 340);
                    //set ball's velocity to 0 so that it just falls down
                    ball.setVelocity(0, 0);
                }
                if (ball.physicsCollide(sand) && ball.getX() > 200)
                {
                    leftPoints++;
                    leftScore.changeText(Convert.ToString(leftPoints));
                    ball.setPosition(60, 100);
                    rightShell.setPosition(340, 340);
                    leftShell.setPosition(40, 340);
                    ball.setVelocity(0, 0);
                }


                //end of stage 3
            }
        }