Esempio n. 1
0
 public void GrabLadder(EntityLadder ladder)
 {
     Movement = MovementType.Climb;
     AnimationManager.Play(AnimationLibrary["climbLadder"]);
     ActiveLadder = ladder;
     MoveSpeed    = WalkSpeed;
     Move(new Vector2(ladder.Position.X, Position.Y));
 }
Esempio n. 2
0
 public void DismountLadder()
 {
     ProposedPosition = Position;
     Movement         = MovementType.RunWalk;
     AnimationManager.Play(AnimationLibrary["idle"]);
     ActiveLadder = null;
     OnPlayerMoved();
 }
Esempio n. 3
0
        public ActorPlayer(int id, PlayerIndex controller, Vector2 position)
        {
            ID               = id;
            Controller       = controller;
            Position         = position;
            ProposedPosition = position;
            Velocity         = new Vector2(0);
            FallVector       = new Vector2(0);
            Content          = Global.Content;

            WalkSpeed = 32f;
            RunSpeed  = 128f;
            MoveSpeed = WalkSpeed;

            Collisions  = new List <Rectangle>();
            IsColliding = false;
            IsGrounded  = true;

            CreateCollisionMask(Position, 32, 64);

            AnimationManager = new AnimationManager();
            AnimationLibrary = new Dictionary <string, Animation>();
            Facing           = ActorFacing.Right;
            Movement         = MovementType.RunWalk;
            SavedMovement    = MovementType.RunWalk;

            ActiveLadder = null;

            LoadContent();

            AnimationManager.Play(AnimationLibrary["idle"]);

            Inventory = new ActorInventory();

            InputManager.DownPressed     += OnDownPress;
            InputManager.UpPressed       += OnUpPress;
            InputManager.LeftPressed     += OnLeftPress;
            InputManager.RightPressed    += OnRightPress;
            InputManager.JumpPressed     += OnJumpPress;
            InputManager.RunPressed      += OnRunPress;
            InputManager.RunReleased     += OnRunRelease;
            InputManager.InteractPressed += OnInteractPress;
        }
Esempio n. 4
0
        /// <summary>
        /// Loads TiledMap into memory, releasing old CollisionMasks, if present
        /// </summary>
        /// <param name="mapID">ID of Map to Load</param>
        /// <returns></returns>
        public void LoadMap(string mapID)
        {
            SceneObjectLoader loader = new SceneObjectLoader();

            if (ActiveMap != null)
            {
                loader.SaveSceneObjects(MapID, TileSceneObjects);
            }

            if (CollisionSolids.Count > 0)
            {
                for (int i = CollisionSolids.Count - 1; i >= 0; i--)
                {
                    CollisionSolids.RemoveAt(i);
                }
            }
            if (TransitionHandlers.Count > 0)
            {
                for (int i = TransitionHandlers.Count - 1; i >= 0; i--)
                {
                    TransitionHandlers.RemoveAt(i);
                }
            }

            MapID = mapID;
            string assetPath = Global.GetMapAssetPathByID(MapID);

            MapToLoad = Content.Load <TiledMap>(assetPath);

            TiledMapObjectLayer collisionLayer  = MapToLoad.GetLayer <TiledMapObjectLayer>("CollisionMasks");
            TiledMapObjectLayer transitionLayer = MapToLoad.GetLayer <TiledMapObjectLayer>("Transitions");
            TiledMapObjectLayer interactive     = MapToLoad.GetLayer <TiledMapObjectLayer>("Interactive");

            if (collisionLayer.Objects.Length > 0 && collisionLayer != null)
            {
                foreach (TiledMapObject _sceneObject in collisionLayer.Objects)
                {
                    switch (_sceneObject.Name)
                    {
                    case "CollisionSolid":
                    {
                        EntityCollisionSolid _newCollisionObject = new EntityCollisionSolid(_sceneObject.Position, (int)_sceneObject.Size.Width, (int)_sceneObject.Size.Height);
                        CollisionSolids.Add(_newCollisionObject);
                        break;
                    }

                    case "CollisionSolidAngle":
                    {
                        EntityCollisionSolid _newCollision = new EntityCollisionSolid(_sceneObject.Position, (int)_sceneObject.Size.Width, (int)_sceneObject.Size.Height, float.Parse(_sceneObject.Properties["Tilt"]));
                        CollisionSolids.Add(_newCollision);
                        break;
                    }
                    }
                }
            }
            if (transitionLayer.Objects.Length > 0 && transitionLayer != null)
            {
                foreach (TiledMapObject _transition in transitionLayer.Objects)
                {
                    switch (_transition.Name)
                    {
                    case "TransitionDoor":
                    {
                        TransitionHandler transition = new TransitionHandler(_transition.Properties["MapID"], _transition.Position.X, _transition.Position.Y, float.Parse(_transition.Properties["PlayerX"]), float.Parse(_transition.Properties["PlayerY"]), _transition.Size.Width, _transition.Size.Height);
                        TransitionHandlers.Add(transition);
                        break;
                    }

                    case "TransitionDoorLocked":
                    {
                        TransitionHandler transition = new TransitionHandler(_transition.Properties["MapID"], _transition.Position.X, _transition.Position.Y, float.Parse(_transition.Properties["PlayerX"]), float.Parse(_transition.Properties["PlayerY"]), _transition.Size.Width, _transition.Size.Height);
                        if (_transition.Properties["LockType"] == "Key")
                        {
                            transition.LockWithKey(Global.GetSceneObjectBYID(_transition.Properties["KeyShortname"]), int.Parse(_transition.Properties["KeyQuantity"]));
                        }
                        if (_transition.Properties["LockType"] == "Trigger")
                        {
                            transition.LockWithTrigger(_transition.Properties["TriggerKey"]);
                        }
                        TransitionHandlers.Add(transition);
                        break;
                    }

                    case "TransitionSilent":
                    {
                        TransitionHandler transition = new TransitionHandler(_transition.Properties["MapID"], _transition.Position.X, _transition.Position.Y, float.Parse(_transition.Properties["PlayerX"]), float.Parse(_transition.Properties["PlayerY"]), _transition.Size.Width, _transition.Size.Height);
                        transition.SetAsSilent();
                        TransitionHandlers.Add(transition);
                        break;
                    }
                    }
                }
            }
            if (interactive != null && interactive.Objects.Length > 0)
            {
                foreach (TiledMapObject _interactive in interactive.Objects)
                {
                    switch (_interactive.Name)
                    {
                    case "InteractiveLadder":
                    {
                        EntityLadder ladder = new EntityLadder(_interactive.Position, (int)_interactive.Size.Width, (int)_interactive.Size.Height);
                        InteractiveEntities.Add(ladder);
                        break;
                    }
                    }
                }
            }

            ActiveMap        = MapToLoad;
            TileSceneObjects = new List <TileEntitySceneObject>(loader.LoadSceneObjects(mapID));

            BoundingBox = new Rectangle(0, 0, ActiveMap.WidthInPixels, ActiveMap.HeightInPixels);

            OnMapLoaded();
        }