/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here new Camera(this, Vector2.Zero, new Vector2(tileMap.GetLength(1) * tileWidth, tileMap.GetLength(0) * tileHeight)); new InputEngine(this); // Create a sentry for testing. Services.AddService(sentry1 = new Sentry(this, new Vector2(64, 128), new List <TileRef>() { new TileRef(21, 2, 0), new TileRef(21, 3, 0), new TileRef(21, 4, 0), new TileRef(21, 5, 0), new TileRef(21, 6, 0), new TileRef(21, 7, 0), new TileRef(21, 8, 0), }, 64, 64, 0f)); SetColliders(TileType.BLUESTEEL); SetColliders(TileType.BLUEBOX); SpawnPlayer(TileType.HOME); base.Initialize(); }
private void FindBody() { List <Sentry> Sentries = (List <Sentry>)Game.Services.GetService(typeof(List <Sentry>)); foreach (Sentry sentry in Sentries) { // Find appropiate body with the same name if (Name == sentry.Name && sentry != null) { parentBody = sentry; } } }
public void CollisionSentry(Sentry s) { if (BoundingRectangle.Intersects(s.BoundingRectangle)) { PixelPosition = previousPosition; } if (MySuperProjectile.BoundingRectangle.Intersects(s.BoundingRectangle) && MySuperProjectile.Visible == true) { MySuperProjectile.ProjectileState = SuperProjectile.PROJECTILE_STATE.EXPLODING; s.Health -= 50; //if (s.Health <= 0) //{ // s.Visible = false; //} } }
/// <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); Services.AddService(spriteBatch); Services.AddService(Content.Load <Texture2D>(@"Tiles/tank tiles 64 x 64")); // Tile References to be drawn on the Map corresponding to the entries in the defined // Tile Map // "free", "pavement", "ground", "blue", "home", "grass" "end" TileRefs.Add(new TileRef(4, 2, 0)); TileRefs.Add(new TileRef(3, 3, 1)); TileRefs.Add(new TileRef(6, 3, 2)); TileRefs.Add(new TileRef(6, 2, 3)); TileRefs.Add(new TileRef(0, 2, 4)); TileRefs.Add(new TileRef(0, 1, 5)); TileRefs.Add(new TileRef(0, 4, 6)); // Names fo the Tiles new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight); List <Tile> found = SimpleTileLayer.getNamedTiles("home"); new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight); List <Tile> foundSentry = SimpleTileLayer.getNamedTiles(backTileNames[(int)TileType.GREENBOX]); Services.AddService(new TilePlayer(this, new Vector2((int)TileType.HOME), new List <TileRef>() { new TileRef(15, 2, 0), new TileRef(15, 3, 0), new TileRef(15, 4, 0), new TileRef(15, 5, 0), new TileRef(15, 6, 0), new TileRef(15, 7, 0), new TileRef(15, 8, 0), }, 64, 64, 0f)); SetColliders(TileType.GREENBOX); SetColliders(TileType.BLUEBOX); TilePlayer tilePlayer = Services.GetService <TilePlayer>(); tilePlayer.AddHealthBar(new HealthBar(tilePlayer.Game, tilePlayer.PixelPosition)); player = (TilePlayer)Services.GetService(typeof(TilePlayer)); Projectile playerProjectile = new Projectile(this, new List <TileRef>() { new TileRef(8, 0, 0) }, new AnimateSheetSprite(this, player.PixelPosition, new List <TileRef>() { new TileRef(0, 0, 0), new TileRef(1, 0, 1), new TileRef(2, 0, 2) }, 64, 64, 0), player.PixelPosition, 1); player.LoadProjectile(playerProjectile); for (int i = 0; i < foundSentry.Count; i++) { sentryTurret = new Sentry(this, new Vector2(foundSentry[i].X * tileWidth, foundSentry[i].Y * tileHeight), new List <TileRef>() { new TileRef(20, 2, 0), new TileRef(20, 3, 0), new TileRef(20, 4, 0), new TileRef(20, 5, 0), new TileRef(20, 6, 0), new TileRef(20, 6, 0), new TileRef(20, 8, 0), }, 64, 64, 0); sentryList.Add(sentryTurret); } for (int i = 0; i < sentryList.Count; i++) { Projectile projectile = new Projectile(this, new List <TileRef>() { new TileRef(8, 0, 0) }, new AnimateSheetSprite(this, sentryList[i].PixelPosition, new List <TileRef>() { new TileRef(0, 0, 0), new TileRef(1, 0, 1), new TileRef(2, 0, 2) }, 64, 64, 0), sentryList[i].PixelPosition, 1); sentryList[i].LoadProjectile(projectile); sentryList[i].Health = 20; } // TODO: use this.Content to load your game content here //Background backgroundMusic = Content.Load <Song>(@"Audio/bckGroundMusic"); MediaPlayer.Play(backgroundMusic); MediaPlayer.Volume = 0.4f; MediaPlayer.IsRepeating = true; //Sound FX sfx[0] = Content.Load <SoundEffect>(@"Audio/Explosion 2"); //Player Shot sfx[1] = Content.Load <SoundEffect>(@"Audio/Beep"); //Sentry Shot sfx[2] = Content.Load <SoundEffect>(@"Audio/Explosion"); //Projectile Explosion sfx[3] = Content.Load <SoundEffect>(@"Audio/Ching"); //Victory sfx[4] = Content.Load <SoundEffect>(@"Audio/Error"); //Fail //Screens victory = Content.Load <Texture2D>(@"Images/Victory"); gameOver = Content.Load <Texture2D>(@"Images/GameOver"); }