/// <summary> /// Checks two GameObject's to see if they collide. /// </summary> /// <param name="obj1">The first object.</param> /// <param name="obj2">The second object.</param> /// <returns>True if there is a collision. False otherwise.</returns> public static bool CheckBoundingBoxCollision(GameObject obj1, GameObject obj2) { if (((obj1.HitBox.X + obj1.HitBox.Width >= obj2.HitBox.X) && (obj1.HitBox.X <= obj2.HitBox.X + obj2.HitBox.Width)) && ((obj1.HitBox.Y + obj1.HitBox.Height >= obj2.HitBox.Y) && (obj1.HitBox.Y <= obj2.HitBox.Y + obj2.HitBox.Height))) return true; return false; }
/// <summary> /// Creates a new Room object. /// </summary> /// <param name="roomName">The name of the room that is to be created.</param> /// <param name="content">The content manager to use for assets.</param> /// <param name="doorIndex">The index of the door to enter from. If no index is specified, or the index is -1, /// the room's default spawn location will be used.</param> public Room(String name, int doorIndex) { roomName = name; Content = new ContentManager(GameResources.GameServices, "Content"); soundEngine = new AudioEngine(Content, roomName); isLoaded = false; Load("Data/Rooms/" + roomName + ".txt", doorIndex); if (isPersistant) LoadRoomState(); collisionMap = Content.Load<Texture2D>("Images/" + graphicsName + "Collisions"); collisionColors = new Color[collisionMap.Width * collisionMap.Height]; collisionMap.GetData<Color>(collisionColors); background = new GameObject(graphicsName, Content); background.Spawn(new Vector2(0, 0)); if (hasLighting) { lightingMap = new GameObject(graphicsName + "LightingMap", Content); lightingMap.Spawn(new Vector2(0, 0)); } }
/// <summary> /// Interacts with the given object and interaction type. /// </summary> /// <param name="otherObject">The object to interaction type.</param> /// <param name="interactionType">The type of interaction to take place.</param> public override InteractionActions InteractWith(GameObject otherObject, InteractionTypes interactionType) { if (otherObject.ItemType != ItemList.NullItem && interactionType == InteractionTypes.Collision) { PickUpItem(otherObject); } else { switch (otherObject.ObjectName) { case "Door": if (interactionType == InteractionTypes.PlayerAction) { Door door = (Door)otherObject; if (!door.IsOpen) { if (!itemArray[(byte)door.LockType]) hudCallback("This door is locked.", false, true); else if (door.LinkedRoomName == "(unassigned)") hudCallback("This door appears to go nowhere.", false, true); else door.Open(); return InteractionActions.None; } } else if (!otherObject.IsSolid && interactionType == InteractionTypes.Collision) { Door door = (Door)otherObject; if (door.IsRoomLoaded) roomCallback(door.LinkedRoom); else { loadingDoor = door; GameManager.ToggleFreeze(true); hudCallback("Loading room...", false, false); } if (door.Orientation == Door.DoorOrientations.FacingLeft) ResetActionStates(XDirection.Right); else ResetActionStates(XDirection.Left); return InteractionActions.None; } break; case "SavePoint": if (interactionType == InteractionTypes.PlayerAction) { currentHealth = maxHealth; saveCallback(); return InteractionActions.None; } break; case "Lever": if (interactionType == InteractionTypes.PlayerAction) { otherObject.SwitchLever(); return InteractionActions.Lever; } break; default: return InteractionActions.None; } } return InteractionActions.None; }
/// <summary> /// Picks up the designated item, despawning it and adding it to the player's inventory. /// </summary> /// <param name="item">The item that was picked up.</param> private void PickUpItem(GameObject item) { itemArray[(byte)item.ItemType] = true; item.Despawn(); if (item.IsKey) soundEngine.Play(AudioEngine.SoundEffects.KeyGet); else if (item.IsPowerup) { soundEngine.Play(AudioEngine.SoundEffects.ItemGet); string info = null; switch (item.ObjectName) { case "DashPowerup": info = "You got the dash powerup!\nUse the triggers (or Q on a keyboard) to dash, even in midair."; break; } if (info != null) hudCallback(info, true, true); } }
/// <summary> /// Searches the current room for the nearest valid interactable object and returns it if /// one is in range /// </summary> /// <returns>The nearest object</returns> private GameObject FindInteractionObject(GameObject initiator, InteractionTypes interactionType) { GameObject nearestObject = currentRoom.GetNearestObject(initiator.InteractionPoint, player.InteractionDistance, interactionType); return nearestObject; }
/// <summary> /// Deals with object interactions between each other. /// </summary> /// <param name="otherObject">The other object to interact with.</param> public virtual InteractionActions InteractWith(GameObject otherObject, InteractionTypes interactionType) { // TODO: Add the interaction chart for each possible object interaction. // The owner of this method is considered the "initiator" of the interaction return InteractionActions.None; }