Beispiel #1
0
 public Astar(Node StartingNode, Node TargetNode, Game game, SimpleTileLayer layer, bool DisableDiagonalPathfinding)
 {
     this.StartingNode = StartingNode;
     this.TargetNode   = TargetNode;
     this.layer        = layer;
     this.game         = game;
     this.DisableDiagonalPathfinding = DisableDiagonalPathfinding;
 }
        public void TestGetActor()
        {
            SimpleTileLayer layer = new SimpleTileLayer(LayerType.All, 7, 7);
            PathTile path = new PathTile(0);
            layer.Tiles[3][2] = path;

            Assert.Equal(path, layer.GetActorAt(3, 2));
            Assert.Equal(path, layer.GetActorAt(new Vector2I(3, 2)));
        }
        public void ActorOutOfRangeIsObstacle(int x, int y, bool valid)
        {
            SimpleTileLayer layer = new SimpleTileLayer(LayerType.All, 7, 7);

            if (valid)
                Assert.IsNotType<Obstacle>(layer.GetActorAt(x, y));
            else
                Assert.IsType<Obstacle>(layer.GetActorAt(x, y));
        }
        /// <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);

            // Load in the tile sheet.
            Texture2D tx = Content.Load <Texture2D>(@"Tiles/tank tiles 64 x 64");

            Services.AddService(tx);

            // Load in victory and game over textures.
            victory = Content.Load <Texture2D>(@"Winter Game Sprites/Victory");

            gameOver = Content.Load <Texture2D>(@"Winter Game Sprites/Game Over Edited");

            // Create font for the timer.
            timerFont = Content.Load <SpriteFont>("timerFont");

            // Load Sound effects
            playerFire      = Content.Load <SoundEffect>(@"Winter Game Sound Effects Wave/PlayerFire");
            sentryExplosion = Content.Load <SoundEffect>(@"Winter Game Sound Effects Wave/SentryExplosion");

            victoryFanfare = Content.Load <SoundEffect>(@"Winter Game Sound Effects Wave/TanksForPlaying");

            #region Load Tile Images
            // Tile References to be drawn on the Map corresponding to the entries in the defined
            // Tile Map
            // "crates", "pavement", "red water", "sentry", "home", "exit", "skull", locked".
            TileRefs.Add(new TileRef(11, 1, 0));
            TileRefs.Add(new TileRef(3, 3, 1));
            TileRefs.Add(new TileRef(0, 9, 0));
            TileRefs.Add(new TileRef(6, 2, 3));
            TileRefs.Add(new TileRef(0, 2, 4));
            TileRefs.Add(new TileRef(1, 2, 0));
            TileRefs.Add(new TileRef(6, 11, 0));
            TileRefs.Add(new TileRef(5, 3, 0));
            // Names for the Tiles

            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);
            #endregion

            // I haven't used the following line of code later on.
            List <Tile> found = SimpleTileLayer.GetNamedTiles("sentry");

            #region Load and Play BGM.
            // Load Background Music.
            this.backgroundMusic = Content.Load <Song>(@"Winter Game Music/Metal Fox");

            // Set volume.
            MediaPlayer.Volume      = 0.0f;
            MediaPlayer.IsRepeating = true;
            #endregion

            // TODO: use this.Content to load your game content here
        }
