Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
 public static void Save(Level level)
 {
 }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (IsActive && !coveredByOtherScreen)
            {
                Camera camera = ((MacGame)ScreenManager.Game).camera;
                Player player = ((Player)_objekts["hero"]);

                if(Mouse.GetState().LeftButton == ButtonState.Pressed){
                    int x = Mouse.GetState().X + (int)camera.Position.X;
                    int y = Mouse.GetState().Y + (int)camera.Position.Y;

                    if(!_objekts.ContainsKey("tileB" + x.ToString() + y.ToString()))
                    {
                        MousePointer pointer = (MousePointer)_objekts["mouse-pointer"];

                        Objekt newO = new Objekt();
                        if(selected_tile == null)
                        {
                            pointer.State = MousePointer.MouseState.Erase;
                        }
                        else
                        {
                            newO = (Tile)selected_tile.Clone();
                            newO.Position = new Vector2(x,y);
                            newO.WorldPosition = true;
                            newO.SelectedAction = "tile";
                            pointer.State = MousePointer.MouseState.Point;
                        }

                        List<Collision> mouseCollisions = Collided(pointer);
                        if(pointer.State == MousePointer.MouseState.Point
                           && mouseCollisions.Count == 0)
                        {
                            newO.Name = "tileB" + x.ToString() + y.ToString();
                            _objekts.Add("tileB" + x.ToString() + y.ToString(),
                                        newO);
                        }
                        else if(pointer.State == MousePointer.MouseState.Erase
                                && mouseCollisions.Count > 0)
                        {
                            foreach(Collision c in mouseCollisions)
                            {
                                _objekts.Remove(c.CollidedObjekt.Name);
                            }
                        }
                    }
                }

                if(Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.S)){
                    Level level = new Level("Level1");
                    level.Save(_objekts);
                    string output = JsonConvert.SerializeObject(level,Formatting.Indented);
                    File.WriteAllText(@"/Users/Fritz/Documents/level_Save.json", output);
                }

                if(Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Tab)){
                    TileScreen tileScreen = new TileScreen();
                    tileScreen.TitleText = "Maker";
                    ScreenManager.AddScreen(tileScreen, "Tile");
                }

                if(Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.A)){
                    player.playerStates["LEFT"] = true;
                    player.playerStates["RIGHT"] = false;
                }

                if(Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.D)){
                    player.playerStates["RIGHT"] = true;
                    player.playerStates["LEFT"] = false;
                }

                if(!_jump)
                {
                    if(Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Space)){
                        if(player.playerStates["FALL"] == false){
                            player.playerStates["JUMP"] = true;
                            _jump = true;
                        }
                    }
                }

                if(_jump)
                {
                    if(Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.Space)){
                        if(player.playerStates["JUMP"] == true){
                            player.playerStates["JUMP"] = false;
                        }
                        _jump = false;
                    }
                }

                List<Collision> collisions = Collided(player);
                if(collisions.Count > 0){
                    foreach(Collision col in collisions)
                    {
                        if(col.Side == CollisionSide.Bottom)
                        {
                            player.playerStates["FALL"] = false;
                        }
                        if(col.Side == CollisionSide.Right)
                        {
                            player.playerStates["RIGHT"] = false;
                        }
                        if(col.Side == CollisionSide.Left)
                        {
                            player.playerStates["LEFT"] = false;
                        }
                        if(col.Side == CollisionSide.Top)
                        {
                            player.playerStates["FALL"] = true;
                            player.playerStates["JUMP"] = false;
                        }
                    }
                    //System.Console.WriteLine("Collided:" + kvp.Key);
                }
                else{
                    if(player.playerStates["JUMP"] == false){
                        player.playerStates["FALL"] = true;
                    }
                }

                player.Actions();

                _objekts["mouse-pointer"].Position =
                    new Vector2(Mouse.GetState().X + (int)camera.Position.X,
                                Mouse.GetState().Y + (int)camera.Position.Y);

                if(player.Position.X > ((MacGame)ScreenManager.Game).graphics.GraphicsDevice.DisplayMode.Width / 2)
                    camera.Position =
                        new Vector2(player.Position.X - ((MacGame)ScreenManager.Game).graphics.GraphicsDevice.DisplayMode.Width / 2,0);
                if(player.Position.Y > 720)
                    player.Position = new Vector2(player.Position.X, 0);
                // TODO: Add your update logic here
                //screenManager.Update(gameTime);

                //Session.Update(gameTime);
            }
        }