コード例 #1
0
        public void AddLaser(Vector2 p)
        {
            float      left   = 0;
            float      right  = 0.1f;
            float      top    = 0.1f;
            float      bottom = 0;
            GameSprite obs    = new GameSprite();

            Texture lasertexture = TextureLoader.FromFile(device, "../../redLaser.bmp");

            obs.Tex = lasertexture;

            obs.AddVertex(new Vector2(left, top));
            obs.AddTex(new Vector2(0, 0));
            obs.AddVertex(new Vector2(right, top));
            obs.AddTex(new Vector2(1, 0));
            obs.AddVertex(new Vector2(right, bottom));
            obs.AddTex(new Vector2(1, 1));
            obs.AddVertex(new Vector2(left, bottom));
            obs.AddTex(new Vector2(0, 1));
            obs.Color       = Color.Transparent;
            obs.Transparent = true;
            Vector2 q = p;

            q.Y  -= 0.05f;
            q.X  += 0.25f;
            obs.P = q;
            obs.V = new Vector2(3, 0);
            lasers.Add(obs);
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: sarteleb/yoloswagtopia
        public Game()
        {
            InitializeComponent();

            if (!InitializeDirect3D())
            {
                return;
            }

            sounds = new AlienSound(this);

            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);

            background = new Background(device, playingW, playingH);

            font = new Microsoft.DirectX.Direct3D.Font(device,                         // Device we are drawing on
                                                       40,                             // Font height in pixels
                                                       0,                              // Font width in pixels or zero to match height
                                                       FontWeight.Bold,                // Font weight (Normal, Bold, etc.)
                                                       0,                              // mip levels (0 for default)
                                                       false,                          // italics?
                                                       CharacterSet.Default,           // Character set to use
                                                       Precision.Default,              // The font precision, try some of them...
                                                       FontQuality.Default,            // Quality?
                                                       PitchAndFamily.FamilyDoNotCare, // Pitch and family, we don't care
                                                       "Arial");                       // And the name of the font

            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            texture1          = TextureLoader.FromFile(device, "../../texture1.bmp");
            texture2          = TextureLoader.FromFile(device, "../../texture2.png");
            texture3          = TextureLoader.FromFile(device, "../../texture3.bmp");
            texture4          = TextureLoader.FromFile(device, "../../texture4.bmp");
            texture5          = TextureLoader.FromFile(device, "../../texture5.bmp");
            texture6          = TextureLoader.FromFile(device, "../../texture6.bmp");
            stoneTexture      = TextureLoader.FromFile(device, "../../texture7.bmp");
            finishLineTexture = TextureLoader.FromFile(device, "../../finishlineplatform.bmp");
            projectileGen     = new ProjectileGenerator(device);

            //Create barrier to keep player from walking off edges
            AddObstacle(-0.1f, 0, int.MinValue, int.MaxValue, Color.MintCream);
            AddObstacle(playingW, playingW + 0.1f, int.MinValue, int.MaxValue, Color.MintCream);

            Polygon startingPlat = new Polygon();

            startingPlat.AddVertex(new Vector2(0, .1f));
            startingPlat.AddVertex(new Vector2(.5f, .1f));
            startingPlat.AddVertex(new Vector2(.5f, 0));
            startingPlat.AddVertex(new Vector2(0, 0));
            startingPlat.Color = Color.DarkSlateGray;
            world.Add(startingPlat);

            Platform platform = new Platform();

            platform.AddVertex(new Vector2(3.2f, 2));
            platform.AddVertex(new Vector2(4.3f, 2));
            platform.AddVertex(new Vector2(4.3f, 1.8f));
            platform.AddVertex(new Vector2(3.2f, 1.8f));
            platform.Color = Color.DarkSlateGray;
            world.Add(platform);

            Platform platform4 = new Platform();

            platform4.AddVertex(new Vector2(21, 2));
            platform4.AddVertex(new Vector2(21.5f, 2));
            platform4.AddVertex(new Vector2(21.5f, 1.8f));
            platform4.AddVertex(new Vector2(21, 1.8f));
            platform4.Color = Color.DarkSlateGray;
            world.Add(platform4);

            Platform platform5 = new Platform();

            platform5.AddVertex(new Vector2(23, 2));
            platform5.AddVertex(new Vector2(23.5f, 2));
            platform5.AddVertex(new Vector2(23.5f, 1.8f));
            platform5.AddVertex(new Vector2(23, 1.8f));
            platform5.Color = Color.DarkSlateGray;
            platform5.setDtOffset(0.01f);
            world.Add(platform5);

            HorizontalPlat platform2 = new HorizontalPlat();

            platform2.AddVertex(new Vector2(11, 2));
            platform2.AddVertex(new Vector2(12f, 2));
            platform2.AddVertex(new Vector2(12f, 1.8f));
            platform2.AddVertex(new Vector2(11f, 1.8f));
            platform2.Speed = 1f;
            platform2.Color = Color.DarkSlateGray;
            platform2.Width = 4;
            world.Add(platform2);

            //addTexturedPolygon(left, right, bottom, top, outer, texture)
            addTexturedPolygon(1.2f, 1.9f, 1.4f, 1.6f, 1.3f, stoneTexture); //1st plat
            addTexturedPolygon(6, 7, 1.7f, 3f, 1.5f, texture1);             //3rd after moving

            addTexturedPolygon(9, 10, 1.2f, 1.7f, 1.0f, texture4);
            addTexturedPolygon(15, 16, 2.5f, 2.7f, 2.0f, texture5);
            addTexturedPolygon(18, 20, 2.2f, 2.4f, 1.5f, texture2);
            addTexturedPolygon(24.5f, 25, 2.2f, 2.4f, 1.5f, texture3);
            addTexturedPolygon(27, 29, 2.2f, 2.4f, 1.5f, texture6);

            EndPlat pt = new EndPlat();

            pt.Tex = finishLineTexture;
            pt.AddVertex(new Vector2(30, 1.5f)); //A
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(32, 1.5f)); //B
            pt.AddTex(new Vector2(1, 0));
            pt.AddVertex(new Vector2(32, 0.5f)); //C
            pt.AddTex(new Vector2(1, 1));
            pt.AddVertex(new Vector2(30, 0.5f));
            pt.AddTex(new Vector2(0, 1));
            pt.Color = Color.Transparent;
            world.Add(pt);

            Texture spritetexture = TextureLoader.FromFile(device, "../../falco.png");

            player.Tex = spritetexture;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 0.5f));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 0.5f));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color       = Color.Transparent;
            player.Transparent = true;
            player.P           = new Vector2(0.5f, 1);
            player.A           = new Vector2(0, -9.8f);
            currentPlat        = null;

            scores = new Scoring("../../highscores.xml");
            scores.Load();
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: erskin19/Project3CSE471
        public Game()
        {
            InitializeComponent();
            if (!InitializeDirect3D())
            {
                return;
            }
            // To create a triangle

            /*  vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
             *                            3,      // How many
             *                            device, // What device
             *                            0,      // No special usage
             *                            CustomVertex.PositionColored.Format,
             *                            Pool.Managed);*/

            // To create a rectangle
            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);
            verticeshex = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                           6,                                    // How many
                                           device,                               // What device
                                           0,                                    // No special usage
                                           CustomVertex.PositionColored.Format,
                                           Pool.Managed);

            background = new Background(device, playingW, playingH);

            //font = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 20f));

            sound = new GameSounds(this);

            // Add a polygon

            /* floor.AddVertex(new Vector2(0, 1));
             * floor.AddVertex(new Vector2(playingW, 1));
             * floor.AddVertex(new Vector2(playingW, 0.9f));
             * floor.AddVertex(new Vector2(0, 0.9f));
             * floor.Color = Color.CornflowerBlue;*/

            // Add multiple polygons to form the world
            Polygon floor = new Polygon();

            floor.AddVertex(new Vector2(0, 1));
            floor.AddVertex(new Vector2(playingW, 1));
            floor.AddVertex(new Vector2(playingW, 0.9f));
            floor.AddVertex(new Vector2(0, 0.9f));
            floor.Color = Color.CornflowerBlue;
            world.Add(floor);
            for (int i = 0; i < 10; i++)
            {
                Texture         coin_texture = TextureLoader.FromFile(device, "../../coin.png");
                PolygonTextured hexagon      = new PolygonTextured();
                hexagon.Transparent = true;
                hexagon.Tex         = coin_texture;

                float x = (float)random.Next(2, 10);
                float y = (float)random.Next(1, 6);

                hexagon.AddVertex(new Vector2(x + 0.5f / 6, y));
                hexagon.AddTex(new Vector2(0.75f, 1f));
                hexagon.AddVertex(new Vector2(x, y + 1.732f / 12));
                hexagon.AddTex(new Vector2(1f, 0.5f));
                hexagon.AddVertex(new Vector2(x + 0.5f / 6, y + 1.732f / 6));
                hexagon.AddTex(new Vector2(0.75f, 0f));
                hexagon.AddVertex(new Vector2(x + 1.5f / 6, y + 1.732f / 6));
                hexagon.AddTex(new Vector2(0.25f, 0f));
                hexagon.AddVertex(new Vector2(x + 2f / 6, y + 1.732f / 12));
                hexagon.AddTex(new Vector2(0f, 0.5f));
                hexagon.AddVertex(new Vector2(x + 1.5f / 6, y));
                hexagon.AddTex(new Vector2(0.25f, 1f));
                hexagon.Color = Color.Transparent;
                coins.Add(hexagon);
            }

            Texture flag_texture = TextureLoader.FromFile(device, "../../../textures/flag.png");

            flag.AddVertex(new Vector2(9.7f, 2));
            flag.AddVertex(new Vector2(10.7f, 2));
            flag.AddVertex(new Vector2(10.7f, 1));
            flag.Tex = flag_texture;
            flag.AddTex(new Vector2(0, 0));
            flag.AddTex(new Vector2(1, 0));
            flag.AddTex(new Vector2(1, 1));
            //world.Add(flag);
            //basketball
            Texture basketballtexture = TextureLoader.FromFile(device, "../../basketball.png");

            basketball.Transparent = true;
            basketball.P           = new Vector2(2, 2);
            //basketball.V = new Vector2(0.1f,-0.1f);
            basketball.Tex = basketballtexture;

            basketball.AddVertex(new Vector2(-0.5f / 3, 1.732f / 6));
            basketball.AddTex(new Vector2(0, 1));
            basketball.AddVertex(new Vector2(0.5f / 3, 1.732f / 6));
            basketball.AddTex(new Vector2(0, 0));
            basketball.AddVertex(new Vector2(0.5f / 3, 0));
            basketball.AddTex(new Vector2(1, 0));
            basketball.AddVertex(new Vector2(-0.5f / 3, 0));
            basketball.AddTex(new Vector2(1, 1));
            basketball.Color = Color.Transparent;
            //powerup.Add(basketball);
            //Vector2 v_b = basketball.V;
            //v_b.Y = -0.5f;
            //basketball.V = v_b;

            AddObstacle(2, 3, 1.7f, 1.9f, Color.Crimson);
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 2.2f, 2.4f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(6.5f, 7.5f, 2.5f, 2.7f, Color.Chocolate);
            AddObstacle(8.5f, 9.5f, 1.0f, 1.2f, Color.AliceBlue);

            Platform platform = new Platform();

            platform.AddVertex(new Vector2(3.2f, 2));
            platform.AddVertex(new Vector2(3.9f, 2));
            platform.AddVertex(new Vector2(3.9f, 1.8f));
            platform.AddVertex(new Vector2(3.2f, 1.8f));
            platform.Color = Color.Black;
            world.Add(platform);

            Texture texture = TextureLoader.FromFile(device, "../../stone08.bmp");

            //PolygonTextured pt = new PolygonTextured();
            pt.Tex = texture;
            pt.AddVertex(new Vector2(1.2f, 3.5f));
            pt.AddTex(new Vector2(0, 1));
            pt.AddVertex(new Vector2(1.9f, 3.5f));
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(1.9f, 3.3f));
            pt.AddTex(new Vector2(1, 0));
            pt.AddVertex(new Vector2(1.2f, 3.3f));
            pt.AddTex(new Vector2(1, 1));
            pt.Color = Color.Transparent;
            world.Add(pt);

            //Texture spritetexture = TextureLoader.FromFile(device, "../../guy8.bmp");
            spritetexture      = TextureLoader.FromFile(device, "../../../textures/small_mario.png");
            spritepowertexture = TextureLoader.FromFile(device, "../../../textures/big_mario.png");
            player.Transparent = true;
            player.P           = new Vector2(0.5f, 1);
            player.Tex         = spritetexture;

            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color = Color.Transparent;

            /*
             * Texture wolverineTex = TextureLoader.FromFile(device, "../../../textures/wolverine.bmp");
             * wolverine = new Wolverine(2, 2);
             * wolverine.Tex = wolverineTex;
             */
            Texture wolvSprite = TextureLoader.FromFile(device, "../../../textures/wolverine.png");

            for (int i = 0; i < 1; i++)
            {
                //wolverine = new Wolverine((float)random.Next(3, 5) + (float)random.NextDouble(),  .5f);
                wolverine = new Wolverine(3, .5f);

                //wolverine.Transparent = true;
                //wolverine.P = new Vector2(0.5f, 1);
                wolverine.Tex = wolvSprite;
                wolverines.Add(wolverine);
            }

            /*
             * wolverine.AddVertex(new Vector2(-0.2f, 0));
             * wolverine.AddTex(new Vector2(0, 1));
             * wolverine.AddVertex(new Vector2(-0.2f, 1));
             * wolverine.AddTex(new Vector2(0, 0));
             * wolverine.AddVertex(new Vector2(0.2f, 1));
             * wolverine.AddTex(new Vector2(0.125f, 0));
             * wolverine.AddVertex(new Vector2(0.2f, 0));
             * wolverine.AddTex(new Vector2(0.125f, 1));
             * wolverine.Color = Color.Transparent;
             */

            /*
             * Texture swordtexture = TextureLoader.FromFile(device, "../../sword_alpha.png");
             * sword_sprite.Transparent = true;
             * //sword_sprite.P = new Vector2(2,2);
             * sword_sprite.Tex = swordtexture;
             * sword_sprite.AddVertex(new Vector2(1, 0));
             * sword_sprite.AddTex(new Vector2(0,1));
             * sword_sprite.AddVertex(new Vector2(2, 0.5f));
             * sword_sprite.AddTex(new Vector2(1,0.5f));
             * sword_sprite.AddVertex(new Vector2(1, 1));
             * sword_sprite.AddTex(new Vector2(0,0));
             * sword_sprite.Color = Color.Transparent;
             */
            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: o2themar/CSE471Project3
        public Game()
        {
            InitializeComponent();

            if (!InitializeDirect3D())
            {
                return;
            }

            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);

            string fileName    = "mars.bmp";
            string bg_fileName = "bg_image.bmp";

            background = new Background(device, playingW, playingH, bg_fileName);

            // Add files for polygons here
            string pentegonfile  = "../../pentagon.txt";
            string trianglefile  = "../../triangle.txt";
            string trapizoidfile = "../../trapizoid.txt";
            string arrowfile     = "../../arrow.txt";
            string tboxfile      = "../../tbox.txt";

            audio = new GameAudio(this);

            score = new Score(device);

            lives = new Lives(device);
            lives.lives_number = 3;         // Set life count to 3

            game_over = new GameOver(device);

            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            Polygon floor = new Polygon();

            floor.AddVertex(new Vector2(0, 1));
            floor.AddVertex(new Vector2(playingW, 1));
            floor.AddVertex(new Vector2(playingW, 0.9f));
            floor.AddVertex(new Vector2(0, 0.9f));
            floor.Color = Color.CornflowerBlue;
            world.Add(floor);


            Polygon ceil = new Polygon();

            ceil.AddVertex(new Vector2(0, 1));
            ceil.AddVertex(new Vector2(playingW, 1));
            ceil.AddVertex(new Vector2(playingW, 0.9f));
            ceil.AddVertex(new Vector2(0, 0.9f));
            ceil.Color = Color.CornflowerBlue;
            world.Add(ceil);

            //AddObstacle(2, 3, 1.7f, 1.9f, Color.Crimson);
            //AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            //AddObstacle(5, 6, 2.2f, 2.4f, Color.BurlyWood);
            //AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            //AddObstacle(6.5f, 7.5f, 2.5f, 2.7f, Color.Chocolate);

            Platform platform = new Platform();

            platform.AddVertex(new Vector2(18.2f, 2));
            platform.AddVertex(new Vector2(18.7f, 2));
            platform.AddVertex(new Vector2(18.7f, 1.8f));
            platform.AddVertex(new Vector2(18.2f, 1.8f));
            platform.Color = Color.CornflowerBlue;
            world.Add(platform);

            //FOR Adding trogdor to the monster polygon
            Texture texture6 = TextureLoader.FromFile(device, "../../trogdor1.png");


            Monster monster = new Monster();

            monster.Tex = texture6;
            monster.AddVertex(new Vector2(3, 1f));
            monster.AddTex(new Vector2(1, 1));
            monster.AddVertex(new Vector2(3, 1.8f));
            monster.AddTex(new Vector2(1, 0));
            monster.AddVertex(new Vector2(4, 1.8f));
            monster.AddTex(new Vector2(0, 0));
            monster.AddVertex(new Vector2(4, 1f));
            monster.AddTex(new Vector2(0, 1));
            monster.Color       = Color.Transparent;
            monster.Transparent = true;
            world.Add(monster);


            Monster monster2 = new Monster();

            monster2.Tex = texture6;
            monster2.AddVertex(new Vector2(6, 1f));
            monster2.AddTex(new Vector2(1, 1));
            monster2.AddVertex(new Vector2(6, 1.8f));
            monster2.AddTex(new Vector2(1, 0));
            monster2.AddVertex(new Vector2(7, 1.8f));
            monster2.AddTex(new Vector2(0, 0));
            monster2.AddVertex(new Vector2(7, 1f));
            monster2.AddTex(new Vector2(0, 1));
            monster2.Color       = Color.Transparent;
            monster2.Transparent = true;
            world.Add(monster2);

            Monster monster3 = new Monster();

            monster3.Tex = texture6;
            monster3.AddVertex(new Vector2(13, 1f));
            monster3.AddTex(new Vector2(1, 1));
            monster3.AddVertex(new Vector2(13, 2f));
            monster3.AddTex(new Vector2(1, 0));
            monster3.AddVertex(new Vector2(14, 2f));
            monster3.AddTex(new Vector2(0, 0));
            monster3.AddVertex(new Vector2(14, 1f));
            monster3.AddTex(new Vector2(0, 1));
            monster3.Color       = Color.Transparent;
            monster3.Transparent = true;
            world.Add(monster3);

            Monster monster4 = new Monster();

            monster4.isBig = true;
            monster4.Tex   = texture6;
            monster4.AddVertex(new Vector2(15, 1f));
            monster4.AddTex(new Vector2(1, 1));
            monster4.AddVertex(new Vector2(15, 2.8f));
            monster4.AddTex(new Vector2(1, 0));
            monster4.AddVertex(new Vector2(16, 2.8f));
            monster4.AddTex(new Vector2(0, 0));
            monster4.AddVertex(new Vector2(16, 1f));
            monster4.AddTex(new Vector2(0, 1));
            monster4.Color       = Color.Transparent;
            monster4.Transparent = true;
            world.Add(monster4);


            Monster monster5 = new Monster();

            monster5.Tex   = texture6;
            monster5.isBig = true;
            monster5.AddVertex(new Vector2(19, 1f));
            monster5.AddTex(new Vector2(1, 1));
            monster5.AddVertex(new Vector2(19, 2.3f));
            monster5.AddTex(new Vector2(1, 0));
            monster5.AddVertex(new Vector2(21, 2.3f));
            monster5.AddTex(new Vector2(0, 0));
            monster5.AddVertex(new Vector2(21, 1f));
            monster5.AddTex(new Vector2(0, 1));
            monster5.Color       = Color.Transparent;
            monster5.Transparent = true;
            world.Add(monster5);

            Monster monster6 = new Monster();

            monster6.Tex   = texture6;
            monster6.is748 = true;
            monster6.AddVertex(new Vector2(21, 1f));
            monster6.AddTex(new Vector2(1, 1));
            monster6.AddVertex(new Vector2(21, 3f));
            monster6.AddTex(new Vector2(1, 0));
            monster6.AddVertex(new Vector2(23, 3f));
            monster6.AddTex(new Vector2(0, 0));
            monster6.AddVertex(new Vector2(23, 1f));
            monster6.AddTex(new Vector2(0, 1));
            monster6.Color       = Color.Transparent;
            monster6.Transparent = true;
            world.Add(monster6);

            Monster monster7 = new Monster();

            monster7.Tex = texture6;
            monster7.is2 = true;
            monster7.AddVertex(new Vector2(28, 1f));
            monster7.AddTex(new Vector2(1, 1));
            monster7.AddVertex(new Vector2(28, 4f));
            monster7.AddTex(new Vector2(1, 0));
            monster7.AddVertex(new Vector2(31, 4f));
            monster7.AddTex(new Vector2(0, 0));
            monster7.AddVertex(new Vector2(31, 1f));
            monster7.AddTex(new Vector2(0, 1));
            monster7.Color       = Color.Transparent;
            monster7.Transparent = true;
            world.Add(monster7);


            Texture         texture = TextureLoader.FromFile(device, "../../metal.bmp");
            PolygonTextured pt      = new PolygonTextured();

            pt.Tex = texture;

            /*
             * pt.AddVertex(new Vector2(1.2f, 3.5f));
             * pt.AddTex(new Vector2(0, 1));
             * pt.AddVertex(new Vector2(1.9f, 3.5f));
             * pt.AddTex(new Vector2(0, 0));
             * pt.AddVertex(new Vector2(1.9f, 3.3f));
             * pt.AddTex(new Vector2(1, 0));
             * pt.AddVertex(new Vector2(1.2f, 3.3f));
             * pt.AddTex(new Vector2(1, 1));
             * pt.Color = Color.Transparent;
             * world.Add(pt);*/

            ReadFileAndTexture(pentegonfile, pt, 1f, 0f);
            pt.Color    = Color.Transparent;
            pt.ismapped = true;
            world.Add(pt);


            Texture         texture2 = TextureLoader.FromFile(device, "../../black_dots.bmp");
            PolygonTextured pt2      = new PolygonTextured();

            pt2.Tex      = texture2;
            pt2.ismapped = true;
            ReadFileAndTexture(trianglefile, pt2, 3, .5f);
            pt2.Color = Color.Transparent;
            world.Add(pt2);


            Texture         texture3 = TextureLoader.FromFile(device, "../../metal.bmp");
            PolygonTextured pt3      = new PolygonTextured();

            pt3.Tex      = texture3;
            pt3.ismapped = true;
            ReadFileAndTexture(trapizoidfile, pt3, 5, .8f);
            pt3.Color = Color.Transparent;
            world.Add(pt3);


            Texture         texture4 = TextureLoader.FromFile(device, "../../flower.bmp");
            PolygonTextured pt4      = new PolygonTextured();

            pt4.Tex      = texture4;
            pt4.ismapped = true;
            ReadFileAndTexture(arrowfile, pt4, 7f, 0);
            pt4.Color = Color.Transparent;
            world.Add(pt4);


            Texture         texture5 = TextureLoader.FromFile(device, "../../lightning.bmp");
            PolygonTextured pt5      = new PolygonTextured();

            pt5.Tex      = texture5;
            pt5.ismapped = true;
            ReadFileAndTexture(tboxfile, pt5, 9, 0);
            pt5.Color = Color.Transparent;
            world.Add(pt5);


            Texture spritetexture = TextureLoader.FromFile(device, "../../guy8.bmp");

            player.P           = new Vector2(0.5f, 1);
            player.Tex         = spritetexture;
            player.Transparent = true;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color = Color.Transparent;

            stood = true;
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: bonnenbe/cse471proj3
        public Game()
        {
            InitializeComponent();

            if (!InitializeDirect3D())
            {
                return;
            }
            score = new Score();
            score.start();
            end = false;

            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);

            background = new Background(device, playingW, playingH);

            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            Polygon floor = new Polygon();

            floor.AddVertex(new Vector2(0, .1f));
            floor.AddVertex(new Vector2(playingW, .1f));
            floor.AddVertex(new Vector2(playingW, 0));
            floor.AddVertex(new Vector2(0, 0));
            floor.Color = Color.CornflowerBlue;
            world.Add(floor);

            AddObstacle(2, 3, 1.7f, 1.9f, Color.Crimson);
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 2.2f, 2.4f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(6.5f, 7.5f, 2.5f, 2.7f, Color.Chocolate);

            Texture         texture = TextureLoader.FromFile(device, "../../stone08.bmp");
            PolygonTextured pt      = new PolygonTextured();

            pt.Tex = texture;
            pt.AddVertex(new Vector2(1.2f, 3.5f));
            pt.AddTex(new Vector2(0, 1));
            pt.AddVertex(new Vector2(1.9f, 3.5f));
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(1.9f, 3.3f));
            pt.AddTex(new Vector2(1, 0));
            pt.AddVertex(new Vector2(1.2f, 3.3f));
            pt.AddTex(new Vector2(1, 1));
            pt.Color = Color.Transparent;
            world.Add(pt);

            Texture spritetexture = TextureLoader.FromFile(device, "../../sprite_guy.png");

            player.Tex = spritetexture;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, .8f));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, .8f));
            player.Color       = Color.Transparent;
            player.Transparent = true;
            player.P           = new Vector2(0.5f, .1f);

            Texture skytexture = TextureLoader.FromFile(device, "../../night-sky.png");

            sky.Tex = skytexture;
            sky.AddVertex(new Vector2(0, 0));
            sky.AddTex(new Vector2(0, 1));
            sky.AddVertex(new Vector2(0, playingH));
            sky.AddTex(new Vector2(0, 0));
            sky.AddVertex(new Vector2((float)Width / (float)Height * playingH, playingH));
            sky.AddTex(new Vector2(1, 0));
            sky.AddVertex(new Vector2((float)Width / (float)Height * playingH, 0));
            sky.AddTex(new Vector2(1, 1));

            AddTriangle(new Vector2(1.5f, 1.1f), 1.5f, .2f, "../../crazy.png");
            AddTriangle(new Vector2(3f, 2.3f), 1, .6f, "../../irontop.png");
            AddTriangle(new Vector2(4f, 2.5f), .8f, .5f, "../../bluething.jpg");
            AddTriangle(new Vector2(5f, 3f), .2f, .4f, "../../stone08.bmp");
            AddTriangle(new Vector2(6f, 2f), 1.2f, .35f, "../../planet.png");
            AddTriangle(new Vector2(7f, 4f), 1.11f, 1, "../../irontop.png");
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: klugaman/CSE471
        public Game()
        {
            InitializeComponent();
            if (!InitializeDirect3D())
            {
                return;
            }

            sounds = new GameSound(this);
            sounds.Victory();

            font = new Microsoft.DirectX.Direct3D.Font(device,                         // Device we are drawing on
                                                       20,                             // Font height in pixels
                                                       0,                              // Font width in pixels or zero to match height
                                                       FontWeight.Bold,                // Font weight (Normal, Bold, etc.)
                                                       0,                              // mip levels (0 for default)
                                                       false,                          // italics?
                                                       CharacterSet.Default,           // Character set to use
                                                       Precision.Default,              // The font precision, try some of them...
                                                       FontQuality.Default,            // Quality?
                                                       PitchAndFamily.FamilyDoNotCare, // Pitch and family, we don't care
                                                       "Arial");                       // And the name of the font



            // To create a rectangle
            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);
            background = new Background(device, playingW, playingH);


            //draw floor /////////////////////////////////////////////////////////////
            Texture floor = TextureLoader.FromFile(device, "../../../floor.jpg");

            AddTexture(0, playingW / 3, 0, 1, Color.Transparent, floor, 0, 1, 0, 1);

            Texture poolTexture = TextureLoader.FromFile(device, "../../../pool.png");

            AddBadPoly(playingW / 3, playingW / 3 * (1 + 0.5f), 0, 0.7f, Color.Transparent, poolTexture, 0, 1, 0, 1);

            AddTexture(playingW / 3 * (1 + 0.5f), playingW, 0, 1, Color.Transparent, floor, 0, 1, 0, 1);


            //create a platform
            AddPlatform(3.2f, 3.9f, 1.8f, 2, Color.CornflowerBlue);

            //create a platform
            AddPlatform2(playingW / 3, playingW / 3 + 0.7f, 0.8f, 1, Color.Black);

            AddCoins();


            Texture c1 = TextureLoader.FromFile(device, "../../../candy1.png");
            Texture c2 = TextureLoader.FromFile(device, "../../../candy2.png");

            AddBadPoly(13.1f, 13.9f, 3.2f, 3.4f, Color.Transparent, c1, 0.3f, 1, 0.55f, 0.85f);

            AddBadPoly(7.1f, 8.1f, 2.2f, 2.8f, Color.Transparent, c2, 0.2f, 1, 0.05f, 0.45f);

            AddBadPoly(26, 27, 1.5f, 2.1f, Color.Transparent, c2, 0.2f, 1, 0.05f, 0.45f);

            AddObstacle(27.1f, 27.7f, 3.0f, 3.2f, Color.BlanchedAlmond);

            /////////////////////////////////////////////////////////////////////////////////////////////////////



            ////Game
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 1.4f, 1.6f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(8.5f, 9.5f, 2.5f, 2.7f, Color.Brown);


            AddObstacle(10.5f, 11.5f, 1.5f, 1.7f, Color.AliceBlue);

            ///add

            AddObstacle(11.5f, 12.5f, 2.2f, 2.4f, Color.PeachPuff);
            // AddObstacle(13.5f, 15f, 3.2f, 3.4f, Color.BlanchedAlmond);
            AddObstacle(14.5f, 15.5f, 2f, 2.2f, Color.Aqua);

            AddObstacle(22.5f, 24f, 3.0f, 3.2f, Color.Crimson);//red
            AddObstacle(29.1f, 29.9f, 2.5f, 2.8f, Color.Chocolate);



            Platform platform = new Platform();

            platform.AddVertex(new Vector2(3.2f, 2));
            platform.AddVertex(new Vector2(3.9f, 2));
            platform.AddVertex(new Vector2(3.9f, 1.8f));
            platform.AddVertex(new Vector2(3.2f, 1.8f));
            platform.Color = Color.Black;
            world.Add(platform);


            ///OBJECT1
            Texture weird_texture = TextureLoader.FromFile(device, "../../../green.jpg");
            Weird   wd            = new Weird();

            wd.Tex = weird_texture;
            //triangle  offset=0
            wd.AddVertex(new Vector2(1.5f, 1.1f));
            wd.AddVertex(new Vector2(1f, 1.5f));
            wd.AddVertex(new Vector2(2f, 1.5f));
            world.Add(wd);



            ///OBJECT2
            Texture         texture = TextureLoader.FromFile(device, "../../../stone08.bmp");
            PolygonTextured pt      = new PolygonTextured();

            pt.Tex = texture;
            pt.AddVertex(new Vector2(17.5f, 1f));
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(17f, 1.5f));
            pt.AddTex(new Vector2(0, 1));

            pt.AddVertex(new Vector2(19f, 1.5f));
            pt.AddTex(new Vector2(1, 1));

            pt.AddVertex(new Vector2(18.5f, 1f));
            pt.AddTex(new Vector2(1, 0));



            pt.Color = Color.Transparent;
            world.Add(pt);


            ///OBJECT3
            Texture         texture3 = TextureLoader.FromFile(device, "../../../brown.jpg");
            PolygonTextured pt3      = new PolygonTextured();

            pt3.Tex = texture3;
            pt3.AddVertex(new Vector2(20, 2.7f));            //A
            pt3.AddTex(new Vector2(0, 1));
            pt3.AddVertex(new Vector2(21, 2.7f));            //B
            pt3.AddTex(new Vector2(0.5f, 0));
            pt3.AddVertex(new Vector2(21, 2.5f));            //C
            pt3.AddTex(new Vector2(1, 0.5f));
            pt3.AddVertex(new Vector2((20 + 21) / 2.0f, 2)); //D
            pt3.AddTex(new Vector2(1, 1));
            pt3.AddVertex(new Vector2(20, 2.5f));
            pt3.AddTex(new Vector2(0, 0.5f));
            world.Add(pt3);



            ///Object4
            Texture         texture4 = TextureLoader.FromFile(device, "../../../green.jpg");
            PolygonTextured pt4      = new PolygonTextured();

            pt4.Tex = texture4;


            pt4.AddVertex(new Vector2(5.375f, 1f));
            pt4.AddTex(new Vector2(1, 0.5f));
            pt4.AddVertex(new Vector2(5f, 1.2f));
            pt4.AddTex(new Vector2(0, 0));
            pt4.AddVertex(new Vector2(5.5f, 1.4f));
            pt4.AddTex(new Vector2(0, 0.5f));
            pt4.AddVertex(new Vector2(5.5f, 1.2f));
            pt4.AddTex(new Vector2(0.5f, 0));
            pt4.AddVertex(new Vector2(6f, 1.2f));
            pt4.AddTex(new Vector2(0.5f, 0.5f));
            pt4.AddVertex(new Vector2(5.625f, 1f));
            pt4.AddTex(new Vector2(0.5f, 1));


            world.Add(pt4);


            Texture spritetexture = TextureLoader.FromFile(device, "../../../guy8.bmp");

            player.Transparent = true;
            player.P           = new Vector2(0.5f, 1);
            player.Tex         = spritetexture;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color = Color.Transparent;
            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;
        }