Beispiel #5
0
        private void PathFinding(GameTime gameTime, SimpleTileLayer layer, string UnitID, List <Sentry> Units)
        {
            #region Calculate Location
            if (updateTime > UPDATE_TIME_MAX) // Check every millisecond.
            {
                astarThreadWorker = null;
                AstarManager.AddNewThreadWorker(
                    new Node(new Vector2(
                                 (int)(PixelPosition.X / FrameWidth),
                                 (int)(PixelPosition.Y / FrameHeight))),
                    new Node(new Vector2(
                                 (int)(Target.X) / FrameWidth,
                                 (int)(Target.Y) / FrameHeight)),
                    Game, layer, false, UnitID);
                updateTime = 0f;
            }
            else
            {
                updateTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            #endregion

            AstarManager.AstarThreadWorkerResults.TryPeek(out astarThreadWorkerTemp);

            #region Add Location to WayPoints
            if (astarThreadWorkerTemp != null)
            {
                if (astarThreadWorkerTemp.WorkerIDNumber == UnitID)
                {
                    AstarManager.AstarThreadWorkerResults.TryDequeue(out astarThreadWorker);

                    if (astarThreadWorker != null)
                    {
                        wayPoint = new WayPoint();

                        WayPointsList = astarThreadWorker.astar.GetFinalPath();

                        for (int i = 0; i < WayPointsList.Count; i++)
                        {
                            WayPointsList[i] = new Vector2(
                                WayPointsList[i].X * FrameWidth,
                                WayPointsList[i].Y * FrameHeight);
                        }
                    }
                }
            }
            #endregion

            #region Avoid Obstacles and Move to Target
            if (WayPointsList.Count > 0)
            {
                Avoidance(gameTime, UnitID);
                wayPoint.MoveTo(gameTime, this, WayPointsList);
            }
            #endregion
        }
Beispiel #6
0
        public void TestGetActor()
        {
            SimpleTileLayer layer = new SimpleTileLayer(LayerType.All, 7, 7);
            PathTile        path  = new PathTile(0);

            layer.Tiles[3][2] = path;

            Assert.Equal(path, layer.GetActorAt(3, 2));
            Assert.Equal(path, layer.GetActorAt(new Vector2I(3, 2)));
        }
Beispiel #7
0
        private Vector2 ChooseRandomTile()
        {
            List <Tile> groundTiles = SimpleTileLayer.GetNamedTiles("ground");

            Vector2 randomTilePosition = new Vector2(
                groundTiles[Camera.random.Next(0, groundTiles.Count)].X * FrameWidth,
                groundTiles[Camera.random.Next(0, groundTiles.Count)].Y * FrameHeight);

            return(randomTilePosition);
        }
Beispiel #8
0
        public void ActorOutOfRangeIsObstacle(int x, int y, bool valid)
        {
            SimpleTileLayer layer = new SimpleTileLayer(LayerType.All, 7, 7);

            if (valid)
            {
                Assert.IsNotType <Obstacle>(layer.GetActorAt(x, y));
            }
            else
            {
                Assert.IsType <Obstacle>(layer.GetActorAt(x, y));
            }
        }
Beispiel #9
0
        /// <summary>
        /// This function will run the astar algorithem and tries to find the shortest path.
        /// </summary>
        /// <param name="StartingNode">The starting position in (Array coordinates) of the search path.</param>
        /// <param name="TargetNode">The target or destination position in (Array coordinates) where the search for the path will end at.</param>
        /// <param name="map">Map class.</param>
        /// <param name="DisableDiagonalPathfinding">If true, the A* algorithm will not search the path in diagonal direction.</param>
        /// <param name="WorkerIDNumber">ID number for this worker thread so you can get the results back.</param>
        public AstarThreadWorker(Node StartingNode, Node TargetNode, Game game, SimpleTileLayer layer, bool DisableDiagonalPathfinding, string WorkerIDNumber)
        {
            if (StartingNode.Position.X > layer.MapWidth || StartingNode.Position.Y > layer.MapHeight)
            {
                throw new Exception("StartingNode size cannot be bigger than map array size. Please make sure the StartingNode position is in array coordinates not pixel coordinates.");
            }

            if (TargetNode.Position.X > layer.MapWidth || TargetNode.Position.Y > layer.MapHeight)
            {
                throw new Exception("TargetNode size cannot be bigger than map array size. Please make sure the TargetNode position is in array coordinates not pixel coordinates.");
            }

            this.WorkerIDNumber = WorkerIDNumber;
            astar = new Astar(StartingNode, TargetNode, game, layer, DisableDiagonalPathfinding);
            astar.FindPath(game);
        }
        /// <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"
            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));
            // Names fo the Tiles

            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);
            List <Tile> found = SimpleTileLayer.getNamedTiles(backTileNames[(int)TileType.GREENBOX]);
            // TODO: use this.Content to load your game content here
        }
