Пример #1
0
        public static bool BoundingCollision3(Objekt a, Objekt b)
        {
            if(a.Bounds.Intersects(b.Bounds))
                return true;

            return false;
        }
Пример #2
0
        public static bool BoundingCollision2(Objekt a, Objekt b)
        {
            // check if their bounding boxes touch
            if( b.Bounds.X + b.Bounds.Width < a.Bounds.X )
            {
                return false;
            }

            if( b.Bounds.X > a.Bounds.X + a.Bounds.Width )
            {
                return false;
            }

            if( b.Bounds.Y + b.Bounds.Height< a.Bounds.Y )
            {
                return false;
            }

            if( b.Bounds.Y > a.Bounds.Y + a.Bounds.Height )
            {
                return false;
            }

            // bounding boxes intersect
            return true;
        }
Пример #3
0
        public static bool BoundingCollision(Objekt a, Objekt b)
        {
            Rectangle rectangleA = a.Bounds;
            Rectangle rectangleB = b.Bounds;
            // Find the bounds of the rectangle intersection
            int top = Math.Max(rectangleA.Top, rectangleB.Top);
            int bottom = Math.Min(rectangleA.Bottom, rectangleB.Bottom);
            int left = Math.Max(rectangleA.Left, rectangleB.Left);
            int right = Math.Min(rectangleA.Right, rectangleB.Right);

            if (top >= bottom || left >= right)
                return false;

            return true;
        }
Пример #4
0
        public static Collision Collided(Objekt o1, Objekt o2)
        {
            if(Utility.BoundingCollision3(o1, o2)){
                Collision collided = new Collision();

                if(o1.Bottom.Intersects(o2.Bounds))
                {
                    collided.Side = CollisionSide.Bottom;
                    collided.CollidedObjekt = o2;
                    System.Console.WriteLine("Bottom: " + o2.GetType().Name);
                    return collided;
                }

                if(o1.Top.Intersects(o2.Bounds))
                {
                    collided.Side = CollisionSide.Top;
                    collided.CollidedObjekt = o2;
                    System.Console.WriteLine("Top: " + o2.GetType().Name);
                    return collided;
                }

                if(o1.Right.Intersects(o2.Bounds))
                {
                    collided.Side = CollisionSide.Right;
                    collided.CollidedObjekt = o2;
                    System.Console.WriteLine("Right: " + o2.GetType().Name);
                    return collided;
                }

                if(o1.Left.Intersects(o2.Bounds))
                {
                    collided.Side = CollisionSide.Left;
                    collided.CollidedObjekt = o2;
                    System.Console.WriteLine("Left: " + o2.GetType().Name);
                    return collided;
                }

                collided.Side = CollisionSide.Unknown;
                collided.CollidedObjekt = o2;
                return collided;
            }

            return null;
        }
Пример #5
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;
        }
Пример #6
0
        private static void LoadActions(Objekt o, JArray actions, MacGame game)
        {
            //JArray actions = (JArray)obj["Actions"];
            string firstAction = (string)actions[0]["Name"];
            int rows = 0;
            int cols = 0;

            for(int i2 = 0; i2 < actions.Count; i2++)
            {
                rows = (int)actions[i2]["Rows"];
                cols = (int)actions[i2]["Columns"];
                //scale = (float)actions[i2]["Scale"];
                if(rows == 0 && cols == 0)
                {
                    o.AddSprite((string)actions[i2]["Name"],
                                  new Sprite(game.Content, (string)actions[i2]["Asset"]));
                }
                else
                {
                    o.AddSprite((string)actions[i2]["Name"],
                                  new Sprite(game.Content, (string)actions[i2]["Asset"],rows,cols));
                }
            }

            o.SelectedAction = firstAction;
        }
Пример #7
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;
        }
Пример #8
0
        protected List<Collision> Collided(Objekt o)
        {
            List<Collision> collisions = new List<Collision>();

            foreach(KeyValuePair<string, Objekt> kvp in _objekts){
                if(kvp.Value.InScreen() && !kvp.Value.Equals(o) && kvp.Value.Collidable){
                    Collision col = Collision.Collided(o, kvp.Value);

                    if(col != null){
                        collisions.Add(col);
                    }
                }
            }

            return collisions;
        }
Пример #9
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);
            }
        }
Пример #10
0
 protected Collision Collided(Objekt o)
 {
     foreach(KeyValuePair<string, Tile> kvp in tiles){
         if(!kvp.Value.Equals(o) && kvp.Value.Collidable){
             Collision clicked = Collision.Collided(o, kvp.Value);
             if(clicked != null){
                 return clicked;
             }
         }
     }
     return null;
 }
Пример #11
0
        /// <summary>
        /// Load the graphics content
        /// </summary>
        /// <param name="batch">SpriteBatch object</param>
        /// <param name="screenWidth">Width of the screen</param>
        /// <param name="screenHeight">Height of the screen</param>
        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;
            tiles = new Dictionary<string, Tile>();

            backgroundTexture =
                content.Load<Texture2D>(@"Textures\GameScreens\PopupScreen");

            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;

            backgroundPosition.X = (viewport.Width - backgroundTexture.Width) / 2;
            backgroundPosition.Y = (viewport.Height - backgroundTexture.Height) / 2;

            titlePosition.X = (viewport.Width -
                               Fonts.HeaderFont.MeasureString(titleText).X) / 2;
            titlePosition.Y = backgroundPosition.Y + 70f;

            tiles.Add("Ground", new Tile((MacGame)ScreenManager.Game, true));

            tiles["Ground"].AddSprite("tile", new Sprite(content, "Ground", false));
            tiles["Ground"].Position = new Vector2(backgroundPosition.X + 20,
                                                   backgroundPosition.Y + 100);
            tiles["Ground"].SelectedAction = "tile";

            tiles.Add("Ground2", new Tile((MacGame)ScreenManager.Game, true));

            tiles["Ground2"].AddSprite("tile", new Sprite(content, "Ground2", false));

            tiles["Ground2"].Position = new Vector2(backgroundPosition.X + 60,
                                                   backgroundPosition.Y + 100);

            tiles["Ground2"].SelectedAction = "tile";

            tiles.Add("Eraser", new Tile(
                (MacGame)ScreenManager.Game, true));

            tiles["Eraser"].AddSprite("eraser", new Sprite(content, "eraser", false));
            tiles["Eraser"].Position = new Vector2(backgroundPosition.X + 550,
                                                   backgroundPosition.Y + 400);
            tiles["Eraser"].SelectedAction = "eraser";

            mouse = new Objekt((MacGame)ScreenManager.Game, true);

            mouse.AddSprite("point",new Sprite(content, "mouse-pointer",false));
            mouse.SelectedAction = "point";
            mouse.Position = new Vector2(0,0);
        }