コード例 #7
0
        public void AddEnemy(Vector2 p, int type)
        {
            GameSprite enemy = new GameSprite();

            Texture enemytexture;

            switch (type)
            {
            case 2:
                enemy.AddVertex(new Vector2(-0.2f, 0.09f));
                enemy.AddVertex(new Vector2(-0.065f, 0.15f));
                enemy.AddVertex(new Vector2(0.065f, 0.15f));
                enemy.AddVertex(new Vector2(0.2f, 0.09f));
                enemy.AddVertex(new Vector2(0.2f, -0.15f));
                enemy.AddVertex(new Vector2(-0.2f, -0.15f));
                enemytexture = TextureLoader.FromFile(device, "../../enemy2.bmp");
                enemy.Tex    = enemytexture;
                enemy.AddTex(new Vector2(0, 0.2f));
                enemy.AddTex(new Vector2(0.32f, 0.1f));
                enemy.AddTex(new Vector2(0.64f, 0.1f));
                enemy.AddTex(new Vector2(1, 0.2f));
                enemy.AddTex(new Vector2(1, 1));
                enemy.AddTex(new Vector2(0, 1));
                break;

            case 3:
                enemy.AddVertex(new Vector2(-0.2f, 0.07f));
                enemy.AddVertex(new Vector2(-0.07f, 0.2f));
                enemy.AddVertex(new Vector2(0.07f, 0.2f));
                enemy.AddVertex(new Vector2(0.2f, 0.07f));
                enemy.AddVertex(new Vector2(0.2f, -0.2f));
                enemy.AddVertex(new Vector2(-0.2f, -0.2f));
                enemytexture = TextureLoader.FromFile(device, "../../enemy3.bmp");
                enemy.Tex    = enemytexture;
                enemy.AddTex(new Vector2(0, 0.36f));
                enemy.AddTex(new Vector2(0.36f, 0.06f));
                enemy.AddTex(new Vector2(0.64f, 0.06f));
                enemy.AddTex(new Vector2(1, 0.36f));
                enemy.AddTex(new Vector2(1, 1));
                enemy.AddTex(new Vector2(0, 1));
                break;

            case 4:
                enemy.AddVertex(new Vector2(-0.2f, 0));
                enemy.AddVertex(new Vector2(-0.05f, 0.15f));
                enemy.AddVertex(new Vector2(0.05f, 0.15f));
                enemy.AddVertex(new Vector2(0.2f, 0));
                enemy.AddVertex(new Vector2(0.15f, -0.05f));
                enemy.AddVertex(new Vector2(-0.15f, -0.05f));
                enemytexture = TextureLoader.FromFile(device, "../../enemy4.bmp");
                enemy.Tex    = enemytexture;
                enemy.AddTex(new Vector2(0, 0.55f));
                enemy.AddTex(new Vector2(0.32f, 0.14f));
                enemy.AddTex(new Vector2(0.68f, 0.14f));
                enemy.AddTex(new Vector2(1, 0.55f));
                enemy.AddTex(new Vector2(1, 0.8f));
                enemy.AddTex(new Vector2(0, 0.8f));
                break;

            default:
                enemy.AddVertex(new Vector2(-0.2f, 0.15f));
                enemy.AddVertex(new Vector2(0.2f, 0.15f));
                enemy.AddVertex(new Vector2(0.2f, 0));
                enemy.AddVertex(new Vector2(0.15f, -0.15f));
                enemy.AddVertex(new Vector2(-0.15f, -0.15f));
                enemy.AddVertex(new Vector2(-0.2f, 0));
                enemytexture = TextureLoader.FromFile(device, "../../enemy1.bmp");
                enemy.Tex    = enemytexture;
                enemy.AddTex(new Vector2(0, 0));
                enemy.AddTex(new Vector2(1, 0));
                enemy.AddTex(new Vector2(1, 0.5f));
                enemy.AddTex(new Vector2(0.86f, 0.93f));
                enemy.AddTex(new Vector2(0.14f, 0.93f));
                enemy.AddTex(new Vector2(0, 0.5f));
                break;
            }

            enemy.Color       = Color.Transparent;
            enemy.Transparent = true;
            enemy.P           = p;
            //This sets the original velocity.
            //TODO: Figure out how to change Y velocity depending on enemy
            enemy.V = new Vector2(-1.5f, 0);
            enemies.Add(enemy);
        }
