static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Game game = new Game(); GameSounds snd = new GameSounds(game); game.setSounds(snd); game.Show(); do { game.Advance(); game.Render(); Application.DoEvents(); } while (game.Created); }
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; }
/// <summary> /// Set the sound object for the game /// </summary> public void setSounds(GameSounds newSnd) { snd = newSnd; }
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 }