Beispiel #11
0
        private void HandleMovement(GameTime gameTime)
        {
            SimpleTileLayer tileMap  = (SimpleTileLayer)Game.Services.GetService(typeof(SimpleTileLayer));
            List <Sentry>   Sentries = (List <Sentry>)Game.Services.GetService(typeof(List <Sentry>));

            if (!IsDead && !DestinationReached)
            {
                PathFinding(gameTime, tileMap, Name, Sentries);
            }
            else
            {
                if (Velocity.X > 0 && Velocity.Y > 0)
                {
                    Velocity -= Deceleration;
                }
                else
                {
                    Velocity = Vector2.Zero;
                }
            }
        }
        public SimpleTileLayerTest()
        {
            var tilesetMock0 = new Mock <TilesetTable>();

            tilesetMock0.Setup(x => x.TileNumber(It.IsAny <string>())).Returns(0);
            var tilesetMock1 = new Mock <TilesetTable>();

            tilesetMock1.Setup(x => x.TileNumber(It.IsAny <string>())).Returns(1);

            var mockTile1 = new Mock <Tile>(MockBehavior.Default, tilesetMock0.Object);
            var mockTile2 = new Mock <Tile>(MockBehavior.Default, tilesetMock1.Object);
            var tile0     = mockTile1.Object;
            var tile1     = mockTile2.Object;

            Tile[] row0 = new Tile[] { tile0, tile1, tile1 };
            Tile[] row1 = new Tile[] { tile1, tile1, tile0 };
            Tile[] row2 = new Tile[] { tile0, tile1, tile0 };

            m_tileArray = new[]
            {
                row0, row1, row2
            };

            m_tileSequenceArray = new Tile[] {
                row0[0], row1[0], row2[0],
                row0[1], row1[1], row2[1],
                row0[2], row1[2], row2[2],
            };

            m_simpleTileLayer = new SimpleTileLayer(LayerType.Obstacle, 3, 3)
            {
                Tiles = m_tileArray
            };

            var atlas = new Atlas();

            atlas.IncrementTime(new TimeSpan(atlas.YearLength.Ticks / 2)); // Set summer
            m_simpleTileLayer.UpdateTileStates(atlas);
        }
        /// <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"
            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));
            // Names fo the Tiles

            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);
            List <Tile> found = SimpleTileLayer.getNamedTiles(backTileNames[(int)TileType.GREENBOX]);

            // TODO: use this.Content to load your game content here

            for (int i = 0; i < found.Count; i++)
            {
                sentryTurret = new SentryTurret(this, new Vector2(found[i].X * tileWidth, found[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, 7, 0),
                    new TileRef(20, 8, 0),
                }, 64, 64, 0f);
                sentryList.Add(sentryTurret);
            }
        }
        public SimpleTileLayerTest()
        {
            var tilesetMock0 = new Mock<ITilesetTable>();
            tilesetMock0.Setup(x => x.TileNumber(It.IsAny<string>())).Returns(0);
            var tilesetMock1 = new Mock<ITilesetTable>();
            tilesetMock1.Setup(x => x.TileNumber(It.IsAny<string>())).Returns(1);

            var mockTile1 = new Mock<Tile>(MockBehavior.Default, tilesetMock0.Object);
            var mockTile2 = new Mock<Tile>(MockBehavior.Default, tilesetMock1.Object);
            var tile0 = mockTile1.Object;
            var tile1 = mockTile2.Object;

            Tile[] row0 = new Tile[] { tile0, tile1, tile1 };
            Tile[] row1 = new Tile[] { tile1, tile1, tile0 };
            Tile[] row2 = new Tile[] { tile0, tile1, tile0 };

            m_tileArray = new[]
                {
                    row0, row1, row2
                };

            m_tileSequenceArray = new Tile[] {
                row0[0], row1[0], row2[0],
                row0[1], row1[1], row2[1],
                row0[2], row1[2], row2[2],
                };

            m_simpleTileLayer = new SimpleTileLayer(LayerType.Obstacle, 3, 3)
            {
                Tiles = m_tileArray
            };

            var atlas = new Atlas();
            atlas.IncrementTime(new TimeSpan(atlas.YearLength.Ticks / 2)); // Set summer
            m_simpleTileLayer.UpdateTileStates(atlas);
        }
