コード例 #1
0
        public static void Dispose()
        {
            foreach (ItemTile t in mapItems)
            {
                t.GetRigidbody.Dispose();
            }

            foreach (Coins c in mapCoins)
            {
                c.GetRigidbody.Dispose();
            }

            foreach (Enemy e in mapEnemies)
            {
                e.GetRigidbody.Dispose();
            }

            // Yes, I know a list would be faster :P
            if (player != null)
            {
                player = null;
            }

            if (exit != null)
            {
                exit = null;
            }

            if (testActor != null)
            {
                testActor.body.Dispose();
                testActor = null;
            }

            Game1.camera.Reset();

            mapEnemies.Clear();
            mapItems.Clear();
            mapCoins.Clear();
        }
コード例 #2
0
        public static void Dispose()
        {
            foreach (ItemTile t in mapItems)
            {
                t.GetRigidbody.Dispose();
            }

            foreach (Coins c in mapCoins)
            {
                c.GetRigidbody.Dispose();
            }

            foreach (Enemy e in mapEnemies)
            {
                e.GetRigidbody.Dispose();
            }

            // Yes, I know a list would be faster :P 
            if (player != null)
            {
                player = null;
            }

            if (exit != null)
            {
                exit = null;
            }

            if (testActor != null)
            {
                testActor.body.Dispose();
                testActor = null;
            }

            Game1.camera.Reset();

            mapEnemies.Clear();
            mapItems.Clear();
            mapCoins.Clear();
        }
コード例 #3
0
        //level loader
        public static void LoadLevel(string name)
        {
            if (mapItems == null)
            {
                mapItems = new List <ItemTile>();
            }

            if (mapCoins == null)
            {
                mapCoins = new List <Coins>();
            }

            if (mapEnemies == null)
            {
                mapEnemies = new List <Enemy>();
            }

            levelDone = false;

            coins = 0;

            string filePath = Game1.content.RootDirectory.ToString() + "\\Levels\\" + name + ".map";

            int x = 0;
            int y = 0;

            foreach (string line in File.ReadAllLines(filePath))
            {
                x = 0;

                foreach (char token in line)
                {
                    switch (token)
                    {
                    // Blank space
                    case '.':
                        // mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 0f, ItemTileType.Blank));
                        break;

                    case '#':
                        mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.Block));
                        break;

                    case '+':
                        mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.BlockC));
                        break;

                    case '-':
                        mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.DarkBrick));
                        break;

                    case 'c':
                        //mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.Coin));
                        mapCoins.Add(new Coins(new Vector2(x * 32, y * 32)));
                        break;

                    case 'p':
                        player = new Player(new Vector2(x * 32, y * 32));
                        break;

                    case 'q':
                        testActor = new TestActor(new Vector2(x * 32, y * 32));
                        break;

                    case 'x':
                        exit = new Exit(new Vector2(x * 32, y * 32));
                        break;

                    case 'e':
                        mapEnemies.Add(new Enemy(new Vector2(x * 32, y * 32)));
                        break;

                        // Unknown tile type character
                        //    default:
                        //      throw new Exception(String.Format("Wrong Char"));
                    }
                    x++;
                }

                y++;
            }
        }
コード例 #4
0
        //level loader
        public static void LoadLevel(string name)
        {
            if (mapItems == null)
                mapItems = new List<ItemTile>();

            if (mapCoins == null)
                mapCoins = new List<Coins>();

            if (mapEnemies == null)
                mapEnemies = new List<Enemy>();

            levelDone = false;

            coins = 0;

            string filePath = Game1.content.RootDirectory.ToString() + "\\Levels\\" + name + ".map";

            int x = 0;
            int y = 0;

            foreach (string line in File.ReadAllLines(filePath))
            {
                x = 0;

                foreach (char token in line)
                {
                    switch (token)
                    {
                        // Blank space
                        case '.':
                            // mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 0f, ItemTileType.Blank));
                            break;

                        case '#':
                            mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.Block));
                            break;

                        case '+':
                            mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.BlockC));
                            break;

                        case '-':
                            mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.DarkBrick));
                            break;

                        case 'c':
                            //mapItems.Add(new ItemTile(new Vector2(x * 32, y * 32), 1f, ItemTileType.Coin));
                            mapCoins.Add(new Coins(new Vector2(x * 32, y * 32)));
                            break;

                        case 'p':
                            player = new Player(new Vector2(x * 32, y * 32));
                            break;

                        case 'q':
                            testActor = new TestActor(new Vector2(x * 32, y * 32));
                            break;

                        case 'x':
                            exit = new Exit(new Vector2(x * 32, y * 32));
                            break;

                        case 'e':
                            mapEnemies.Add(new Enemy(new Vector2(x * 32, y * 32)));
                            break;

                            // Unknown tile type character
                            //    default:
                            //      throw new Exception(String.Format("Wrong Char"));
                    }
                    x++;
                }

                y++;
            }

        }