Exemplo n.º 1
0
 public XmlWrite()
 {
     // initialise levelFolder
     StaticVariables.execFolder = AppDomain.CurrentDomain.BaseDirectory;
     StaticVariables.levelFolder = StaticVariables.execFolder;
     // create world
     this.w = new World(10, 10);
     // fill world
     this.w.FillWorld(TERRAIN.grass_normal, new Size(10, 10));
     // initialize player
     this.w.InitPlayer(new PointF(5, 5));
     this.p = w.getPlayer();
     LevelWriter.saveWorld(this.w, this.file);
     beforelist = new TerrainTile[w.getTerrain().Count];
     before = new Entity[w.getEntities().Count];
     // save beforlist
     w.getTerrain().CopyTo(beforelist);
     w.getEntities().CopyTo(before);
     world = new World(10, 10);
     world.loadLevel(this.file);
     afterlist = new TerrainTile[world.getTerrain().Count];
     after = new Entity[world.getEntities().Count];
     // save afterlist
     world.getTerrain().CopyTo(afterlist);
     world.getEntities().CopyTo(after);
 }
Exemplo n.º 2
0
        /*
         * Grid simulation setup:
         * G = Grass, W = Water
         * |G|G|G|
         * |G|G|G|
         * |W|W|W|
         */
        public PlayerInventory()
        {
            // Initialize world
            this.w = new World(Size, Size);
            // Fill world with tiles of grass
            w.FillWorld(TERRAIN.grass_normal, new Size(Size, Size));
            // Fill third row with water
            for (int i = 0; i <= 2; i++)
                w.setTerraintile(new Point(i, 2), (int)SPRITES.water);

            // Initialize player
            w.InitPlayer(new PointF(1, 1));
            this.p = w.getPlayer();
        }
Exemplo n.º 3
0
        /*
         * Grid simulation setup:
         * G = Grass, W = Water
         * |G|G|G|
         * |G|G|G|
         * |G|G|G|
         */
        public KeyDoor()
        {
            // Initialize world
            this.w = new World(Size, Size);
            // Fill world with tiles of grass
            w.FillWorld(TERRAIN.grass, new Size(Size, Size));

            // Initialize player
            w.InitPlayer(new PointF(0, 0));
            this.p = w.getPlayer();
            p.CurrentDirection = (int)Player.Direction.Down;

            // Initialize door and key
            this.d = new Door(new PointF(1, 0));
            w.addEntity(d);
            this.k = new Key(new PointF(0, 0));
            w.addEntity(k);
        }
Exemplo n.º 4
0
        public void loadLevel(String fileName)
        {
            if (fileName != null) {
                if (currentLevelPath == null || currentLevelPath != fileName) {
                    fileName = Path.Combine(StaticVariables.levelFolder, fileName + ".xml");
                } else
                {
                    fileName = currentLevelPath;
                }

                objects = new List<Entity> ();
                terrainTiles = new List<TerrainTile> ();
                heightData = new List<Byte> ();
                enemies = new List<Enemy> ();

                Door.DoorCount = 0;
                Key.KeyCount = 0;

                LevelReader level = new LevelReader (fileName);
                this.objects = level.getObjects ();

                //Pre-sort entities by Y-position for improved performance when rendering
                for (int i = 0; i < objects.Count; i++) {
                    Entity x = objects[i];
                    while ((i - 1 >= 0) && (x.getLocation().Y < objects[i - 1].getLocation().Y))
                    {
                        objects[i] = objects[i - 1];
                        i--;
                    }
                    objects[i] = x;
                }

                List<int> terrain = level.getTerrainTiles ();
                foreach (int id in terrain) {
                    terrainTiles.Add (TileTypes [id]);
                }

                Size size = level.getSize ();
                width = size.Width;
                height = size.Height;

                List<Entity> enemyEntities = objects.FindAll (e => e.getType() == ENTITIES.enemy);
                foreach (Enemy enemy in enemyEntities) {
                    enemies.Add ((Enemy)enemy);
                }

                if (StaticVariables.currentState == STATE.editor) {
                    player = null;
                    Entity focus = new Entity (ENTITIES.def, new PointF (size.Width / 2, size.Height / 2), 0);
                    setFocusEntity (focus);
                } else {
                    player = (Player)objects.FirstOrDefault (e => e.getType () == ENTITIES.player);
                    if (player == null) {
                        Random rand = new Random ();
                        player = new Player (new PointF (rand.Next (0, width), rand.Next (0, height)), 50);
                        objects.Add (player);
                    }
                    Console.WriteLine (player.getLocation ());
                    setFocusEntity (player);
                }
                currentLevelPath = fileName;
            } else {
                player = new Player(new PointF(120, 120), 50);
                FillWorld (TERRAIN.grass_normal, new Size(50, 50));
            }
            try {
                System.Media.SoundPlayer music = new System.Media.SoundPlayer(StaticVariables.musicFolder + ("/Icescape.wav"));
                music.Play();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Manually initialize player on given location
 /// </summary>
 /// <param name="location"></param>
 public void InitPlayer(PointF location)
 {
     player = new Player(location, 50);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Fill the world with given terraintile-spriteID
        /// </summary>
        /// <param name="terrain"></param>
        /// <param name="size"></param>
        public void FillWorld(TERRAIN terrain, Size size)
        {
            this.width = Math.Max(StaticVariables.minWorldSize, Math.Min(size.Width, StaticVariables.maxWorldSize));
            this.height = Math.Max(StaticVariables.minWorldSize, Math.Min(size.Height, StaticVariables.maxWorldSize));
            terrainTiles = new List<TerrainTile> ();
            objects = new List<Entity> ();

            for (int i = 0; i < width * height; i++)
            {
                terrainTiles.Add(TileTypes[(int)terrain]);
            }
            player = null;
            Entity focus = new Entity (ENTITIES.def, new PointF (size.Width / 2, size.Height / 2), 0);
            setFocusEntity (focus);
        }