Beispiel #15
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //Audio Load
            bkMusic   = Content.Load <Song>("bkMusic");
            death     = Content.Load <SoundEffect>("Wasted");
            shot      = Content.Load <SoundEffect>("Grenade");
            explosion = Content.Load <SoundEffect>("Explosion");
            winner    = Content.Load <SoundEffect>("Winner");

            //Tiles for EndGame Screen
            txGameOver = Content.Load <Texture2D>(@"Tiles/Wasted");
            txwinner   = Content.Load <Texture2D>(@"Tiles/Winner");
            gameOver   = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            // 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"));
            Services.AddService(Content.Load <SpriteFont>(@"font"));

            // Tile References to be drawn on the Map corresponding to the entries in the defined
            // Tile Map
            // "free", "pavement", "ground", "blue", "home", "exit"
            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(3, 3, 5));
            // Names of the Tiles
            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);

            TilePlayer player = Services.GetService <TilePlayer>();

            //Projectile Service
            Projectile playerProjectile = new Projectile(this, new List <TileRef>()
            {
                new TileRef(7, 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);

            SetColliders(TileType.BLUEBOX);
            SetColliders(TileType.EXIT);

            playerProjectile.AddShot(shot);
            playerProjectile.AddExplosionSound(explosion);

            player.LoadProjectile(playerProjectile);

            //This is the only bit of code done by either of my teammates, this part was done by Conor Flannery
            //Sentry Turret
            List <Tile> found = SimpleTileLayer.getNamedTiles(backTileNames[(int)TileType.GREENBOX]);

            // TODO: use this.Content to load your game content here

            for (int i = 0; i < found.Count; i++)
            {
                sentryTurret = new SentryTurret(this, new Vector2(found[i].X * tileWidth, found[i].Y * tileHeight), 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);
                sentryList.Add(sentryTurret);
            }
            //This is the end of the code done by Conor Flannery

            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);

                projectile.AddShot(shot);
                projectile.AddExplosionSound(explosion);

                sentryList[i].LoadProjectile(projectile);
                sentryList[i].Health = 20;
            }
        }
Beispiel #16
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);
            Services.AddService(spriteBatch);


            //Initialize a 17 second timer for the loading screen.
            float timer = 17;



            Song      startVoice = Content.Load <Song>(@"Winter Game Sounds/ballsofsteel");
            Texture2D txCoin     = Content.Load <Texture2D>(@"Winter Game Sprites/Insert Coin");

            Services.AddService(txCoin);



            //Trying to get the loading screen and the startup music to activate at the same time.
            //while under a 17 second timer (the length of the sound).
            if (timer <= 17)
            {
                //Loads the loading screen and proceeds to play the startup music.
                Song      startSong = Content.Load <Song>(@"Winter Game Sounds/ps_1");
                Texture2D txLoad    = Content.Load <Texture2D>(@"Winter Game Sprites/Loading Screen");
                Services.AddService(txLoad);



                //Set volume.
                MediaPlayer.Volume = 0.5f;
            }


            //When the loading screen is finished, this should load the game.
            else if (timer >= 17)
            {
                Services.AddService(Content.Load <Texture2D>(@"Tiles/tank tiles 64 x 64"));
            }



            // Create font for the timer.
            timerFont = Content.Load <SpriteFont>("timerFont");



            // Tile References to be drawn on the Map corresponding to the entries in the defined
            // Tile Map
            // "free", "pavement", "ground", "blue", "home"
            TileRefs.Add(new TileRef(4, 2, 0));
            TileRefs.Add(new TileRef(3, 3, 1));
            TileRefs.Add(new TileRef(0, 9, 0));
            TileRefs.Add(new TileRef(6, 2, 3));
            TileRefs.Add(new TileRef(0, 2, 4));
            // Names for the Tiles

            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);
            List <Tile> found = SimpleTileLayer.GetNamedTiles("green box");
            // TODO: use this.Content to load your game content here
        }