コード例 #8
0
        public Game()
        {
            InitializeComponent();
            if (!InitializeDirect3D())
            {
                return;
            }

            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);

            background = new Background(device, playingW + 2, playingH);
            sounds     = new GameSounds(this);

            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            Texture spritetexture = TextureLoader.FromFile(device, "../../ship.bmp");

            player.Tex = spritetexture;

            float L = 0.225f;
            float Y = 0.05f;

            player.AddVertex(new Vector2(-L, L));
            player.AddTex(new Vector2(Y, 0));

            player.AddVertex(new Vector2(0, L));
            player.AddTex(new Vector2(0.5f, 0));

            player.AddVertex(new Vector2(L, 0.005f));
            player.AddTex(new Vector2(1.0f - Y, 0.5f - 0.005f));

            player.AddVertex(new Vector2(L, -0.005f));
            player.AddTex(new Vector2(1.0f - Y, 0.5f + 0.005f));

            player.AddVertex(new Vector2(0, -L));
            player.AddTex(new Vector2(0.5f, 1));

            player.AddVertex(new Vector2(-L, -L));
            player.AddTex(new Vector2(Y, 1));

            player.Color       = Color.Transparent;
            player.Transparent = true;
            player.P           = new Vector2(2f, 2);

            AddEnemy(new Vector2(6, 2), 1);
            AddEnemy(new Vector2(8, 2), 2);
            AddEnemy(new Vector2(10, 2), 3);
            AddEnemy(new Vector2(12, 2), 4);

            //setting up the font
            font = new Microsoft.DirectX.Direct3D.Font(device,                         // Device we are drawing on
                                                       20,                             // Font height in pixels
                                                       0,                              // Font width in pixels or zero to match height
                                                       FontWeight.Bold,                // Font weight (Normal, Bold, etc.)
                                                       0,                              // mip levels (0 for default)
                                                       false,                          // italics?
                                                       CharacterSet.Default,           // Character set to use
                                                       Precision.Default,              // The font precision, try some of them...
                                                       FontQuality.Default,            // Quality?
                                                       PitchAndFamily.FamilyDoNotCare, // Pitch and family, we don't care
                                                       "Terminal");                    // And the name of the font
        }
