/// <summary> /// RaceState constructor which adds the different gameobjects and lists in the correct order of drawing. /// </summary> public RaceState() { //create background Add(new SpriteGameObject("road")); //create a list for collidable objects Add(bodies = new GameObjectList()); //create user controlled car bodies.Add(player = new Car(new Vector2(920, 1400))); //hardcoded position data from 'Tiled' bodies.Add(barrel = new Barrel(new Vector2(1000, 1600))); //create four opponents for (int i = 0; i < 4; i++) { float x = 1300 - i * 130; //hardcoded position data from 'Tiled' float y = 1400 + i * 50; float speed = 6 - i * 0.5f; float offset = (i - 1.5f) * 20; bodies.Add(new CarNPC(new Vector2(x, y), speed, offset)); } //load scenery new LevelLoader().LoadLevel(this); }
public override void HandleInput(InputHelper inputHelper) { base.HandleInput(inputHelper); if (makePacket) { int rand = GameEnvironment.Random.Next(15); GameObjectList level = this.parent as GameObjectList; SpriteGameObject home = GameWorld.Find("home") as SpriteGameObject; GameObjectList TowerList = GameWorld.Find("towerlist") as GameObjectList; if ((rand == 1 || rand == 2) && spawnVirus == true) { Virus virus = new Virus(this.position + this.Center, this, TowerList, home); level.Add(virus); } else if (rand == 3 && spawnTrojan == true) { Trojan trojan = new Trojan(this.position + this.Center, this, TowerList, home); level.Add(trojan); } else { Packet packet = new Packet(this.position + this.Center, serverColor, type, this, TowerList, home); GameObjectList packetList = level.Find("packetList") as GameObjectList; packetList.Add(packet); } makePacket = false; } }
/// <summary> /// RaceState constructor which adds the different gameobjects and lists in the correct order of drawing. /// </summary> public RaceState() { //create background Add(new SpriteGameObject("road")); //create a list for collidable objects Add(bodies = new GameObjectList()); //create user controlled car bodies.Add(player = new Car(new Vector2(920, 1400))); //hardcoded position data from 'Tiled' //create four opponents for (int i = 0; i < 4; i++) { float x = 1300 - i * 130; //hardcoded position data from 'Tiled' float y = 1400 + i * 50; float speed = 6 - i * 0.5f; float offset = (i - 1.5f) * 20; bodies.Add(new CarNPC(new Vector2(x, y), speed, offset)); } //load scenery new LevelLoader().LoadLevel(this); // put all physics object in array so we can loop trough them later foreach (GameObject gameObject in Children) { if (gameObject is Body) { bodies.Add(gameObject); } } }
/// <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 LoadLevel(string path) { GameObjectList entities = new GameObjectList(2, "entities"); RootList.Add(entities); GameObjectList items = new GameObjectList(1, "items"); entities.Add(items); GameObjectList enemies = new GameObjectList(1, "enemies"); entities.Add(enemies); Camera camera = new Camera("player", 0, "camera"); RootList.Add(camera); GameMouse mouse = new GameMouse(); RootList.Add(mouse); LoadOverlays(); LoadFile(path); }
public PlayingState() { background = new SpriteGameObject("spr_Background", 0, "", 0, 80); this.Add(background); Cursor cursor = new Cursor(2); map = new MapV2(scale, new Point(50, 50)); world.Add(map); player = new BaseEntity("spr_Humanoid", scale, map.RandomFreePositionInMap(), map, world, true, cursor); //Buffs player because else it is to hard player.movementSpeed *= 3; player.maxHealth *= 4; player.health *= 4; world.Add(player); //Adds enemies for (int i = 0; i < map.Columns / 5; i++) { world.Add(new BaseEntity("spr_Humanoid", scale, map.RandomFreePositionInMap(), map, world, false, player)); } this.Add(world); this.Add(new MiniMap(map, player, world, new Point(42, 42), 1, MiniMap.ViewLoc.TopRight)); hud = new HUD(player); this.Add(hud); this.Add(cursor); }
/// <summary>Create the level.</summary> /// <param name="levelIndex">The index of the level.</param> 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); Add(new GameObjectList(1, "waterdrops")); Add(new GameObjectList(2, "enemies")); LoadTiles("Content/Levels/" + levelIndex + ".txt"); // add a few random mountains for (int i = 0; i < 5; i++) { SpriteGameObject mountain = new SpriteGameObject("Backgrounds/spr_mountain_" + (GameEnvironment.Random.Next(2) + 1), 1, "", 0, SpriteGameObject.Backgroundlayer.background); mountain.Position = new Vector2((float)GameEnvironment.Random.NextDouble() * (width * cellWidth) - mountain.Width / 2, (height * cellHeight) - mountain.Height); backgrounds.Add(mountain); } Clouds clouds = new Clouds(2, "", this); backgrounds.Add(clouds); Add(backgrounds); SpriteGameObject timerBackground = new SpriteGameObject("Sprites/spr_timer", 100); timerBackground.Position = new Vector2(10, 10); Add(timerBackground); quitButton = new Button("Sprites/spr_button_quit", 100); quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10); Add(quitButton); }
public Level(int levelIndex) { // load the backgrounds GameObjectList backgrounds = new GameObjectList(0, "backgrounds"); SpriteGameObject backgroundSky = new SpriteGameObject("Backgrounds/spr_sky", 1); 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), (GameEnvironment.Random.Next(3, 5))); 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(4); backgrounds.Add(clouds); Add(backgrounds); quitButton = new Button("Sprites/spr_button_quit", 100); quitButton.Position = new Vector2(GameEnvironment.Screen.X - quitButton.Width - 10, 10); Add(quitButton); Add(new GameObjectList(6, "waterdrops")); Add(new GameObjectList(7, "enemies")); LoadTiles("Content/Levels/" + levelIndex + ".txt"); }
public StatusBar() : base() { clickableObjects = new GameObjectList(); background = new SpriteGameObject("spr_bar"); overHeadArrowsIcon = new ClickableSpriteGameObject("arrow_raining", IconType.OverheadArrowsIcon); rollingBoulderIcon = new ClickableSpriteGameObject("bolder_powerupp", IconType.RollingBoulderIcon); boilingOilIcon = new ClickableSpriteGameObject("spr_keuze_mage", IconType.BoilingOilIcon); moneyCount = new TextGameObject("GameFont"); overHeadArrowsIcon.Position = new Vector2(975, 30); rollingBoulderIcon.Position = new Vector2(1075, 30); boilingOilIcon.Position = new Vector2(1175, 30); moneyCount.Position = new Vector2(800, 30); moneyCount.Text = ""; clickableObjects.Add(overHeadArrowsIcon); clickableObjects.Add(rollingBoulderIcon); clickableObjects.Add(boilingOilIcon); Add(background); Add(overHeadArrowsIcon); Add(rollingBoulderIcon); Add(boilingOilIcon); Add(moneyCount); }
public PainterGameWorld() { background = new SpriteGameObject("spr_background"); scoreBar = new SpriteGameObject("spr_scorebar"); cannon = new Cannon(); canSprites = new GameObjectList(); canSprites.Add(new PaintCan(450f, Color.Red)); canSprites.Add(new PaintCan(575f, Color.Green)); canSprites.Add(new PaintCan(700f, Color.Blue)); scoreText = new TextGameObject("GameFont"); scoreText.Position = new Vector2(5, 7); livesSprites = new GameObjectList(); for(int iLife = 0; iLife < MAX_LIVES; iLife++) { SpriteGameObject life = new SpriteGameObject("spr_lives", 0, iLife.ToString()); life.Position = new Vector2(iLife * life.BoundingBox.Width, scoreBar.Position.Y + scoreBar.BoundingBox.Height + 15); livesSprites.Add(life); } //Add the background sprite to the gameworld Add(background); Add(scoreBar); Add(cannon); Add(canSprites); Add(scoreText); Add(livesSprites); Reset(); }
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"); }
public Level(int levelIndex) { 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.Sprite.SheetHeight); backgrounds.Add(background_main); for (int i = 0; i < 5; i++) { 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.Sprite.SheetWidth / 2, GameEnvironment.Screen.Y - mountain.Sprite.SheetHeight); backgrounds.Add(mountain); } Clouds clouds = new Clouds(2); backgrounds.Add(clouds); this.Add(backgrounds); QuitButton = new Button("Sprites/spr_button_back", 100); QuitButton.Position = new Vector2(10, 10); this.Add(QuitButton); this.Add(new GameObjectList(1, "ZenyS")); this.LoadTiles("Content/Levels/" + levelIndex + ".txt"); GameObjectList ZenyS = this.Find("ZenyS") as GameObjectList; GameScore = new Score(ZenyS); GameScore.Position = new Vector2(GameEnvironment.Screen.X - 60, 10); this.Add(GameScore); }
public Level2() { Console.WriteLine("Level2"); Reset(); timebarSpace = 10.768F; this.Add(new SpriteGameObject("spr_background")); thePlayer = new Player(3, 3); door = new Door(14, 0); goal = new MainGoal(26, 3); xaxis = new Xaxis(8, "Map/spr_horizontal_art_blue"); yaxis = new Yaxis(20, "Map/spr_vertical_art_blue"); Mouse.SetPosition(GameEnvironment.Screen.X / 2, GameEnvironment.Screen.Y / 2); floors = new GameObjectList(); walls = new GameObjectList(); goals = new GameObjectList(); inputScreen = new InputScreen(GameEnvironment.Screen.X / 2 - 64 * 2, GameEnvironment.Screen.Y); inputanswer = new InputAnswer(GameEnvironment.Screen.X / 2 - 64 * 2, GameEnvironment.Screen.Y); timeGround = new SpriteGameObject("Map/time_ground"); guards = new GameObjectList(); lasers = new GameObjectList(); times = new GameObjectList(); score = new Score(12, 20, (int)time); Axis_nums = new Axis_numbers(20, 8); switchBoards = new GameObjectList(); this.Add(floors); this.Add(switchBoards); this.Add(lasers); this.Add(walls); this.Add(door); this.Add(xaxis); this.Add(yaxis); this.Add(Axis_nums); this.Add(goal); this.Add(goals); this.Add(guards); this.Add(thePlayer); this.Add(inputScreen); this.Add(timeGround); this.Add(times); this.Add(score); this.Add(inputanswer); goals.Add(new ExtraGoal(11, 9)); guards.Add(new Guard(new Vector2(3, 13), new Vector2(25, 13))); FloorSetup(); WallSetup(); TimeBarSetup(); SoundSetup(); lasers.Add(new Laser(new Vector2(11, 6), new Vector2(14, 10), Color.Red, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(23, 10), new Vector2(28, 7), Color.Blue, xaxis.gridPos, yaxis.gridPos)); switchBoards.Add(new SwitchBoard(3, 7, Color.Blue)); switchBoards.Add(new SwitchBoard(22, 3, Color.Red)); }
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 void AddToList(int instances) { for (int i = 0; i < instances; i++) { gameObjects.Add(new GameObject()); gameObjects[i].SetActive(false); } stateMachine.gameObjects = gameObjects; }
public ObjectPool(Vector2 pos, Vector2 ad, Vector2 vel) { this.Add(bullets); for (int i = 0; i < 50; i++) { bullets.Add(new Bullet("Projectiles/Bullet", pos, ad, 0, false, vel, true, 0)); bullets.Add(new Bullet("Projectiles/Bullet", pos, ad, 0, false, vel, true, 1)); } }
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(); } TileField tiles = new TileField(textLines.Count - 1, width, 1, "tiles"); int height = textLines.Count - 1; GameObjectList hintField = new GameObjectList(100); Add(hintField); string hint = textLines[textLines.Count - 2]; SpriteGameObject hintFrame = new LockedSpriteGameObject("Overlays/spr_frame_hint", 1); hintField.Position = new Vector2((GameEnvironment.Screen.X - hintFrame.Width) / 2, 10); hintField.Add(hintFrame); TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); hintText.Text = textLines[textLines.Count - 2]; hintText.Position = new Vector2(120, 25); hintText.Color = Color.Black; hintField.Add(hintText); int timerTime = int.Parse(textLines[textLines.Count - 1]); timer.SetTime = timerTime; VisibilityTimer hintTimer = new VisibilityTimer(hintField, 1, "hintTimer"); Add(hintTimer); Add(tiles); tiles.CellWidth = 72; tiles.CellHeight = 55; this.width = width * tiles.CellWidth; this.height = height * tiles.CellHeight; for (int x = 0; x < width; x++) { Tile t = new Tile(); tiles.Add(t, x, 0); } for (int x = 0; x < width; ++x) { for (int y = 1; y < textLines.Count - 1; ++y) { Tile t = LoadTile(textLines[y - 1][x], x, y); tiles.Add(t, x, y); } } }
/// <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 override void Update(GameTime gameTime) { base.Update(gameTime); score.Text = goals.ToString(); //detect if ball got in goal if (ballFired && theBall.Position.Y < 50 && theBall.Position.X > 320 && theBall.Position.X < 500) { if (goals >= 19) { crowd.Add(new Crowd(new Vector2(75, 25 + (50 * (goals - 19))))); } if (goals < 19) { crowd.Add(new Crowd(new Vector2(25, 25 + (50 * goals)))); } theBall.Visible = false; ballFired = false; goals++; } //look if ball missed if (ballFired && theBall.Position.Y < 0) { theBall.Visible = false; ballFired = false; lives--; } numberOfLives.Text = lives.ToString(); //collision detection if (theBall != null) { if (theBall.CollidesWith(goalKeeper)) { theBall.Visible = false; ballFired = false; lives--; } } if (lives <= 0) { gameOver = true; } if (gameOver) { GameEnvironment.GameStateManager.SwitchTo("GameOverState"); lives = 3; goals = 0; thePlayer.Reset(); gameOver = false; crowd.Children.Clear(); } }
private void LoadPlayer(int x, int y) { Player player; try { PlayerType playerType = (PlayerType)Enum.Parse(typeof(PlayerType), GameEnvironment.GameSettingsManager.GetValue("character")); switch (playerType) { case PlayerType.Bard: player = new Bard(); break; case PlayerType.Warrior: player = new Warrior(); break; case PlayerType.Wizzard: player = new Wizzard(); break; default: player = new Warrior(); break; } } catch { player = new Warrior(); } GameObjectList entities = GetObject("entities") as GameObjectList; entities.Add(player); player.SetupPlayer(); player.MovePositionOnGrid(x, y); if (MultiplayerManager.Online && false) { foreach (LobbyPlayer lobbyplayer in MultiplayerManager.Party.playerlist.playerlist) { if (lobbyplayer.ishost == false) { Item item = new Item(id: "player2"); GameObjectList items = GetObject("items") as GameObjectList; entities.Add(item); item.MovePositionOnGrid(50, 50); } } } }
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(); } TileField tiles = new TileField(textLines.Count - 2, width, 1, "tiles"); //initialize news Tile GameObjectList hintField = new GameObjectList(100); Add(hintField); time = double.Parse(textLines[textLines.Count - 1]); //laatste regel van de txt bestanden en leest dit als tijd string hint = textLines[textLines.Count - 2]; SpriteGameObject hintFrame = new SpriteGameObject("Overlays/spr_frame_hint", 1); hintFrame.CameraFollow = false; hintField.Position = new Vector2((GameEnvironment.Screen.X - hintFrame.Width) / 2, 10); hintField.Add(hintFrame); TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); hintText.Text = textLines[textLines.Count - 2]; // hintText.Position = new Vector2(120, 25); hintText.Color = Color.Black; hintField.Add(hintText); VisibilityTimer hintTimer = new VisibilityTimer(hintField, 1, "hintTimer"); Add(hintTimer); 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); } } LevelSize = new Vector2(tiles.CellWidth * width, tiles.CellHeight * (textLines.Count - 1)); }
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 Life() : base() { position = new Vector2(500, 30); this.Add(text); this.Add(points); this.Add(hearts); hearts.Add(new Heart(new Vector2(70, 0))); hearts.Add(new Heart(new Vector2(120, 0))); hearts.Add(new Heart(new Vector2(170, 0))); text.Text = "life"; points.Text = "point total = " + 0; points.Position = new Vector2(-500, 0); points.Color = Color.Purple; text.Color = Color.Purple; }
void Init() { for (int i = 0; i < snakeSegments - 1; i++) { snake.Add(new SnakeSegment("spr_snakebody", new Vector2(i * snakeSpacing, 0))); } snake.Add(new SnakeSegment("spr_snakehead", new Vector2(snakeSpacing * snakeSegments - snakeSpacing, 0))); for (int i = 0; i < mushroomAmount; i++) { Random r = new Random(); int x = r.Next(randomMushroom[0], randomMushroom[1]); int y = r.Next(randomMushroom[2], randomMushroom[3]); mushrooms.Add(new Mushroom(new Vector2(x, y))); } }
public BackGround() : base() { Add(speedLines = new GameObjectList()); Add(objects = new GameObjectList()); speedLines.Add(new SpriteGameObject("BackGround")); speedLines.Add(new SpriteGameObject("BackGround")); speedLines.Children[0].Position -= new Vector2(0, (speedLines.Children[0] as SpriteGameObject).Height); foreach (SpriteGameObject speedLine in speedLines.Children) { speedLine.Velocity = new Vector2(0, BG_SPEEDLINE_XSPEED); } Reset(); }
/// <summary> /// Loads the conversation box for the first time (with the first text) /// </summary> public void ShowConversationBox() { SpriteGameObject conversationFrame = new SpriteGameObject("Assets/Sprites/Conversation Boxes/conversationbox1", 0, "", 10, false); Position = new Vector2(GameEnvironment.Screen.X / 2 - conversationFrame.Width / 2, GameEnvironment.Screen.Y * 3 / 4); Add(conversationFrame); TextGameObject currentText = new TextGameObject("Assets/Fonts/ConversationFont", 0, "currentlydisplayedtext") { Color = Color.White, Text = textLines[convIndex], Position = new Vector2(100, conversationFrame.Height / 2) }; displayedText.Add(currentText); }
public void wave() { int getRandomNotNullValue(int min, int max) { Random random = new Random(); int value = random.Next(min, max); while (value == 0) { value = random.Next(min, max); } return(value); } String[] assetNames = { "Red1", "BlueGhost", "YellowGhost" }; for (int iGhostType = 0; iGhostType < assetNames.Length; iGhostType++) { for (int IGhost = 0; IGhost < nGhostsPerLevel; IGhost++) { ghosts.Add(new Ghost(assetNames[iGhostType], new Vector2(startXPosition + IGhost * ghostWidth, startYPosition + iGhostType * ghostHeight), new Vector2(getRandomNotNullValue(-10, 10), getRandomNotNullValue(-10, 10)))); } } }
public void AddToList(int instances) { for (int i = 0; i < instances; i++) { gameObjects.Add(new GameObject()); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { list.Add(gameObject); } }
public WinState() { Add(new SpriteGameObject("MaliciousCompliance-temp")); Add(scoreText = new TextGameObject("GameFont", 1)); Add(confettiList = new GameObjectList()); for (int i = 0; i < confettiCount; i++) { confettiList.Add(new RotatingSpriteGameObject("confetti" + GameEnvironment.Random.Next(6) + "-temp")); } foreach (RotatingSpriteGameObject confetti in confettiList.Children) { confetti.Origin = confetti.Center; confetti.Degrees += GameEnvironment.Random.Next(-20, 20); confetti.Velocity = new Vector2(GameEnvironment.Random.Next(-10, 10), 20); confetti.Position = new Vector2(GameEnvironment.Random.Next(0, GameEnvironment.Screen.X), GameEnvironment.Random.Next(-50, -20)); confettiQueue.Enqueue(confetti); } scoreText.Text = "SCORE: " + PlayingState.finalScore.ToString(); scoreText.Position = new Vector2(GameEnvironment.Screen.X / 2 - scoreText.Size.X / 2f, GameEnvironment.Screen.Y / 2); Add(tryAgainText = new TextGameObject("GameFont", 1)); tryAgainText.Text = "Press any key to continue."; tryAgainText.Position = new Vector2(GameEnvironment.Screen.X / 2 - scoreText.Size.X * 1.5f, scoreText.Position.Y + 200); }
public override void Reset() { base.Reset(); lives.Children.Clear(); for (int i = 0; i < 3; i++) { lives.Add(new RotatingSpriteGameObject("life-temp")); (lives.Children[i] as RotatingSpriteGameObject).Degrees = 45; lives.Children[i].Position = new Vector2(30 + (lives.Children[i] as RotatingSpriteGameObject).Sprite.Width * i, 0); } timeScore = startTimeScore; timeUp.Visible = true; player.Position = resetPoint; foreach (Projectile projectile in projectileList.Children) { projectileQueue.Enqueue(projectile); projectile.Position = new Vector2(-1000, -1000); } frameCount = baseFrameCount; }
private void Shoot() { GameObjectList projectiles = GameWorld.Find("PlayerProjectiles") as GameObjectList; PlayerProjectile projectile = new PlayerProjectile(position + new Vector2(0, -60), shootLeft); projectiles.Add(projectile); }
public override void Update(GameTime gameTime) { base.Update(gameTime); frameCounter++; if (frameCounter > 100) { pipes.Add(new Pipe()); frameCounter = 0; } scoreCount = 0; foreach (Pipe pipe in pipes.Children) { if (pipe.OverlapsPipe(theBird) || theBird.position.Y > GameEnvironment.Screen.Y || theBird.position.Y < 0 - theBird.texture.Height) { isGameOver = true; } if (pipe.GlobalPosition.X < theBird.position.X) { scoreCount++; } } if (isGameOver) { SetGameOver(); } theScore.theText = scoreCount.ToString(); }
private void AddTab(Tab tab) { int tabTitleWidth = width / tabs.Count - 4; int index = tabs.FindIndex(t => t.Equals(tab)); TabButton b = new TabButton(new Point(width / tabs.Count - 4, 50), tab, titleFont, titleColor, bgColor); b.Action = () => { Tab prevActive = tabs.Find(t => t.Active); if (prevActive != null) { prevActive.Active = false; } b.tab.Active = true; GameObjectList content = this.Find("Content") as GameObjectList; Remove(content); GameObjectList newContent = new GameObjectList(0, "Content"); newContent.Add(b.tab.Content); newContent.Position = new Vector2(0, 50); Add(newContent); }; b.Position = new Vector2(width / tabs.Count * index + 2, 2); (this.Find("TabTitles") as GameObjectList).Add(b); }
public PlayingState() : base() { SpriteGameObject background = new SpriteGameObject("calligraphy"); this.Add(background); balls = new GameObjectList(0, "balls"); Random random = new Random(); for (int i = 0; i < 20; i++) { int randomsprite = random.Next(1, 4); string assetName = "spr_ball_green"; if (randomsprite == 1) { assetName = "spr_ball_green"; } if (randomsprite == 2) { assetName = "spr_ball_blue"; } if (randomsprite == 3) { assetName = "spr_ball_red"; } Vector2 aPositon = new Vector2(random.Next(100, 700), random.Next(100, 500)); Vector2 aVelocity = new Vector2(((float)random.NextDouble() - 0.5f) * 10, ((float)random.NextDouble() - 0.5f) * 10); balls.Add(new Ball(assetName, aPositon, aVelocity, Vector2.Zero, new Vector2(0, EARTH_GRAVITY), random.FloatBetween(8, 23), 0.85f)); } this.Add(balls); }
public void LoadTiles(string path) { 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(); } TileField tiles = new TileField(textlines.Count - 2, width, 1, "tiles"); GameObjectList hintfield = new GameObjectList(100); this.Add(hintfield); string hint = textlines[textlines.Count - 1]; SpriteGameObject hint_frame = new SpriteGameObject("Overlays/spr_frame_hint", 1); hintfield.Position = new Vector2((GameEnvironment.Screen.X - hint_frame.Width) / 2, 10); hint_frame.Meebewegen(); hintfield.Add(hint_frame); TextGameObject hintText = new TextGameObject("Fonts/HintFont", 2); hintText.Text = textlines[textlines.Count - 2]; hintText.Position = new Vector2(120, 25); hintText.Color = Color.Black; hintfield.Add(hintText); VisibilityTimer hintTimer = new VisibilityTimer(hintfield, 1, "hintTimer"); this.Add(hintTimer); GameObject.lvltimer = Convert.ToDouble(textlines[textlines.Count - 1]); // de laatste lijn in de textfile heeft de tijd 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); } }
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 Level(int levelIndex) : base() { 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); for(int i = 0; i < 5; i++) { 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(0.5, 1, 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"); }
public GameWorld() { //soundeffecten inladen InsaneKillerArcher.AssetManager.PlayMusic("background_music"); //laat bovenaan staan, is aleen de achtergrond. Add(new SpriteGameObject("background")); statusBar = new StatusBar(); Add(statusBar); castle = new Castle(); groundList = new GameObjectList(); for (int i = 0; i < InsaneKillerArcher.Screen.X/32; i++) { ground = new SpriteGameObject("gras"); ground.Position = new Vector2(i * ground.Width, InsaneKillerArcher.Screen.Y - ground.Height); groundList.Add(ground); } player = new Player(); player.Position = new Vector2(50, InsaneKillerArcher.Screen.Y - castle.mainCastle.Height - player.Body.Height + 35); catapultBoulders = new GameObjectList(); archers = new GameObjectList(); catapults = new GameObjectList(); Add(archers); Add(catapults); enemySpawner = new EnemySpawner(2, 5); arrows = new GameObjectList(); archerArrows = new GameObjectList(); animatedProjectiles = new GameObjectList(); Add(castle); Add(enemySpawner); Add(player); Add(catapultBoulders); Add(arrows); Add(archerArrows); Add(animatedProjectiles); Add(groundList); }
public PlayingState() { levels = new GameObjectList(0,"levels"); levels.Add(new Level(1)); this.Add(levels); }