Beispiel #17
0
 /// <summary>
 /// This function will add a new thread worker for A* algorithm to run on.
 /// </summary>
 /// <param name="StartingNode">The starting position in (Array coordinates) of the search path.</param>
 /// <param name="TargetNode">The target or destination position in (Array coordinates) where the search for the path will end at.</param>
 /// <param name="map">Map class.</param>
 /// <param name="DisableDiagonalPathfinding">If true, the A* algorithm will not search the path in diagonal direction.</param>
 /// <param name="WorkerIDNumber">ID number for this worker thread so you can get the results back.</param>
 public static void AddNewThreadWorker(Node StartingNode, Node TargetNode, Game game, SimpleTileLayer layer, bool DisableDiagonalPathfinding, string WorkerIDNumber)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
     {
         AstarThreadWorker astarWorker = new AstarThreadWorker(StartingNode, TargetNode, game, layer, DisableDiagonalPathfinding, WorkerIDNumber);
         AstarThreadWorkerResults.Enqueue(astarWorker);
     }));
 }
Beispiel #18
0
        private static ITileLayer FillTileLayer(
            Layer layer,
            LayerType layerType,
            Dictionary <int, StaticTile> staticTilesContainer,
            TilesetTable tilesetTable,
            Action <GameActor> initializer,
            Random random)
        {
            SimpleTileLayer newSimpleLayer = new SimpleTileLayer(layerType, layer.Width, layer.Height, random);

            string[] lines = layer.Data.RawData.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
                             .Where(l => !string.IsNullOrWhiteSpace(l)).ToArray();
            Assembly assembly = Assembly.GetExecutingAssembly();

            Type[] cachedTypes = assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(Tile))).ToArray();
            for (int i = 0; i < lines.Length; i++)
            {
                string[] tiles = lines[i].Split(',');
                for (int j = 0; j < tiles.Length; j++)
                {
                    if (tiles[j].Trim() == "")
                    {
                        continue;
                    }
                    int tileNumber = int.Parse(tiles[j]);

                    if (tileNumber == 0)
                    {
                        continue;
                    }

                    int x = j;
                    int y = layer.Height - 1 - i;
                    if (staticTilesContainer.ContainsKey(tileNumber))
                    {
                        newSimpleLayer.AddInternal(x, y, staticTilesContainer[tileNumber]);
                    }
                    else
                    {
                        string tileName = tilesetTable.TileName(tileNumber);
                        if (tileName != null)
                        {
                            Tile newTile = CreateInstance(tileName, tileNumber, cachedTypes, new Vector2I(x, y));
                            initializer.Invoke(newTile);
                            newSimpleLayer.AddInternal(x, y, newTile);
                            if (newTile is StaticTile)
                            {
                                staticTilesContainer.Add(tileNumber, newTile as StaticTile);
                            }
                        }
                        else
                        {
                            Log.Instance.Error("Tile with number " + tileNumber + " was not found in TilesetTable");
                        }
                    }
                }
            }

            if (layer.Properties != null)
            {
                Property render = layer.Properties.PropertiesList.FirstOrDefault(x => x.Name.Trim() == "Render");
                if (render != null)
                {
                    newSimpleLayer.Render = bool.Parse(render.Value);
                }
            }

            return(newSimpleLayer);
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            sFont = Content.Load <SpriteFont>("sFont");

            // 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", "blue steel", "green box", "home"
            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));

            // Names fo the Tiles

            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);
            List <Tile> found = SimpleTileLayer.getNamedTiles(backTileNames[(int)TileType.GREENBOX]);

            Projectile playerBullet = new Projectile(this, new List <TileRef>()
            {
                new TileRef(5, 0, 0)
            },
                                                     new AnimateSheetSprite(this, player.PixelPosition, new List <TileRef>()
            {
                new TileRef(7, 0, 0),
                new TileRef(8, 0, 0),
                new TileRef(0, 0, 0),
                new TileRef(1, 0, 0),
                new TileRef(2, 0, 0)
            }, tileWidth, tileHeight, 1), player.PixelPosition, 1);


            player.LoadProjectile(playerBullet);


            //List<Tile> found = SimpleTileLayer.getNamedTiles("green box");
            // added a senytry gameservice similer to a player. 29/11/17 at 13:44
            for (int i = 0; i < found.Count; i++)
            {
                sentrys = new Sentry(this, new Vector2(found[i].X * tileWidth, found[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, 7, 0),
                    new TileRef(20, 8, 0),
                }, 64, 64, 0f);
                sentryList.Add(sentrys);

                Projectile projectile = new Projectile(this, new List <TileRef>()
                {
                    new TileRef(0, 0, 0)
                },
                                                       new AnimateSheetSprite(this, player.PixelPosition, new List <TileRef>()
                {
                    new TileRef(7, 0, 0),
                    new TileRef(8, 0, 0),
                    new TileRef(0, 0, 0),
                    new TileRef(1, 0, 0),
                    new TileRef(2, 0, 0)
                }, tileWidth, tileHeight, 1), player.PixelPosition, 1);

                sentryList[i].loadProjectile(projectile);
                sentryList[i].Health = 2;
            }

            player.playerCrossHair = new CrossHair(this, new List <TileRef>()
            {
                new TileRef(11, 6, 0)
            }, player.PixelPosition, 1);
            // insert soundEffects and songs!
            bulletExplosion = Content.Load <SoundEffect>("SoundEffects/atari_boom");
            Shooting        = Content.Load <SoundEffect>("SoundEffects/atari_boom2");
            backingTrack    = Content.Load <Song>("Songs/bgm_action_1");
        }
