private void AddObstacle(float p1, float p2, float p3, float p4, Color color) { Polygon p = new Polygon(); p.AddVertex(new Vector2(p1, p4)); p.AddVertex(new Vector2(p2, p4)); p.AddVertex(new Vector2(p2, p3)); p.AddVertex(new Vector2(p1, p3)); p.Color = color; world.Add(p); }
private void AddObstacle(float left, float right, float bottom, float top, Color color) { Polygon p = new Polygon(); p.AddVertex(new Vector2(left, bottom)); p.AddVertex(new Vector2(left, top)); p.AddVertex(new Vector2(right, top)); p.AddVertex(new Vector2(right, bottom)); p.Color = color; world.Add(p); }
public void AddObstacle(float left, float right, float bottom, float top, Color color) { Polygon newpoly = new Polygon(); newpoly.AddVertex(new Vector2(left, bottom)); newpoly.AddVertex(new Vector2(left, top)); newpoly.AddVertex(new Vector2(right, top)); newpoly.AddVertex(new Vector2(right, bottom)); newpoly.Color = color; world.Add(newpoly); }
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(); }
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; }
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; }
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"); }
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, playingH); score = new Score(device); lives = new Lives(device); lives.lives_number = 3; game_over = new GameOver(device); //create 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 "Arial"); // And the name of the font // 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); 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.CornflowerBlue; 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"); 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; }
public void AddObstacle(float left, float right, float bottom, float top, Color color) { Polygon newpoly = new Polygon(); newpoly.AddVertex(new Vector2(left, bottom)); newpoly.AddVertex(new Vector2(left, top)); newpoly.AddVertex(new Vector2(right, top)); newpoly.AddVertex(new Vector2(right, bottom)); newpoly.Color = color; world.Add(newpoly); }
//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(); }