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; 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; }