Beispiel #20
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);
            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");
        }
Beispiel #21
0
        private static ITileLayer FillTileLayer(
            Layer layer,
            LayerType layerType,
            Dictionary<int, StaticTile> staticTilesContainer,
            TilesetTable tilesetTable,
            Action<GameActor> initializer,
            Random random)
        {
            SimpleTileLayer newSimpleLayer = new SimpleTileLayer(layerType, layer.Width, layer.Height, random);
            string[] lines = layer.Data.RawData.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
                .Where(l => !string.IsNullOrWhiteSpace(l)).ToArray();
            Assembly assembly = Assembly.GetExecutingAssembly();
            Type[] cachedTypes = assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(Tile))).ToArray();
            for (int i = 0; i < lines.Length; i++)
            {
                string[] tiles = lines[i].Split(',');
                for (int j = 0; j < tiles.Length; j++)
                {
                    if (tiles[j].Trim() == "")
                        continue;
                    int tileNumber = int.Parse(tiles[j]);

                    if (tileNumber == 0) continue;

                    int x = j;
                    int y = layer.Height - 1 - i;
                    if (staticTilesContainer.ContainsKey(tileNumber))
                    {
                        newSimpleLayer.AddInternal(x, y, staticTilesContainer[tileNumber]);
                    }
                    else
                    {
                        string tileName = tilesetTable.TileName(tileNumber);
                        if (tileName != null)
                        {
                            Tile newTile = CreateInstance(tileName, tileNumber, cachedTypes, new Vector2I(x, y));
                            initializer.Invoke(newTile);
                            newSimpleLayer.AddInternal(x, y, newTile);
                            if (newTile is StaticTile)
                            {
                                staticTilesContainer.Add(tileNumber, newTile as StaticTile);
                            }
                        }
                        else
                        {
                            Log.Instance.Error("Tile with number " + tileNumber + " was not found in TilesetTable");
                        }
                    }
                }
            }

            if (layer.Properties != null)
            {
                Property render = layer.Properties.PropertiesList.FirstOrDefault(x => x.Name.Trim() == "Render");
                if (render != null)
                    newSimpleLayer.Render = bool.Parse(render.Value);
            }

            return newSimpleLayer;
        }
