Esempio n. 1
0
        public Dictionary<string, Objekt> Load(MacGame game,
                                               ContentManager content)
        {
            Dictionary<string, Objekt> levelObjects =
                new Dictionary<string, Objekt> ();

            Objekt add = null;

            foreach (ObjectInfo o in Objects) {
                switch(o.Type)
                {
                case "maker.Objekt":
                    add = new Objekt(game,o.Obj.Collidable);
                    break;
                case "maker.Tile":
                    Tile tile = (Tile)o.Obj;
                    add = new Tile(game,true);
                    //((Tile)add).SolidBottom = tile.SolidBottom;
                    //((Tile)add).SolidLeft = tile.SolidLeft;
                    //((Tile)add).SolidRight = tile.SolidRight;
                    //((Tile)add).SolidTop = tile.SolidTop;
                    break;
                case "maker.Player":
                    Player player = (Player)o.Obj;
                    add = new Player(game);
                    break;
                }

                add.Position = o.Obj.Position;
                foreach(ObjectInfo.Action a in o.Actions)
                {
                    add.AddSprite(a.Name, new Sprite(content,a.Asset));
                }

                levelObjects.Add(o.Name,add);
            }

            return levelObjects;
        }
Esempio n. 2
0
        public override void LoadContent()
        {
            MacGame _game = (MacGame)ScreenManager.Game;
            Camera camera = ((MacGame)ScreenManager.Game).camera;

            pixel = new Texture2D(_game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);

            pixel.SetData(new[] { Color.White });

            //            _objekts.Add("bg1", new Objekt(
            //                                           _game.spriteBatch, _game.graphics, _game.camera,false));
            //            _objekts.Add("bg2", new Objekt(
            //                                           _game.spriteBatch, _game.graphics, _game.camera, false));
            //            _objekts.Add("bg3", new Objekt(
            //                                           _game.spriteBatch, _game.graphics, _game.camera, false));
            //            _objekts.Add("bg4", new Objekt(
            //                                           _game.spriteBatch, _game.graphics, _game.camera, false));

            //            _objekts["bg1"].AddSprite("bg1", new Sprite(_game.Content, "Background01"));
            //            _objekts["bg2"].AddSprite("bg2", new Sprite(_game.Content, "Background02"));
            //            _objekts["bg3"].AddSprite("bg3", new Sprite(_game.Content, "Background03"));
            //            _objekts["bg4"].AddSprite("bg4", new Sprite(_game.Content, "Background05"));

            //            _objekts["bg1"].SelectedAction = "bg1";
            //            _objekts["bg2"].SelectedAction = "bg2";
            //            _objekts["bg3"].SelectedAction = "bg3";
            //            _objekts["bg4"].SelectedAction = "bg4";

            //            _objekts["bg1"].Scale = 3.0f;
            //            _objekts["bg2"].Scale = 3.0f;
            //            _objekts["bg3"].Scale = 3.0f;
            //            _objekts["bg4"].Scale = 3.0f;
            //
            //            _objekts["bg1"].Position = new Vector2(0,-100);
            //            _objekts["bg2"].Position = new Vector2(_objekts["bg1"].Position.X + _objekts["bg1"].Size.Width, -100);
            //            _objekts["bg3"].Position = new Vector2(_objekts["bg2"].Position.X + _objekts["bg2"].Size.Width, -100);
            //            _objekts["bg4"].Position = new Vector2(_objekts["bg3"].Position.X + _objekts["bg3"].Size.Width, -100);

            //            for(int i = 0; i < 32; i++){
            //                _objekts.Add("tile" + i.ToString(),
            //                             new Tile(
            //                         _game.spriteBatch,
            //                         _game.graphics,
            //                         _game.camera,
            //                         true));
            //                _objekts["tile" + i.ToString()].AddSprite("tile", new Sprite(_game.Content, "Ground"));
            //                _objekts["tile" + i.ToString()].SelectedAction = "tile";
            //                _objekts["tile" + i.ToString()].Position = new Vector2(i * 32,650);
            //                ((Tile)_objekts["tile" + i.ToString()]).SolidTop = true;
            //            }
            //

            //            for(int i = 0; i < 32; i++){
            //                _objekts.Add("tileA" + i.ToString(),
            //                             new Tile(
            //                         _game.spriteBatch,
            //                         _game.graphics,
            //                         _game.camera, true));
            //                _objekts["tileA" + i.ToString()].AddSprite("tile", new Sprite(_game.Content, "Ground"));
            //                _objekts["tileA" + i.ToString()].SelectedAction = "tile";
            //                _objekts["tileA" + i.ToString()].Position = new Vector2((i + 30) * 32,550);
            //                ((Tile)_objekts["tileA" + i.ToString()]).SolidTop = true;
            //            }

            //            _objekts.Add("hero",
            //                         new Player(
            //                       _game.spriteBatch,
            //                       _game.graphics,
            //                       _game.camera));
            //
            //            _objekts["hero"].AddSprite("right",new Sprite(_game.Content, "maker_walk", 1, 4));
            //            _objekts["hero"].AddSprite("left",new Sprite(_game.Content, "maker_walk_left", 1, 4));
            //            _objekts["hero"].SelectedAction = "right";
            //            _objekts["hero"].Position = new Vector2(10, 100);
            //
            //            _objekts.Add("mouse-pointer",
            //                         new Objekt(
            //                       _game.spriteBatch, _game.graphics, _game.camera, false));
            //            _objekts["mouse-pointer"].AddSprite("point", new Sprite(_game.Content, "mouse-pointer"));
            //            _objekts["mouse-pointer"].SelectedAction = "point";
            //            _objekts["mouse-pointer"].Position = new Vector2(0,0);

            selected_tile = new Tile(
                (MacGame)ScreenManager.Game, true);

            selected_tile.AddSprite("tile", new Sprite(ScreenManager.Game.Content, "Ground2"));
            selected_tile.SelectedAction = "tile";

            //Level level = new Level("Level1");
            //level.Save(_objekts);
            //string output = JsonConvert.SerializeObject(level,Formatting.Indented);
            //File.WriteAllText(@"/Users/Fritz/Documents/level1.json", output);

            //string levelfile = File.ReadAllText(@"/Users/Fritz/Documents/level1.json");

            //level = JsonConvert.DeserializeObject<Level>(levelfile);

            _objekts = LevelLoader.Load("Level1",_game, ScreenManager.Game.Content);
               // _objekts["mouse-pointer"] = new MousePointer(_game);
        }