コード例 #9
0
        //constructor
        public Game()
        {
            InitializeComponent();

            if (!InitializeDirect3D())
            {
                return;
            }

            font = new Microsoft.DirectX.Direct3D.Font(device,                         // Device we are drawing on
                                                       20,                             // Font height in pixels
                                                       0,                              // Font width in pixels or zero to match height
                                                       FontWeight.Bold,                // Font weight (Normal, Bold, etc.)
                                                       0,                              // mip levels (0 for default)
                                                       false,                          // italics?
                                                       CharacterSet.Default,           // Character set to use
                                                       Precision.Default,              // The font precision, try some of them...
                                                       FontQuality.Default,            // Quality?
                                                       PitchAndFamily.FamilyDoNotCare, // Pitch and family, we don't care
                                                       "Arial");                       // And the name of the font


            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);

            background = new Background(device, playingW, playingH);
            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;


            Polygon floor = new Polygon();

            floor.AddVertex(new Vector2(0, 1));
            floor.AddVertex(new Vector2(playingW, 1));
            floor.AddVertex(new Vector2(playingW, 0.9f));
            floor.AddVertex(new Vector2(0, 0.9f));
            floor.Color = Color.CornflowerBlue;
            world.Add(floor);

            AddObstacle(2, 3, 1.7f, 1.9f, Color.Crimson);
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 2.2f, 2.4f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(6.5f, 7.5f, 2.5f, 2.7f, Color.Chocolate);


            //create a platform
            AddPlatform(3.2f, 3.9f, 1.8f, 2, Color.CornflowerBlue);


            //load the texture and create an object
            Texture texture = TextureLoader.FromFile(device, "../../../stone08.bmp");

            AddTexture(1.2f, 1.9f, 3.3f, 3.5f, Color.Transparent, texture, 0, 1, 0, 1);

            Texture spritetexture = TextureLoader.FromFile(device, "../../../guy8.bmp");

            player.Tex = spritetexture;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color       = Color.Transparent;
            player.Transparent = true;
            player.P           = new Vector2(0.5f, 1);

            AddNgon();
        }