Beispiel #22
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);
            Services.AddService(spriteBatch);
            Services.AddService(Content.Load <Texture2D>(@"Tiles/tank tiles 64 x 64"));
            Services.AddService(Content.Load <SpriteFont>(@"Font"));

            // Tile References to be drawn on the Map corresponding to the entries in the defined
            // Tile Map
            // "free", "pavement", "ground", "blue", "home", "exit"
            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(1, 2, 5));

            // Names fo the Tiles
            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);

            TilePlayer player = Services.GetService <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);

            playerProjectile.AddFireSound(shoot);
            playerProjectile.AddExplosionSound(explosion);
            player.LoadProjectile(playerProjectile);

            List <Tile> greenTiles = SimpleTileLayer.GetNamedTiles("green");

            //sentry sprite
            for (int i = 0; i < greenTiles.Count; i++)
            {
                TileSentry sentry = new TileSentry(this, new Vector2(greenTiles[i].X * 64, greenTiles[i].Y * 64), 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);
                sentries.Add(sentry);
            }

            for (int i = 0; i < sentries.Count; i++)
            {
                Projectile projectile = new Projectile(this, new List <TileRef>()
                {
                    new TileRef(8, 0, 0)
                },
                                                       new AnimateSheetSprite(this, sentries[i].PixelPosition, new List <TileRef>()
                {
                    new TileRef(0, 0, 0),
                    new TileRef(1, 0, 1),
                    new TileRef(2, 0, 2)
                }, 64, 64, 0), sentries[i].PixelPosition, 1);

                projectile.AddFireSound(shoot);
                projectile.AddExplosionSound(explosion);
                sentries[i].LoadProjectile(projectile);
                sentries[i].Health = 20;
            }


            // TODO: use this.Content to load your game content here
        }
Beispiel #23
0
        protected override void LoadContent()
        {
            spriteBatch           = new SpriteBatch(GraphicsDevice);
            Helper.graphicsDevice = GraphicsDevice;

            penumbra.Transform = Camera.CurrentCameraTranslation;

            // Add SpriteBatch to services, it can be called anywhere.
            Services.AddService(spriteBatch);
            Services.AddService(Content.Load <Texture2D>(@"tiles/tilesheet"));

            // Tile References to be drawn on the Map corresponding to the entries in the defined
            // Tile Map
            TileRefs.Add(new TileRef(7, 0, 0));  // Dirt
            TileRefs.Add(new TileRef(4, 1, 1));  // Ground
            TileRefs.Add(new TileRef(3, 2, 2));  // Metal Box
            TileRefs.Add(new TileRef(5, 0, 3));  // Ground 2
            TileRefs.Add(new TileRef(5, 1, 4));  // Ground 3
            TileRefs.Add(new TileRef(7, 2, 5));  // Ground 4
            TileRefs.Add(new TileRef(7, 3, 6));  // Ground 5
            TileRefs.Add(new TileRef(6, 2, 7));  // Ground 4
            TileRefs.Add(new TileRef(1, 1, 8));  // Metal 2
            TileRefs.Add(new TileRef(2, 1, 9));  // Metal 3
            TileRefs.Add(new TileRef(3, 1, 10)); // Metal 4
            TileRefs.Add(new TileRef(4, 2, 11)); // Dirt (Trigger)

            SimpleTileLayer Layer = new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);

            Services.AddService(Layer);

            // This code is used to find tiles of a specific type
            //List<Tile> tileFound = SimpleTileLayer.GetNamedTiles(backTileNames[(int)TileType.GREENBOX]);

            #region Splash Screen
            Queue <Texture2D> txWinQueue             = new Queue <Texture2D>();
            Dictionary <string, Texture2D> winFrames = new Dictionary <string, Texture2D>();

            winFrames = Loader.ContentLoad <Texture2D>(Content, "background\\WinFrames");
            foreach (var frame in winFrames)
            {
                txWinQueue.Enqueue(frame.Value);
            }

            MainScreen = new SplashScreen(this, Vector2.Zero, 360000.00f, // 6 mins
                                          Content.Load <Texture2D>("background/MainMenu"),
                                          Content.Load <Texture2D>("background/Lose"),
                                          txWinQueue,
                                          Content.Load <Song>("audio/MainMenu"),
                                          Content.Load <Song>("audio/Play"),
                                          Content.Load <Song>("audio/Pause"),
                                          Content.Load <Song>("audio/GameOver"),
                                          Content.Load <Song>("audio/Win"),
                                          Keys.P,
                                          Keys.Enter,
                                          Buttons.A,
                                          Buttons.Start,
                                          Content.Load <SpriteFont>("fonts/font"),
                                          Content.Load <SoundEffect>("audio/BlinkPlay"),
                                          Content.Load <SoundEffect>("audio/BlinkPause"));
            #endregion
        }