Esempio n. 3
0
        public static Dictionary<string, Objekt> Load(string fileName,
                                                       MacGame game,
                                                       ContentManager content)
        {
            Dictionary<string, Objekt> gameObjekts = new Dictionary<string, Objekt>();

            string levelFile = File.ReadAllText (@"/Users/Fritz/Documents/level_Save.json");
            JObject l = JObject.Parse (levelFile);

            Level level = new Level ((string)l ["Name"]);
            JArray objekts = (JArray)l ["Objects"];
            Objekt o = null;
            for (int i = 0; i < objekts.Count; i++) {
                JObject obj = (JObject)objekts[i];
                Objekt add = null;
                JObject gObject = (JObject)obj["Obj"];
                JArray actions = (JArray)obj["Actions"];

                switch((string)obj["Type"])
                {
                    case "maker.Objekt":
                        add = new Objekt(game,false);
                        LoadActions(add, actions, game);
                        break;
                    case "maker.Tile":
                        add = new Tile(game,true);
                        ((Tile)add).SolidBottom = (bool)gObject["SolidBottom"];
                        ((Tile)add).SolidLeft = (bool)gObject["SolidLeft"];
                        ((Tile)add).SolidRight = (bool)gObject["SolidRight"];
                        ((Tile)add).SolidTop = (bool)gObject["SolidTop"];
                        LoadActions(add, actions, game);
                        break;
                    case "maker.Player":
                        add = new Player(game);
                        break;
                    case "maker.MousePointer":
                        add = new MousePointer(game);
                        break;
                }

                //JObject gObject = (JObject)obj["Obj"];
                bool collidable = (bool)gObject["Collidable"];
                JObject position = (JObject)gObject["Position"];
                add.Position = new Vector2((float)position["X"],
                                           (float)position["Y"]);

                string firstAction = (string)actions[0]["Name"];
                float scale = (float)actions[0]["Scale"];

                add.Scale = scale;
                add.Name = (string)obj["Name"];
                gameObjekts.Add((string)obj["Name"], add);
            }

            return gameObjekts;
        }
Esempio n. 4
0
 public Object Clone()
 {
     Tile c = new Tile(this._game, this.Collidable);
     c.AddSprite("tile",(Sprite)this._sprite.Clone());
     c.SelectedAction = "tile";
     return c;
 }