void spawnzombie(int zombienumber, float zposition) { zombies[zombienumber] = new staticmesh(Content, "zombie", 3f, new Vector3(randomiser.Next(1600) - 800, 0, randomiser.Next(10000, 50000) + zposition), new Vector3(0, 0, 0), new Vector3(0, 0, -(randomiser.Next(10, 50)))); zombies[zombienumber].bboxsize = new Vector3(50, 300, 50); zombies[zombienumber].updateobject(); }
void reset() { gameover = false; gameruntime = 0; score = 0; health = 6; playerchar.position = new Vector3(0, 0, 0); playerchar.rotation = new Vector3(0, 0, 0); // Load the 3D models for the static objects in the game from the ContentManager for (int i = 0; i < numberofgrounds; i++) { ground[i] = new staticmesh(Content, "groundaxa", 10f, new Vector3(0, -40, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0)); if (i > 0) { ground[i].position.Z += ground[i - 1].position.Z + 800 * ground[i - 1].size; } } for (int i = 0; i < numberofbullets; i++) { playerbullet[i] = new staticmesh(Content, "bullet", 1f, new Vector3(playerchar.position.X, playerchar.position.Y, playerchar.position.Z), new Vector3(0, 0, 0), new Vector3(0, 0, 0)); playerbullet[i].radius = 30; playerbullet[i].visible = false; } for (int i = 0; i < numberofwalls; i++) { leftwall[i] = new staticmesh(Content, "wallaxa", 10f, new Vector3(-1000, -100, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0)); rightwall[i] = new staticmesh(Content, "wallaxa", 10f, new Vector3(1000, -100, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 0)); if (i > 0) { leftwall[i].position.Z += leftwall[i - 1].position.Z + 800 * leftwall[i - 1].size; rightwall[i].position.Z = leftwall[i].position.Z; } } for (int i = 0; i < numberofzombs; i++) { spawnzombie(i, 1000); zombies[i].bboxsize = new Vector3(50, 300, 50); zombies[i].updateobject(); } }
void reset() { gameover = false; gameruntime = 0; score = 0; // Initialise robot1 object robot = new model3d(Content, "r2d2v2", 2f, new Vector3(0, 0, 0), new Vector3(0, 0, 0), 0.002f, 0.06f, 10); // Load the 3D models for the static objects in the game from the ContentManager for (int i = 0; i < numberofgrounds; i++) { ground[i] = new staticmesh(Content, "long_ground", 10f, new Vector3(0, -40, 0), new Vector3(0, 0, 0)); if (i > 0) { ground[i].position.Z += ground[i - 1].position.Z + 800 * ground[i - 1].size; } } for (int i = 0; i < numberofwalls; i++) { leftwall[i] = new staticmesh(Content, "wall", 10f, new Vector3(-1000, -40, 0), new Vector3(0, 0, 0)); rightwall[i] = new staticmesh(Content, "wall", 10f, new Vector3(1000, -40, 0), new Vector3(0, 0, 0)); if (i > 0) { leftwall[i].position.Z += leftwall[i - 1].position.Z + 800 * leftwall[i - 1].size; rightwall[i].position.Z = leftwall[i].position.Z; } } for (int i = 0; i < numberoftrees; i++) { if (i % 2 == 0) { tree[i] = new staticmesh(Content, "tree", (float)(randomiser.Next(20) + 1) / 10, new Vector3(randomiser.Next(1600) - 800, 0, randomiser.Next(40000) + 1000), new Vector3(0, randomiser.Next(7), 0)); } else { tree[i] = new staticmesh(Content, "lamppost", (float)(randomiser.Next(20) + 1) / 3, new Vector3(randomiser.Next(1600) - 800, 0, randomiser.Next(40000) + 1000), new Vector3(0, randomiser.Next(7), 0)); tree[i].position.Y = tree[i].size * 40; } } }
void reset() { // Reset everything for a new game gameover = false; uservehicle.position = new Vector3(1000, 0, 1000); uservehicle.rotation = new Vector3(0, 0, 0); uservehicle.velocity = new Vector3(0, 0, 0); // Randomly intialise trees and lampposts for (int i = 0; i < numberoftrees; i++) { if (i % 2 == 0) { tree[i] = new staticmesh(Content, "tree", (float)(randomiser.Next(20) + 1) / 10, new Vector3(randomiser.Next(6000) - 3000, 0, randomiser.Next(6000) - 3000), new Vector3(0, randomiser.Next(7), 0)); } else { tree[i] = new staticmesh(Content, "lamppost", (float)(randomiser.Next(20) + 1) / 3, new Vector3(randomiser.Next(6000) - 3000, 0, randomiser.Next(6000) - 3000), new Vector3(0, randomiser.Next(7), 0)); tree[i].position.Y = tree[i].size * 40; } } int numbertospawn = 10 + randomiser.Next(100); for (int i = 0; i < numbertospawn; i++) { ufos.Add(new staticmesh(Content, "ship", (float)(1 + randomiser.Next(20) / 10), new Vector3(randomiser.Next(12000) - 6000, 600 + randomiser.Next(3000), randomiser.Next(12000) - 6000), new Vector3(0, 0, 0))); } }
// Reset values for the start of a new game void reset() { gameover = false; // Load the 3D models for the static objects in the game from the ContentManager ground = new staticmesh(Content, "sground", 100f, new Vector3(0, -40, 0), new Vector3(0, 0, 0)); // Initialise robot1 object robot = new model3d(Content, "r2d2v2", 2f, new Vector3(1000, 0, 1000), new Vector3(0, 0, 0), 0.002f, 0.05f, 10); for (int i = 0; i < numberoftrees; i++) { if (i % 2 == 0) { tree[i] = new staticmesh(Content, "tree", (float)(randomiser.Next(20) + 1) / 10, new Vector3(randomiser.Next(6000) - 3000, 0, randomiser.Next(6000) - 3000), new Vector3(0, randomiser.Next(7), 0)); tree[i].position.Y = tree[i].radius / 2; } else { tree[i] = new staticmesh(Content, "lamppost", (float)(randomiser.Next(20) + 1) / 3, new Vector3(randomiser.Next(6000) - 3000, 0, randomiser.Next(6000) - 3000), new Vector3(0, randomiser.Next(7), 0)); tree[i].position.Y = tree[i].size * 40; } } tree[50] = new staticmesh(Content, "tank", (float)(randomiser.Next(20) + 1) / 10, new Vector3(randomiser.Next(6000), 140, randomiser.Next(6000)), new Vector3(0, randomiser.Next(7), 0)); tree[50].position.Y = tree[50].radius; tree[51] = new staticmesh(Content, "ship", (float)(randomiser.Next(20) + 1) / 10, new Vector3(randomiser.Next(6000) - 3000, 1000, randomiser.Next(6000) - 3000), new Vector3(0, randomiser.Next(7), 0)); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); if (File.Exists(@"highscore.txt")) { String line; StreamReader sr = new StreamReader(@"highscore.txt"); line = sr.ReadLine(); sr.Close(); line = line.Trim(); for (int i = 0; i < numberofhighscores; i++) highscore[i] = (int)Convert.ToDecimal(line); } cameraposition = new Vector3(1000, 100, 10); cameralookat = new Vector3(0, 400, 0); aspectratio = (float)displaywidth / (float)displayheight; ground = new staticmesh(Content, "sground", 100f, new Vector3(0, -40, 0), new Vector3(0, 0, 0)); robot = new model3d(Content, "r2d2v2", 2f, new Vector3(1000, 0, 1000), new Vector3(0, 0, 0), 0.05f, 0.5f, 10); for (int i = 0; i < numberoftrees; i++) { if (i % 2 == 0) trees[i] = new staticmesh(Content, "tree", (float)(randomiser.Next(20) + 1) / 10, new Vector3(randomiser.Next(6000) - 3000, 0, randomiser.Next(6000) - 3000), new Vector3(0, randomiser.Next(7), 0)); else { trees[i] = new staticmesh(Content, "lamppost", (float)(randomiser.Next(20) + 1) / 3, new Vector3(randomiser.Next(6000) - 3000, 0, randomiser.Next(6000) - 3000), new Vector3(0, randomiser.Next(70), 0)); trees[i].position.Y = trees[i].size * 40; } } background = new graphics2d(Content, "Background for Menus", displaywidth, displayheight); mousepointer1 = new sprites2d(Content, "X-Games-Cursor", 0, 0, 0.15f, Color.White, true, randomiser); mousepointer2 = new sprites2d(Content, "X-Games-Cursor-Highlight", 0, 0, 0.15f, Color.White, true,randomiser); menuoptions[0, 0] = new sprites2d(Content, "Start-Normal", displaywidth / 2, 200, 1, Color.White, true,randomiser); menuoptions[0, 1] = new sprites2d(Content, "Start-Selected", displaywidth / 2, 200, 1,Color.White, true,randomiser); menuoptions[1, 0] = new sprites2d(Content, "Options-Normal", displaywidth / 2, 300, 1, Color.White, true,randomiser); menuoptions[1, 1] = new sprites2d(Content, "options-Selected", displaywidth / 2, 300, 1, Color.White, true,randomiser); menuoptions[2, 0] = new sprites2d(Content, "High-Score-Normal", displaywidth / 2, 400, 1, Color.White, true,randomiser); menuoptions[2, 1] = new sprites2d(Content, "High-Score-Selected", displaywidth / 2, 400, 1, Color.White, true,randomiser); menuoptions[3, 0] = new sprites2d(Content, "Exit-Normal", displaywidth / 2, 500, 1, Color.White, true,randomiser); menuoptions[3, 1] = new sprites2d(Content, "Exit-Selected", displaywidth / 2, 500, 1, Color.White, true,randomiser); for (int i = 0; i < numberofoptions; i++) menuoptions[i, 0].updateobject(); mainfont = Content.Load<SpriteFont>("mainfont"); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here mainfont = Content.Load <SpriteFont>("quartz4"); // Load the quartz4 font background = new graphic2d(Content, "Background for Menus", displaywidth, displayheight); up = new sprite2d(Content, "up", 105, displayheight - 180, 0.3f, Color.White, true); down = new sprite2d(Content, "down", 105, displayheight - 50, 0.3f, Color.White, true); left = new sprite2d(Content, "left", 50, displayheight - 115, 0.3f, Color.White, true); right = new sprite2d(Content, "right", 160, displayheight - 115, 0.3f, Color.White, true); left2 = new sprite2d(Content, "left", displaywidth - 180, displayheight - 100, 0.3f, Color.White, true); right2 = new sprite2d(Content, "right", displaywidth - 60, displayheight - 100, 0.3f, Color.White, true); menuoptions[0] = new sprite2d(Content, "player1", displaywidth / 2, 150, 1, Color.White, true); menuoptions[1] = new sprite2d(Content, "options", displaywidth / 2, 220, 1, Color.White, true); menuoptions[2] = new sprite2d(Content, "highscore", displaywidth / 2, 290, 1, Color.White, true); menuoptions[3] = new sprite2d(Content, "exit", displaywidth / 2, 360, 1, Color.White, true); // Load the 3D models for the static objects in the game from the ContentManager ground = new staticmesh(Content, "sground", 100f, new Vector3(0, -40, 0), new Vector3(0, 0, 0)); // Initialise robot1 object uservehicle = new model3d(Content, "tiefighter", 2f, new Vector3(1000, 0, 1000), new Vector3(0, 0, 0), 0.002f, 0.06f, 10); /* * tree[50] = new staticmesh(Content, "tank", (float)(randomiser.Next(20) + 1) / 10, * new Vector3(randomiser.Next(6000) - 3000, 200, randomiser.Next(6000) - 3000), * new Vector3(0, randomiser.Next(7), 0)); * tree[51] = new staticmesh(Content, "ship", (float)(randomiser.Next(20) + 1) / 10, * new Vector3(randomiser.Next(6000) - 3000, 200, randomiser.Next(6000) - 3000), * new Vector3(0, randomiser.Next(7), 0)); * tree[52] = new staticmesh(Content, "stars", 10, * new Vector3(randomiser.Next(6000) - 3000, 200, randomiser.Next(6000) - 3000), * new Vector3(0, randomiser.Next(7), 0)); */ // Load High Scores in using (IsolatedStorageFile savegamestorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (savegamestorage.FileExists("highscores.txt")) { using (IsolatedStorageFileStream fs = savegamestorage.OpenFile("highscores.txt", System.IO.FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { string line; for (int i = 0; i < numberofhighscores; i++) { line = sr.ReadLine(); highscores[i] = Convert.ToInt32(line); } sr.Close(); } } } } // Sort high scores Array.Sort(highscores); Array.Reverse(highscores); }