public ChestOpenCommand(Player player, IWorldItem item, CollisionSides side)
 {
     myPlayer = player;
     //mySword = playerSword;
     myItem = item;
     mySide = side;
 }
Exemple #2
0
        public void Update()
        {
            colliders = myRoom.GetColliders();
            colliders.AddRange(myPlayer.GetColliders());
            Rectangle subjectRectangle, targetRectangle;

            foreach (ICollider subject in colliders)
            {
                foreach (ICollider target in colliders)
                {
                    if (subject == target)
                    {
                        continue;
                    }

                    subjectRectangle = subject.GetRectangle();
                    targetRectangle  = target.GetRectangle();

                    if (CheckCollision(subjectRectangle, targetRectangle))
                    {
                        CollisionSides orientation = GetOrientation(subjectRectangle, targetRectangle);
                        Console.WriteLine("{0} hit {1} side of {2}", target, orientation, subject);
                        responder.HandleCollision(subject, target, orientation);
                    }
                }
            }
            foreach (ICollider collider in delete)
            {
                colliders.Remove(collider);
            }
        }
 public TransportRoomCommand(Game1 game, Player player, Door door, CollisionSides side)
 {
     myGame   = game;
     myPlayer = player;
     myDoor   = door;
     mySide   = side;
 }
Exemple #4
0
 public UnlockDoorCommand(Game1 game, Player player, LockedDoor door, CollisionSides side)
 {
     this.myGame   = game;
     this.myPlayer = player;
     this.mySide   = side;
     this.myDoor   = door;
     roomID        = myGame.currentGamePlayState.CurrentRoom.roomID;
 }
Exemple #5
0
        public CollisionSides GetOrientation(Rectangle subject, Rectangle target)
        {
            float          dx       = subject.Center.X - target.Center.X;
            float          dy       = subject.Center.Y - target.Center.Y;
            CollisionSides xSide    = dx > 0 ? CollisionSides.Left : CollisionSides.Right;
            CollisionSides ySide    = dy > 0 ? CollisionSides.Up : CollisionSides.Down;
            float          xGap     = Math.Abs(dx) - (subject.Width / 2) - (target.Width / 2);
            float          yGap     = Math.Abs(dy) - (subject.Height / 2) - (target.Height / 2);
            float          xOverlap = Math.Max(0, -xGap);
            float          yOverlap = Math.Max(0, -yGap);

            // Choose the direction of the smaller overlap.
            return(yOverlap > xOverlap ? xSide : ySide);
        }
Exemple #6
0
        public void GoToRoom(Room room2, CollisionSides side)
        {
            GameScreenTextureStorage.Instance.SaveScreen(spriteBatch);
            Room room1 = currentGamePlayState.CurrentRoom;

            Map.visitedRoom.Add(room1);
            string targetID = room2.roomID;

            foreach (Room rm in Map.visitedRoom)
            {
                if (rm.roomID == targetID)
                {
                    room2 = rm;
                }
            }
            currentGamePlayState = new GamePlayState(this, room2);
            currentState         = new RoomTransitionState(this, room1, room2, side);
        }
Exemple #7
0
        public void HandleCollision(ICollider subject, ICollider target, CollisionSides side)
        {
            Type subjectType = subject.GetType();
            Type targetType  = target.GetType();

            if (targetType == typeof(EmptyRoomNotifier))
            {
                Console.WriteLine("die");
            }
            Tuple <Type, Type, CollisionSides> key = new Tuple <Type, Type, CollisionSides>(subjectType, targetType, side);

            if (keySet.Contains(key))
            {
                Type commandType = commandMap[key];
                Console.WriteLine(commandType);
                ICommand commandClass = parseConstructor(subject, target, side, commandType);

                if (commandClass != null)
                {
                    commandClass.Execute();
                }
            }
        }
Exemple #8
0
 public EnemyTakeDamageCommand(INpc npc, CollisionSides side)
 {
     this.npc  = npc;
     this.side = side;
 }
