/// <summary> /// Unload contents /// </summary> public override void UnloadContent() { PixelCollision.Dispose(); if (Logo != null) { Logo.Dispose(); } if (Star != null) { Star.Dispose(); } if (Font != null) { Font.Dispose(); } if (Sprite != null) { Sprite.Dispose(); } Sprite = null; }
/// <summary> /// Load contents /// </summary> public override void LoadContent() { // Clear color of the screen Display.RenderState.ClearColor = Color.LightGray; // Mouse.Visible = false; if (!PixelCollision.Init()) { MessageBox.Show("GL_ARB_occlusion_query not found !", "Unsupported extension"); Exit(); } // Textures Logo = new Texture2D("data/logo.png"); Star = new Texture2D("data/star.png"); // Font Sprite = new SpriteBatch(); Font = BitmapFont.CreateFromTTF(@"c:\windows\fonts\verdana.ttf", 14, FontStyle.Regular); }
public void InspectObject(PixelCollision pc) { // Inspected object is a door PixelDoor door = pc.pixelCollider.transform.parent.GetComponent <PixelDoor>(); if (door != null) { if (door.interactionDirection != Direction.All && pc.direction != Direction.All) { if (door.interactionDirection != pc.direction) { return; } if (facingDirection.x > 0 && facingDirection.y > 0 && door.interactionDirection != Direction.NE) { return; } if (facingDirection.x > 0 && facingDirection.y < 0 && door.interactionDirection != Direction.SE) { return; } if (facingDirection.x < 0 && facingDirection.y > 0 && door.interactionDirection != Direction.NW) { return; } if (facingDirection.x < 0 && facingDirection.y < 0 && door.interactionDirection != Direction.SW) { return; } } animator.SetTrigger(Animator.StringToHash("IsInteract")); EnterDoor(door); return; } // Inspected object is an item PixelItem item = pc.pixelCollider.transform.parent.GetComponent <PixelItem>(); if (item != null) { CharacterInventory inv = GetComponentInChildren <CharacterInventory>(); Debug.Assert(inv != null); bool succeed = inv.AddItem(item); if (succeed) { animator.SetTrigger(Animator.StringToHash("IsPickup")); item.gameObject.SetActive(false); item.transform.parent = inv.transform; } return; } // Inspected object is a character currentlySpeakingTo = pc.pixelCollider.transform.parent.GetComponent <Character>(); if (currentlySpeakingTo == this) { currentlySpeakingTo = null; // Cannot talk to one self } if (currentlySpeakingTo != null) { Talk(); } }
/// <summary> /// Called when it is time to draw a frame. /// </summary> public override void Draw() { // Clears the background Display.ClearBuffers(); #region First draw // Sprite.Begin(SpriteBlendMode.Additive, SpriteSortMode.Deferred, false); Sprite.Begin(); // Draw the logo DrawLogo(); // Draw the star if (PixelCollision.Count > 0) { StarColor = Color.Red; } else { StarColor = Color.White; } // Draws the star Sprite.Draw(Star, new Vector2(Mouse.Location.X, Mouse.Location.Y), StarColor); Sprite.End(); #endregion #region Occlusion query PixelCollision.Begin(0.1f); Sprite.Begin(); DrawLogo(); Sprite.End(); // Begin query PixelCollision.BeginQuery(); Sprite.Begin(); Sprite.Draw(Star, new Vector2(Mouse.Location.X, Mouse.Location.Y), StarColor); Sprite.End(); PixelCollision.EndQuery(); PixelCollision.End(); #endregion // Some text Sprite.Begin(); Sprite.DrawString(Font, new Vector2(10, 30), Color.Red, "Count {0}", PixelCollision.Count); Sprite.DrawString(Font, new Vector2(10, 45), Color.Red, "Mouse {0}", new Vector2(Mouse.Location.X, Mouse.Location.Y)); Sprite.End(); }
void MouseClicked() { if (DebugWindowOpen) { return; } if (Input.GetMouseButtonDown(0)) { Vector3 castStart = mousePosition; castStart.z = -10.0f; RaycastHit2D[] raycastHits = Physics2D.CircleCastAll(mousePosition, 30.0f, Vector2.zero); // Detected inspected objects foreach (var hit in raycastHits) { GameObject obj = hit.collider.gameObject; if (obj == this) { continue; } PixelCollider pixelCollider = obj.GetComponent <PixelCollider>(); if (pixelCollider != null) { if (pixelCollider.inspectChildObjects) { continue; } PixelCollider characterCollider = this.GetComponentInChildren <PixelCollider>(); if (pixelCollider.GetPixelRoom() != characterCollider.GetPixelRoom()) { continue; } if (pixelCollider.transform.parent.name == "VirtualObject") { continue; } if (pixelCollider.transform.parent.name == "Player") { continue; } bool withinCollider = pixelCollider.CheckForWithinCollider(mousePosition); if (withinCollider) { Debug.Log(pixelCollider.transform.parent.name); NavigateObject(pixelCollider.GetPixelRoom(), pixelCollider); // Inspect Object PixelCollision pc = new PixelCollision(); pc.pixelCollider = pixelCollider; pc.direction = Direction.All; CharacterTask inspectTask = new CharacterTask(GameTask.TaskType.INSPECT, pc); characterTasks.Enqueue(inspectTask); return; } } } // Detected inspected rooms (for navigation) foreach (var hit in raycastHits) { GameObject obj = hit.collider.gameObject; if (obj == this) { continue; } PixelRoom pixelRoom = obj.GetComponent <PixelRoom>(); if (pixelRoom != null) { PixelCollider pixelCollider = gameObject.GetComponentInChildren <PixelCollider>(); if (pixelCollider == null) { continue; } if (pixelCollider.GetPixelRoom() != pixelRoom) { continue; } Debug.Log(pixelRoom.name); // Navigate Maze Room CharacterTask characterTask = new CharacterTask(GameTask.TaskType.WALKTO, mousePosition); characterTasks.Enqueue(characterTask); } } } }