コード例 #1
0
        public bool pixelCollidesWith(sprite b)
        {
            if (Intersects(this.rectangle, b.rectangle))
            {
                uint[] bitsA = new uint[this.asset.Width * this.asset.Height];
                this.asset.GetData <uint>(bitsA);

                uint[] bitsB = new uint[b.asset.Width * b.asset.Height];
                b.asset.GetData <uint>(bitsB);

                int x1 = Math.Max(this.rectangle.X, b.rectangle.X);
                int x2 = Math.Min(this.rectangle.X + this.rectangle.Width, b.rectangle.X + b.rectangle.Width);

                int y1 = Math.Max(this.rectangle.Y, b.rectangle.Y);
                int y2 = Math.Min(this.rectangle.Y + this.rectangle.Height, b.rectangle.Y + b.rectangle.Height);

                for (int y = y1; y < y2; ++y)
                {
                    for (int x = x1; x < x2; ++x)
                    {
                        if (((bitsA[(x - this.rectangle.X) + (y - this.rectangle.Y) * this.asset.Width] & 0xFF000000) >> 24) > 20 &&
                            ((bitsB[(x - b.rectangle.X) + (y - b.rectangle.Y) * b.asset.Width] & 0xFF000000) >> 24) > 20)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #2
0
        public override void gameIni()
        {
            //set screen size
            this.setScreenSize(400, 400);
            //set screen colour
            this.setScreenColour(Microsoft.Xna.Framework.Graphics.Color.Black);
            //there should be no gravity
            this.setGravity(0);

            //create ball sprite
            ball        = new sprite(this, "pong", 10, 10, 240, 120);
            leftPaddle  = new sprite(this, "pong", 10, 80, 10, 160);
            rightPaddle = new sprite(this, "pong", 10, 80, 380, 160);
            //disable physics collisions
            //otherwise physics engine takes control of paddles response to being hit
            leftPaddle.enableCollision(false);
            rightPaddle.enableCollision(false);
            ball.enableCollision(false);

            //text objects to be used in the game
            title         = new text(this, "pongText", "PONG");
            playerScore   = new text(this, "pongText", "0");
            computerScore = new text(this, "pongText", "0");

            //sets ball initial velocity
            ball.setVelocity(150, 150);
        }
コード例 #3
0
ファイル: pong.cs プロジェクト: SeaHarg/Snake
        public override void gameIni()
        {
            //set screen size
            this.setScreenSize(400, 400);
            //set screen colour
            this.setScreenColour(Microsoft.Xna.Framework.Graphics.Color.Black);
            //there should be no gravity
            this.setGravity(0);

            //create ball sprite
            ball = new sprite(this, "pong",  10, 10, 240, 120);
            leftPaddle = new sprite(this, "pong",  10, 80, 10, 160);
            rightPaddle = new sprite(this, "pong", 10, 80, 380, 160);
            //disable physics collisions
            //otherwise physics engine takes control of paddles response to being hit
            leftPaddle.enableCollision(false);
            rightPaddle.enableCollision(false);
            ball.enableCollision(false);

            //text objects to be used in the game
            title = new text(this, "pongText", "PONG");
            playerScore = new text(this, "pongText", "0");
            computerScore = new text(this, "pongText", "0");

            //sets ball initial velocity
            ball.setVelocity(150, 150);
        }
コード例 #4
0
        public bool simpleCollidesWith(sprite b1)
        {
            Rectangle a = this.rectangle;
            Rectangle b = b1.rectangle;

            // check if two Rectangles intersect
            return(a.Right > b.Left && a.Left < b.Right &&
                   a.Bottom > b.Top && a.Top < b.Bottom);
        }
コード例 #5
0
 public bool physicsCollide(sprite withSprite)
 {
     if (this.rectGeom.Collide(withSprite.rectGeom))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #6
0
ファイル: Snake.cs プロジェクト: SeaHarg/Snake
 public void EdgesIni()
 {
     Border[0] = new sprite(this, "Side", 10, 800, 0, 0);
     Border[1] = new sprite(this, "Side", 800, 10, 0, 0);
     Border[2] = new sprite(this, "Side", 10, 800, 400, 0);
     Border[3] = new sprite(this, "side", 800, 50, 0, 400);
     Border[0].enableCollision(false);
     Border[1].enableCollision(false);
     Border[2].enableCollision(false);
     Border[3].enableCollision(false);
 }
コード例 #7
0
ファイル: exampleGame.cs プロジェクト: SeaHarg/ZombieHigh
        public override void gameIni()
        {
            ball  = new spriteCircle(this, "ball", "ball1", 50, 50, 25, 25);
            ball2 = new spriteCircle(this, "ball", "ball2", 20, 20, 200, 200);
            sprites.Add(ball);
            sprites.Add(ball2);
            s1 = new sound(this, "ring");
            //this.ps.Gravity = new FarseerGames.FarseerPhysics.Mathematics.Vector2 (0f,9.84f);//PHYSICS
            t1 = new text(this, "testFont", "This is a test");

            this.ps.Gravity = new FarseerGames.FarseerPhysics.Mathematics.Vector2(0f, 9.81f);
        }
コード例 #8
0
ファイル: exampleGame.cs プロジェクト: SeaHarg/Snake
        public override void gameIni()
        {
            ball = new spriteCircle(this,"ball","ball1" ,50, 50, 25, 25);
            ball2 = new spriteCircle(this, "ball","ball2", 20, 20, 200, 200);
            sprites.Add(ball);
            sprites.Add(ball2);
            s1 = new sound(this, "ring");
            //this.ps.Gravity = new FarseerGames.FarseerPhysics.Mathematics.Vector2 (0f,9.84f);//PHYSICS
            t1 = new text(this, "testFont", "This is a test");

            this.ps.Gravity = new FarseerGames.FarseerPhysics.Mathematics.Vector2(0f, 9.81f);
        }
コード例 #9
0
        public override void gameIni()
        {
            //set the size of the screen
            //this.setScreenSize(400, 400);
            //create the floor (use an image of sand)
            sand = new sprite(this, "sand", 400, 100, 200, 450);
            //don't let the floor move
            sand.makeStatic(true);


            //create the left wall and don't let it move
            wallLeft = new sprite(this, "sand", 5, 400, 2, 200);
            wallLeft.makeStatic(true);

            //create the right wall and on't let it move
            wallRight = new sprite(this, "bottomPost", 5, 400, 398, 200);
            wallRight.makeStatic(true);

            //create the left shell and don't allow it to be rotated
            leftShell = new sprite(this, "shell", 50, 50, 60, 310);
            leftShell.allowRotation(false);

            //create the right shell and don't allow it to be rotated
            rightShell = new sprite(this, "shell2", 50, 50, 340, 310);
            rightShell.allowRotation(false);

            //create the ball
            ball = new sprite(this, "volleyball", 40, 40, 60, 190);
            //give it a mass that is less than the shells (by default all sprites are given a mass of 1)
            ball.setMass(0.1f);
            //set the balls bounciness (ranges from 0 -no bounve to 1-perfect bounce)
            ball.setBounciness(1);


            //create the post and make it immovable
            bottomPost = new sprite(this, "bottomPost", 10, 200, 200, 350);
            bottomPost.makeStatic(true);


            //set the gravity-tis value affects the speed at which objects are pulled to the ground
            this.setGravity(190.81f);


            //create text objects
            state      = new text(this, "testFont", "Beach Volleyball");
            state1     = new text(this, "testFont", "Beach Volleyball");
            netState   = new text(this, "testFont", "Beach Volleyball");
            leftScore  = new text(this, "testFont", "0");
            rightScore = new text(this, "testFont", "0");
        }
コード例 #10
0
ファイル: netBeachVolleyball.cs プロジェクト: SeaHarg/Snake
        public override void gameIni()
        {
            //set the size of the screen
            //this.setScreenSize(400, 400);
            //create the floor (use an image of sand)
            sand = new sprite(this,  "sand", 400, 100, 200, 450);
            //don't let the floor move
            sand.makeStatic(true);

            //create the left wall and don't let it move
            wallLeft = new sprite(this,  "sand", 5, 400, 2, 200);
            wallLeft.makeStatic(true);

            //create the right wall and on't let it move
            wallRight = new sprite(this, "bottomPost",  5, 400, 398, 200);
            wallRight.makeStatic(true);

            //create the left shell and don't allow it to be rotated
            leftShell = new sprite(this, "shell",  50, 50, 60, 310);
            leftShell.allowRotation(false);

            //create the right shell and don't allow it to be rotated
            rightShell = new sprite(this, "shell2", 50, 50, 340, 310);
            rightShell.allowRotation(false);

            //create the ball
            ball = new sprite(this,  "volleyball", 40, 40, 60, 190);
            //give it a mass that is less than the shells (by default all sprites are given a mass of 1)
            ball.setMass(0.1f);
            //set the balls bounciness (ranges from 0 -no bounve to 1-perfect bounce)
            ball.setBounciness(1);

            //create the post and make it immovable
            bottomPost = new sprite(this, "bottomPost", 10, 200, 200, 350);
            bottomPost.makeStatic(true);

            //set the gravity-tis value affects the speed at which objects are pulled to the ground
            this.setGravity(190.81f);

            //create text objects
            state = new text(this, "testFont", "Beach Volleyball");
            state1 = new text(this, "testFont", "Beach Volleyball");
            netState = new text(this, "testFont", "Beach Volleyball");
            leftScore = new text(this, "testFont", "0");
            rightScore = new text(this, "testFont", "0");
        }
コード例 #11
0
        public override void gameIni()
        {
            gameOver    = false;
            finalStatus = new text(this, "Arial", "");
            //create random variable objects
            rX = new Random();
            rY = new Random();
            this.setScreenSize(300, 400);
            //there should be no gravity
            this.setGravity(0);

            road = new sprite(this, "road", 300f, 400f, 150f, 200f);
            road.enableCollision(false);

            flag = new sprite(this, "flag", 40, 40, 200, -1000);
            flag.enableCollision(false);


            line1 = new sprite(this, "line", 10, 80, 145, 40);
            line1.enableCollision(false);
            line2 = new sprite(this, "line", 10, 80, 145, 140);
            line2.enableCollision(false);
            line3 = new sprite(this, "line", 10, 80, 145, 240);
            line3.enableCollision(false);
            line4 = new sprite(this, "line", 10, 80, 145, 340);
            line4.enableCollision(false);

            car = new sprite(this, "car", 30f, 60f, 135f, 200f, FarseerGames.FarseerPhysics.CollisionCategory.Cat3, FarseerGames.FarseerPhysics.CollisionCategory.Cat1);
            //car.enableCollision(false);


            //kids

            kid1 = new sprite(this, "kid2", 30, 30, rX.Next(100, 200), rY.Next(20, 100), FarseerGames.FarseerPhysics.CollisionCategory.Cat1, FarseerGames.FarseerPhysics.CollisionCategory.Cat3);
            kid2 = new sprite(this, "kid3", 30, 30, rX.Next(100, 200), rY.Next(20, 100), FarseerGames.FarseerPhysics.CollisionCategory.Cat2, FarseerGames.FarseerPhysics.CollisionCategory.Cat4);


            //create text object for timer
            timer = new text(this, "Arial", "0 seconds");
        }
コード例 #12
0
ファイル: racer.cs プロジェクト: SeaHarg/Snake
        public override void gameIni()
        {
            gameOver = false;
             finalStatus = new text(this, "Arial", "");
             //create random variable objects
             rX = new Random();
             rY = new Random();
             this.setScreenSize(300, 400);
             //there should be no gravity
             this.setGravity(0);

             road = new sprite(this,  "road", 300f, 400f, 150f, 200f);
             road.enableCollision(false);

             flag = new sprite(this,  "flag", 40, 40, 200, -1000);
             flag.enableCollision(false);

             line1 = new sprite(this,  "line", 10, 80, 145, 40);
             line1.enableCollision(false);
             line2 = new sprite(this,  "line", 10, 80, 145, 140);
             line2.enableCollision(false);
             line3 = new sprite(this,  "line", 10, 80, 145, 240);
             line3.enableCollision(false);
             line4 = new sprite(this,  "line", 10, 80, 145, 340);
             line4.enableCollision(false);

             car = new sprite(this, "car", 30f, 60f, 135f, 200f, FarseerGames.FarseerPhysics.CollisionCategory.Cat3, FarseerGames.FarseerPhysics.CollisionCategory.Cat1);
             //car.enableCollision(false);

             //kids

             kid1 = new sprite(this,  "kid2", 30, 30, rX.Next (100,200), rY.Next(20,100),FarseerGames.FarseerPhysics.CollisionCategory.Cat1 ,FarseerGames.FarseerPhysics.CollisionCategory.Cat3 );
             kid2 = new sprite(this,  "kid3", 30, 30, rX.Next(100, 200), rY.Next(20, 100),FarseerGames.FarseerPhysics.CollisionCategory.Cat2 ,FarseerGames.FarseerPhysics.CollisionCategory.Cat4 );

             //create text object for timer
             timer = new text(this, "Arial", "0 seconds");
        }
コード例 #13
0
ファイル: ZombieHigh.cs プロジェクト: SeaHarg/ZombieHigh
 public void DeadMan()
 {
     sprite Deadman1 = new sprite(this, "Deadman-1", 31, 64, 0, 0);
     Deadman1.setVelocity(0, 0);
 }
コード例 #14
0
ファイル: Snake.cs プロジェクト: SeaHarg/Snake
 public void UserIni()
 {
     BodySprite = new sprite(this, "body", 10, 10, 200, 200);
     BodySprite.setVelocity(0, -10);
 }
コード例 #15
0
ファイル: sprite.cs プロジェクト: SeaHarg/Snake
 public bool simpleCollidesWith(sprite b1)
 {
     Rectangle a = this.rectangle;
     Rectangle b = b1.rectangle;
     // check if two Rectangles intersect
     return (a.Right > b.Left && a.Left < b.Right &&
             a.Bottom > b.Top && a.Top < b.Bottom);
 }
コード例 #16
0
ファイル: sprite.cs プロジェクト: SeaHarg/Snake
        public bool pixelCollidesWith(sprite b)
        {
            if (Intersects(this.rectangle, b.rectangle))
            {

                uint[] bitsA = new uint[this.asset.Width * this.asset.Height];
                this.asset.GetData<uint>(bitsA);

                uint[] bitsB = new uint[b.asset.Width * b.asset.Height];
                b.asset.GetData<uint>(bitsB);

                int x1 = Math.Max(this.rectangle.X, b.rectangle.X);
                int x2 = Math.Min(this.rectangle.X + this.rectangle.Width, b.rectangle.X + b.rectangle.Width);

                int y1 = Math.Max(this.rectangle.Y, b.rectangle.Y);
                int y2 = Math.Min(this.rectangle.Y + this.rectangle.Height, b.rectangle.Y + b.rectangle.Height);

                for (int y = y1; y < y2; ++y)
                {
                    for (int x = x1; x < x2; ++x)
                    {
                        if (((bitsA[(x - this.rectangle.X) + (y - this.rectangle.Y) * this.asset.Width] & 0xFF000000) >> 24) > 20 &&
                            ((bitsB[(x - b.rectangle.X) + (y - b.rectangle.Y) * b.asset.Width] & 0xFF000000) >> 24) > 20)
                            return true;
                    }
                }
            }

            return false;
        }
コード例 #17
0
ファイル: sprite.cs プロジェクト: SeaHarg/Snake
        public bool physicsCollide(sprite withSprite)
        {
            if (this.rectGeom.Collide(withSprite.rectGeom))
            {

                return true;
            }
            else
            {
                return false;

            }
        }
コード例 #18
0
ファイル: ZombieHigh.cs プロジェクト: SeaHarg/ZombieHigh
        public void DeadMan()
        {
            sprite Deadman1 = new sprite(this, "Deadman-1", 31, 64, 0, 0);

            Deadman1.setVelocity(0, 0);
        }