public WorldObject(Game g, SpriteBatch sb) : base(g) { game = g; spriteBatch = sb; player = new PlayerObject(game, sb, this); game.Components.Add(player); }
/// <summary> /// Gets the closest gate that intersects with the player. /// </summary> /// <param name="player"></param> /// <returns></returns> public Gate getClosestGate(PlayerObject player) { Gate closestGate = null; float gX, gX2, gY, gY2; // Gate Position X, Y - should be 10px less on Y due to perspective float pX, pX2, pY, pY2; // Player Position X,y pX = player.Position.X; pX2 = player.Position.X + player.Texture.Width; pY = player.Position.Y; pY2 = player.Position.Y + player.Texture.Height; foreach(Gate gate in gateQueue) { gX = gate.position.X; gX2 = gX + gate.myTexture.Width; gY = gate.position.Y +20; gY2 = gY + gate.myTexture.Height -35; if (!gate.isHit && ((gX <= pX) && (pX <= gX2) || (gX <= pX2) && (pX2 <= gX2))) // player and gate intersect on X { if ((gY <= pY) && (pY <= gY2) || (gY <= pY2) && (pY2 <= gY2)) // player and gate intersect on Y { closestGate = gate; break; } } else if (gX > pX2) { // This gate is still far, don't look for next ones in this cycle break; } } return closestGate; }
/// <summary> /// Checks if player touches the top of the world. /// </summary> /// <param name="playerObject"></param> /// <returns></returns> internal bool IsTouching(PlayerObject playerObject) { int value = (int)playerObject.Position.Y + playerObject.Texture.Height; value += lineQueue[(int)playerObject.Position.X + playerObject.Texture.Width / 2].Height; if (value == TouchPanel.DisplayHeight) { return true; } return false; }