public override void Update(GameTime gameTime) { base.Update(gameTime); TimerGameObject timer = this.Find("timer") as TimerGameObject; Player player = this.Find("player") as Player; // check if we died if (!player.IsAlive) { timer.Running = false; } // check if we ran out of time if (timer.GameOver) { player.Explode(); } // check if we won if (this.Completed && timer.Running) { player.LevelFinished(); timer.Running = false; } }
public override void Update(GameTime gameTime) { base.Update(gameTime); TimerGameObject timer = Find("timer") as TimerGameObject; Player player = Find("player") as Player; // check if we died if (!player.IsAlive) { timer.Running = false; } // check if we ran out of time if (timer.GameOver) { player.Explode(); } // check if we won if (Completed && timer.Running) { player.LevelFinished(); timer.Running = false; } //Update the camera and the levelsize for current level camera.Update(gameTime, player); camera.levelSize = levelSize; //----------------------------------------------------- }
public override void Update(GameTime gameTime) { base.Update(gameTime); TimerGameObject timer = Find("timer") as TimerGameObject; Player player = Find("player") as Player; // check if we died if (!player.IsAlive) { timer.Running = false; } // check if we ran out of time if (timer.GameOver) { player.Explode(); } // check if we won if (Completed && timer.Running) { player.LevelFinished(); timer.Running = false; } position.X = -player.Position.X + GameEnvironment.Screen.X / 2; }
public Level(int levelIndex) { // load the backgrounds GameObjectList backgrounds = new GameObjectList(0, "backgrounds"); SpriteGameObject backgroundSky = new SpriteGameObject("Backgrounds/spr_sky"); backgroundSky.Position = new Vector2(0, GameEnvironment.Screen.Y - backgroundSky.Height); backgrounds.Add(backgroundSky); // add a few random mountains for (int i = 0; i < 9; i++) //9 mountains in 9 layers for now { SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), i); //changed 1 to i mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * (GameEnvironment.Screen.X + 600) - mountain.Width / 2, //+600 för nu GameEnvironment.Screen.Y - mountain.Height); if (mountain.Layer <= 2) //9 mountains into 3 different layers with 3 different speeds { mountain.Layer = 0; //scroll is to illustrate the speed of the mountains mountain.Scroll = 0.1f; } else if (mountain.Layer <= 5) { mountain.Layer = 1; mountain.Scroll = 0.05f; } else { mountain.Layer = 2; mountain.Scroll = 0.01f; } backgrounds.Add(mountain); /* SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), 1); * mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Width / 2, * GameEnvironment.Screen.Y - mountain.Height); * backgrounds.Add(mountain); */ } // Clouds clouds = new Clouds(2); // backgrounds.Add(clouds); Add(backgrounds); SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100); timerBackground.Position = new Vector2(10, 10); Add(timerBackground); TimerGameObject timer = new TimerGameObject(101, "timer"); timer.Position = new Vector2(25, 30); Add(timer); quitButton = new Button("Sprites/spr_button_quit", 100); quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10); Add(quitButton); Add(new GameObjectList(1, "waterdrops")); Add(new GameObjectList(2, "enemies")); LoadTiles("Content/Levels/" + levelIndex + ".txt"); }
/// <summary>Update the level objects.</summary> public override void Update(GameTime gameTime) { base.Update(gameTime); TimerGameObject timer = Find("timer") as TimerGameObject; Player player = Find("player") as Player; // check if we died if (!player.IsAlive) { timer.Running = false; } // check if we ran out of time if (timer.GameOver) { player.Explode(); } // check if we won if (Completed && timer.Running) { player.LevelFinished(); timer.Running = false; } foreach (Projectile projectile in projectiles) { projectile.Update(gameTime, Find("tiles") as TileField); } // clear unactive projectiles (no memory dump) projectiles.RemoveAll(unActiveProjectile); }
public Level(int levelIndex) { // load the backgrounds GameObjectList backgrounds = new GameObjectList(0, "backgrounds"); SpriteGameObject backgroundSky = new LockedSpriteGameObject("Backgrounds/spr_sky"); backgroundSky.Position = new Vector2(0, GameEnvironment.Screen.Y - backgroundSky.Height); backgrounds.Add(backgroundSky); // add a few random mountains for (int i = 10; i > 0; i--) { newMountainLayer(backgrounds, 3, i * 3 + 7, ((10 - i) * 2)); } Add(backgrounds); SpriteGameObject timerBackground = new LockedSpriteGameObject("Sprites/spr_timer", 100); timerBackground.Position = new Vector2(10, 10); Add(timerBackground); timer = new TimerGameObject(101, "timer"); timer.Position = new Vector2(25, 30); Add(timer); quitButton = new Button("Sprites/spr_button_quit", 100); quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10); Add(quitButton); Add(new GameObjectList(1, "waterdrops")); Add(new GameObjectList(2, "enemies")); LoadTiles("Content/Levels/" + levelIndex + ".txt"); }
/// <summary>Load the level.</summary> public void LoadTiles(string path) { this.path = path; List <string> textlines = new List <string>(); StreamReader fileReader = new StreamReader(path); string line = fileReader.ReadLine(); // first row of the level width = line.Length; // calculated level width while (line != null) { // read all lines textlines.Add(line); line = fileReader.ReadLine(); } height = textlines.Count - 2; // add the hint GameObjectList hintfield = new GameObjectList(100); Add(hintfield); SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1); // hint background hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10); hintfield.Add(hint_frame); TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); // hint text hintText.Text = textlines[textlines.Count - 2]; // last line in the level descriptor hintText.Position = new Vector2(120, 25); hintText.Color = Color.Black; hintfield.Add(hintText); VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); // timeout Add(hintTimer); TimerGameObject timer = new TimerGameObject(101, "timer"); timer.Position = new Vector2(25, 30); timer.TimeLeft = TimeSpan.FromSeconds(double.Parse(textlines[textlines.Count - 1])); Add(timer); // construct the level TileField tiles = new TileField(height, width, 1, "tiles"); Add(tiles); // tile dimentions tiles.CellWidth = 72; cellWidth = 72; tiles.CellHeight = 55; cellHeight = 55; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { Tile t = LoadTile(textlines[y][x], x, y); tiles.Add(t, x, y); } } }
public void LoadTiles(string path) { //Haalt de tekst uit tekstfile int width; List<string> textlines = new List<string>(); StreamReader fileReader = new StreamReader(path); string line = fileReader.ReadLine(); width = line.Length; while (line != null) { textlines.Add(line); line = fileReader.ReadLine(); } //Tijdslimiet i wordt afgelezen uit tekstfile int i = int.Parse(textlines[textlines.Count - 1]); SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100, "timerBackground"); timerBackground.Position = new Vector2(10, 10); this.Add(timerBackground); TimerGameObject timer = new TimerGameObject(i, 101, "timer"); timer.Position = new Vector2(25, 30); this.Add(timer); int height = textlines.Count - 2; //Creëert het speelveld TileField tiles = new TileField(textlines.Count - 2, width, 1, "tiles"); //Plaatst de hintbutton GameObjectList hintfield = new GameObjectList(100, "hintfield"); this.Add(hintfield); string hint = textlines[textlines.Count - 2]; SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1, "hint_frame"); hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10); hintfield.Add(hint_frame); TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2, "hintText"); hintText.Text = hint; hintText.Position = new Vector2(120, 25); hintText.Color = Color.Black; hintfield.Add(hintText); VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); this.Add(hintTimer); //Vult het speelveld met de goede tiles this.Add(tiles); tiles.CellWidth = 72; tiles.CellHeight = 55; for (int x = 0; x < width; ++x) for (int y = 0; y < textlines.Count - 2; ++y) { Tile t = LoadTile(textlines[y][x], x, y); tiles.Add(t, x, y); } levelwidth = width * tiles.CellWidth; levelheight = height * tiles.CellHeight; }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (!finished && isAlive) { if (isOnTheGround) { if (velocity.X == 0) { PlayAnimation("idle"); } else { PlayAnimation("run"); } } else if (velocity.Y < 0) { PlayAnimation("jump"); } TimerGameObject timer = GameWorld.Find("timer") as TimerGameObject; if (walkingOnHot) { timer.Multiplier = 2; } else if (walkingOnIce) { timer.Multiplier = 0.5; } else { timer.Multiplier = 1; } TileField tiles = GameWorld.Find("tiles") as TileField; if (BoundingBox.Top >= tiles.Rows * tiles.CellHeight) { Die(true); } if (Clock <= 0f) //Update de clock { isShooting = false; } else if (Clock > 0f) // Clock voorwaarde { Clock -= 1f; } } DoPhysics(); }
/// <summary>Load the level.</summary> public void LoadTiles(string path) { this.path = path; List<string> textlines = new List<string>(); StreamReader fileReader = new StreamReader(path); string line = fileReader.ReadLine(); // first row of the level width = line.Length; // calculated level width while (line != null) { // read all lines textlines.Add(line); line = fileReader.ReadLine(); } height = textlines.Count - 2; // add the hint GameObjectList hintfield = new GameObjectList(100); Add(hintfield); SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1); // hint background hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10); hintfield.Add(hint_frame); TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); // hint text hintText.Text = textlines[textlines.Count - 2]; // last line in the level descriptor hintText.Position = new Vector2(120, 25); hintText.Color = Color.Black; hintfield.Add(hintText); VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); // timeout Add(hintTimer); TimerGameObject timer = new TimerGameObject(101, "timer"); timer.Position = new Vector2(25, 30); timer.TimeLeft = TimeSpan.FromSeconds(double.Parse(textlines[textlines.Count - 1])); Add(timer); // construct the level TileField tiles = new TileField(height, width, 1, "tiles"); Add(tiles); // tile dimentions tiles.CellWidth = 72; cellWidth = 72; tiles.CellHeight = 55; cellHeight = 55; for (int x = 0; x < width; ++x) for (int y = 0; y < height; ++y) { Tile t = LoadTile(textlines[y][x], x, y); tiles.Add(t, x, y); } }
public Level(int levelIndex) { // load the backgrounds GameObjectList backgrounds = new GameObjectList(0, "backgrounds"); SpriteGameObject backgroundSky = new SpriteGameObject("Backgrounds/spr_sky"); backgroundSky.CameraFollow = false; //blijft staan ten opzichte van de camera backgroundSky.Position = new Vector2(0, GameEnvironment.Screen.Y - backgroundSky.Height); backgrounds.Add(backgroundSky); // add a few random mountains for (int i = 0; i < 5; i++) { SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), i); mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Width / 2, GameEnvironment.Screen.Y - mountain.Height); mountain.ParallaxFollow = true; //layers bergen bewegen anders ten opzichte van elkaar backgrounds.Add(mountain); } Clouds clouds = new Clouds(2); backgrounds.Add(clouds); Add(backgrounds); SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100); timerBackground.Position = new Vector2(10, 10); timerBackground.CameraFollow = false; //timer blijft staan Add(timerBackground); quitButton = new Button("Sprites/spr_button_quit", 100); quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10); quitButton.CameraFollow = false; //quite button blijft staan Add(quitButton); Add(new GameObjectList(1, "waterdrops")); Add(new GameObjectList(2, "enemies")); Add(new GameObjectList(2, "bullets")); //nieuwe bullet Lis aan maken, op Layer twee, aangezien de enemies daar ook zitten. LoadTiles("Content/Levels/" + levelIndex + ".txt"); TimerGameObject timer = new TimerGameObject(time, 101, "timer"); //initialize new timerGameObject timer.Position = new Vector2(25, 30); //new time Object position Add(timer); }
public override void Update(GameTime gameTime) { base.Update(gameTime); // give the bomb the position of the player bomb.PlayerPosition = this.Position; if (!finished && isAlive) { if (isOnTheGround) { if (velocity.X == 0) { PlayAnimation("idle"); } else { PlayAnimation("run"); } } else if (velocity.Y < 0) { PlayAnimation("jump"); } TimerGameObject timer = GameWorld.Find("timer") as TimerGameObject; if (walkingOnHot) { timer.Multiplier = 2; } else if (walkingOnIce) { timer.Multiplier = 0.5; } else { timer.Multiplier = 1; } TileField tiles = GameWorld.Find("tiles") as TileField; if (BoundingBox.Top >= tiles.Rows * tiles.CellHeight) { Die(true); } } DoPhysics(); }
/// <summary>Update the player.</summary> public override void Update(GameTime gameTime) { base.Update(gameTime); if (!finished && isAlive) { if (isOnTheGround) { if (velocity.X == 0) { PlayAnimation("idle"); } else { PlayAnimation("run"); } } else if (velocity.Y < 0) { PlayAnimation("jump"); } TimerGameObject timer = GameWorld.Find("timer") as TimerGameObject; if (walkingOnHot) { timer.Multiplier = 2; } else if (walkingOnIce) { timer.Multiplier = 0.5; } else { timer.Multiplier = 1; } TileField tiles = GameWorld.Find("tiles") as TileField; if (BoundingBox.Top >= tiles.Rows * tiles.CellHeight) { Die(true); } } DoPhysics(); GameEnvironment.ActiveCamera.moveCamera(Position + Center); }
public Level(int levelIndex) { // load the backgrounds GameObjectList backgrounds = new GameObjectList(0, "backgrounds"); SpriteGameObject backgroundSky = new SpriteGameObject("Backgrounds/spr_sky", 0); backgroundSky.Position = new Vector2(0, GameEnvironment.Screen.Y - backgroundSky.Height); backgrounds.Add(backgroundSky); // add a few random mountains for (int i = 0; i < 5; i++) { SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), 3); mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * GameEnvironment.Screen.X - mountain.Width / 2, GameEnvironment.Screen.Y - mountain.Height); backgrounds.Add(mountain); } Clouds clouds = new Clouds(6); backgrounds.Add(clouds); Add(backgrounds); SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 0); timerBackground.Position = new Vector2(10, 10); Add(timerBackground); quitButton = new Button("Sprites/spr_button_quit", 0); quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 0); Add(quitButton); Add(new GameObjectList(1, "waterdrops")); Add(new GameObjectList(2, "enemies")); LoadTiles("Content/Levels/" + levelIndex + ".txt"); //use time set in txt file TimerGameObject timer = new TimerGameObject(time, 0, "timer"); timer.Position = new Vector2(25, 30); Add(timer); }
public Level(int levelIndex) { // load the backgrounds GameObjectList backgrounds = new GameObjectList(0, "backgrounds"); SpriteGameObject background_main = new SpriteGameObject("Backgrounds/spr_sky"); background_main.Position = new Vector2(0, GameEnvironment.Screen.Y - background_main.Height); backgrounds.Add(background_main); SpriteGameObject background_extended = new SpriteGameObject("Backgrounds/spr_sky"); background_extended.Position = new Vector2(background_main.Width, GameEnvironment.Screen.Y - background_main.Height); backgrounds.Add(background_extended); // add a few random mountains for (int i = 0; i < 10; i++) { SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), GameEnvironment.Random.Next(4)+3); mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * (2 * background_main.Width) - mountain.Width / 2, GameEnvironment.Screen.Y - mountain.Height); backgrounds.Add(mountain); } Clouds clouds = new Clouds(4); backgrounds.Add(clouds); this.Add(backgrounds); SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100); timerBackground.Position = new Vector2(10, 10); timerBackground.Meebewegen(); this.Add(timerBackground); TimerGameObject timer = new TimerGameObject(101, "timer"); timer.Position = new Vector2(25, 30); this.Add(timer); quitButton = new Button("Sprites/spr_button_quit", 100); quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10); this.Add(quitButton); this.Add(new GameObjectList(1, "waterdrops")); this.Add(new GameObjectList(2, "enemies")); this.LoadTiles("Content/Levels/" + levelIndex + ".txt"); }
public void LoadTiles(string path) { List <string> textLines = new List <string>(); StreamReader fileReader = new StreamReader(path); string line = fileReader.ReadLine(); int width = line.Length; while (line != null) { textLines.Add(line); line = fileReader.ReadLine(); } GameObjectList hintField = new GameObjectList(100); Add(hintField); string hint = textLines[textLines.Count - 1]; SpriteGameObject hintFrame = new SpriteGameObject("Overlays/spr_frame_hint", 100); hintField.Position = new Vector2((GameEnvironment.Screen.X - hintFrame.Width) / 2, 10); hintField.Add(hintFrame); TextGameObject hintText = new TextGameObject("Fonts/HintFont", 100); hintText.Text = textLines[textLines.Count - 1]; hintText.Position = new Vector2(120, 25); hintText.Color = Color.Black; hintField.Add(hintText); VisibilityTimer hintTimer = new VisibilityTimer(hintField, 1, "hintTimer"); Add(hintTimer); SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100); timerBackground.Position = new Vector2(10, 10); Add(timerBackground); int timerlineoffset = 0; if (int.TryParse(textLines[textLines.Count - 2], out int timerlength)) { TimerGameObject timer = new TimerGameObject(101, "timer", timerlength); timer.Position = new Vector2(25, 30); Add(timer); timerlineoffset = 1; } else { TimerGameObject timer = new TimerGameObject(101, "timer"); timer.Position = new Vector2(25, 30); Add(timer); } TileField tiles = new TileField(textLines.Count - (1 + timerlineoffset), width, 1, "tiles"); Add(tiles); tiles.CellWidth = 72; tiles.CellHeight = 55; for (int x = 0; x < width; ++x) { for (int y = 0; y < textLines.Count - (1 + timerlineoffset); ++y) { Tile t = LoadTile(textLines[y][x], x, y); tiles.Add(t, x, y); } } }