Exemple #9
0
        public RoomTransitionState(Game1 game, Room room1, Room room2, CollisionSides side)
        {
            this.game  = game;
            this.room1 = room1;
            this.room2 = room2;
            mySide     = side;

            scrolling   = 0;
            scrollSpeed = 2;

            if (side == CollisionSides.Right || side == CollisionSides.Left)
            {
                delayLeft = 130;
            }
            else
            {
                delayLeft = 90;
            }

            texture      = RoomTextureStorage.Instance.getRoomSpriteSheet();
            sourceRoom1  = RoomTextureStorage.ROOM_RECTS[room1.roomID];
            sourceRoom2  = RoomTextureStorage.ROOM_RECTS[room2.roomID];
            borderSource = RoomTextureStorage.BORDER;

            adjacentRooms1 = Map.adjacencies[room1.roomID];
            adjacentRooms2 = Map.adjacencies[room2.roomID];
            if (adjacentRooms1[0].Equals("-1"))
            {
                topDoor1 = RoomTextureStorage.TOP_NO_DOOR;
            }
            else if (adjacentRooms1[0].EndsWith("1"))
            {
                topDoor1 = RoomTextureStorage.TOP_LOCKED_DOOR;
                System.Console.WriteLine("HEREEEE");
            }
            else
            {
                topDoor1 = RoomTextureStorage.TOP_OPEN_DOOR;
            }
            if (adjacentRooms1[1].Equals("-1"))
            {
                bottomDoor1 = RoomTextureStorage.BOTTOM_NO_DOOR;
            }
            else if (adjacentRooms1[1].EndsWith("1"))
            {
                bottomDoor1 = RoomTextureStorage.BOTTOM_LOCKED_DOOR;
            }
            else
            {
                bottomDoor1 = RoomTextureStorage.BOTTOM_OPEN_DOOR;
            }
            if (adjacentRooms1[2].Equals("-1"))
            {
                leftDoor1 = RoomTextureStorage.LEFT_NO_DOOR;
            }
            else if (adjacentRooms1[2].EndsWith("1"))
            {
                leftDoor1 = RoomTextureStorage.LEFT_LOCKED_DOOR;
            }
            else
            {
                leftDoor1 = RoomTextureStorage.LEFT_OPEN_DOOR;
            }
            if (adjacentRooms1[3].Equals("-1"))
            {
                rightDoor1 = RoomTextureStorage.RIGHT_NO_DOOR;
            }
            else if (adjacentRooms1[3].EndsWith("1"))
            {
                rightDoor1 = RoomTextureStorage.RIGHT_LOCKED_DOOR;
            }
            else
            {
                rightDoor1 = RoomTextureStorage.RIGHT_OPEN_DOOR;
            }

            if (adjacentRooms2[0].Equals("-1"))
            {
                topDoor2 = RoomTextureStorage.TOP_NO_DOOR;
            }
            else if (adjacentRooms2[0].EndsWith("1"))
            {
                topDoor2 = RoomTextureStorage.TOP_LOCKED_DOOR;
            }
            else
            {
                topDoor2 = RoomTextureStorage.TOP_OPEN_DOOR;
            }
            if (adjacentRooms2[1].Equals("-1"))
            {
                bottomDoor2 = RoomTextureStorage.BOTTOM_NO_DOOR;
            }
            else if (adjacentRooms2[1].EndsWith("1"))
            {
                bottomDoor2 = RoomTextureStorage.BOTTOM_LOCKED_DOOR;
            }
            else
            {
                bottomDoor2 = RoomTextureStorage.BOTTOM_OPEN_DOOR;
            }
            if (adjacentRooms2[2].Equals("-1"))
            {
                leftDoor2 = RoomTextureStorage.LEFT_NO_DOOR;
            }
            else if (adjacentRooms2[2].EndsWith("1"))
            {
                leftDoor2 = RoomTextureStorage.LEFT_LOCKED_DOOR;
            }
            else
            {
                leftDoor2 = RoomTextureStorage.LEFT_OPEN_DOOR;
            }
            if (adjacentRooms2[3].Equals("-1"))
            {
                rightDoor2 = RoomTextureStorage.RIGHT_NO_DOOR;
            }
            else if (adjacentRooms2[3].EndsWith("1"))
            {
                rightDoor2 = RoomTextureStorage.RIGHT_LOCKED_DOOR;
            }
            else
            {
                rightDoor2 = RoomTextureStorage.RIGHT_OPEN_DOOR;
            }
        }
Exemple #10
0
        public ICommand parseConstructor(ICollider subject, ICollider target, CollisionSides side, Type commandType)
        {
            Type targetType  = target.GetType();
            Type subjectType = subject.GetType();

            // Search for a valid constructor for this commandType.
            List <Type[]> signatures = new List <Type[]> {
                new Type[] { targetType },
                new Type[] { typeof(Game1) },
                new Type[] { targetType, typeof(CollisionSides) },
                new Type[] { targetType, typeof(Room) },
                new Type[] { subjectType, targetType, typeof(CollisionSides) },
                new Type[] { subjectType, targetType, typeof(Room) },
                new Type[] { typeof(Game1), subjectType, targetType, typeof(CollisionSides) },
            };

            ConstructorInfo commandConstructor = null;

            foreach (Type[] signature in signatures)
            {
                commandConstructor = commandType.GetConstructor(signature);
                if (commandConstructor != null)
                {
                    break;
                }
            }
            if (commandConstructor == null)
            {
                return(null);
            }

            // Now invoke the constructor.
            switch (commandConstructor.GetParameters().Length)
            {
            case 1:
                if (commandConstructor.GetParameters()[0].ParameterType == typeof(Game1))
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { myGame }));
                }
                else
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { target }));
                }

            case 2:
                if (commandConstructor.GetParameters()[1].ParameterType == typeof(Room))
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { target, myRoom }));
                }
                else
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { target, side }));
                }

            case 3:
                if (commandConstructor.GetParameters()[2].ParameterType == typeof(Room))
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { subject, target, myRoom }));
                }
                else
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { subject, target, side }));
                }

            case 4:
                return((ICommand)commandConstructor.Invoke(new object[] { myGame, subject, target, side }));

            default:
                return(null);
            }
        }
Exemple #11
0
 public ResetCommand(Player player, CollisionSides side)
 {
     myPlayer = player;
     mySide   = side;
 }
Exemple #12
0
 public ThunderDomeWaveCommand(Game1 game, Player player, ICollider collider, CollisionSides side)
 {
     myGame     = game;
     myCollider = collider;
 }
 public ResetNPCCommand(INpc npc, CollisionSides side)
 {
     this.npc  = npc;
     this.side = side;
 }