internal static void DebugZoneTransition(Direction dir) { Point globalScreenCoord = ActiveZone.getGlobalScreenFromPosition(Samus.DrawPosition); Point newGlobalScreen = dir.Move(globalScreenCoord); if (ActiveZone.PositionsOwned.Contains(newGlobalScreen)) { Vector2 newPos = ActiveZone.getLocalScreenOffsetInPixelVector( ActiveZone.getLocalScreenFromGlobalScreen(newGlobalScreen)) + new Vector2(Zone.SCREEN_WIDTH_IN_PIXELS / 2, Zone.SCREEN_HEIGHT_IN_PIXELS / 2); Samus.getCollider().move(newPos - Samus.DrawPosition); } else { Zone departingZone = GameplayManager.ActiveZone; Zone arrivingZone = WorldManager.GetZone(newGlobalScreen); if (arrivingZone == null) return; arrivingZone.Initialize(); Vector2 newPos = arrivingZone.getLocalScreenOffsetInPixelVector( arrivingZone.getLocalScreenFromGlobalScreen(newGlobalScreen)) + new Vector2(Zone.SCREEN_WIDTH_IN_PIXELS / 2, Zone.SCREEN_HEIGHT_IN_PIXELS / 2); departingZone.remove(Samus); Samus.getCollider().move(-Samus.DrawPosition); // move Samus to 0,0 Samus.getCollider().move(newPos); // then to target position Samus.PreviousPosition = Samus.DrawPosition; arrivingZone.HasBeenVisited = true; arrivingZone.add(GameplayManager.Samus); GameplayManager.ActiveZone = arrivingZone; GlobalHelper.getInstance().Camera.Position = arrivingZone.getLocalScreenOffsetInPixelVector( arrivingZone.getLocalScreenCoordFromPosition(GameplayManager.Samus.DrawPosition)); } }
public ChozoStatue(Vector2 position, Item item, Direction facing) { if (facing != Direction.Left && facing != Direction.Right) { facing = Direction.Right; } m_position = position; m_item = item; m_facing = facing; m_statueAnimation = new AnimationController( "Animation/Data/MissionObjects", "Animation/Textures/MissionObjects", StatueAnimation); m_itemAnimation = new AnimationController( "Animation/Data/MissionObjects", "Animation/Textures/MissionObjects", ItemAnimation); Rectangle bounds; if (m_facing == Direction.Left) { bounds = new Rectangle( (int)m_position.X - 60, (int)m_position.Y - 120, 40, 40); } else { bounds = new Rectangle( (int)m_position.X + 20, (int)m_position.Y - 120, 40, 40); } m_collider = new Collider(this, bounds, ColliderType.Scenery); }
internal static Point Move(Point p, Direction d, int distance) { switch (d.EnumValue) { case DirectionEnum.Up: return new Point(p.X, p.Y - distance); case DirectionEnum.Down: return new Point(p.X, p.Y + distance); case DirectionEnum.Left: return new Point(p.X - distance, p.Y); case DirectionEnum.Right: return new Point(p.X + distance, p.Y); } throw new Exception("DirectionUtils:Move: Unknown direction for move request"); }
internal static Point Move(Point p, Direction d) { return Move(p, d, 1); }
internal bool IsOppositeOf(Direction d) { return d.Opposite.EnumValue == this.EnumValue; }
internal bool IsCWOf(Direction d) { return d.RotationCW.EnumValue == this.EnumValue; }
internal static Point SampleOctantPoint(Direction primary, Direction secondary) { Vector2 sample = SampleOctant(primary, secondary); return new Point((int)sample.X, (int)sample.Y); }
internal static Vector2 SampleOctant(Direction primary, Direction secondary) { int leftMax = Math.Min(Zone.SCREEN_WIDTH_IN_PIXELS / 2, Zone.SCREEN_HEIGHT_IN_PIXELS / 2); int rightMin = Math.Max(Zone.SCREEN_WIDTH_IN_PIXELS / 2, Zone.SCREEN_WIDTH_IN_PIXELS - Zone.SCREEN_HEIGHT_IN_PIXELS / 2); int upMax = Math.Min(Zone.SCREEN_WIDTH_IN_PIXELS / 2, Zone.SCREEN_HEIGHT_IN_PIXELS / 2); int downMin = Math.Max(Zone.SCREEN_HEIGHT_IN_PIXELS / 2, Zone.SCREEN_HEIGHT_IN_PIXELS - Zone.SCREEN_WIDTH_IN_PIXELS / 2); double primaryCoord = 0; double secondaryCoord = 0; double primaryMin; double primaryMax; switch(primary.EnumValue) { case DirectionEnum.Left: primaryMin = 0; primaryMax = leftMax; primaryCoord = RandomManager.get().NextDouble() * (primaryMax - primaryMin) + primaryMin; if (secondary == Direction.Up) { secondaryCoord = RandomManager.get().NextDouble() * (leftMax - primaryCoord) + primaryCoord; } else { secondaryCoord = RandomManager.get().NextDouble() * (leftMax - primaryCoord) + downMin; } break; case DirectionEnum.Up: primaryMin = 0; primaryMax = upMax; primaryCoord = RandomManager.get().NextDouble() * (primaryMax - primaryMin) + primaryMin; if (secondary == Direction.Left) { secondaryCoord = RandomManager.get().NextDouble() * (upMax - primaryCoord) + primaryCoord; } else { secondaryCoord = RandomManager.get().NextDouble() * (upMax - primaryCoord) + rightMin; } break; case DirectionEnum.Right: primaryMin = rightMin; primaryMax = Zone.SCREEN_WIDTH_IN_PIXELS; primaryCoord = RandomManager.get().NextDouble() * (primaryMax - primaryMin) + primaryMin; if (secondary == Direction.Up) { secondaryCoord = RandomManager.get().NextDouble() * (upMax - (Zone.SCREEN_WIDTH_IN_PIXELS - primaryCoord)) + (Zone.SCREEN_WIDTH_IN_PIXELS - primaryCoord); } else { secondaryCoord = RandomManager.get().NextDouble() * (Zone.SCREEN_HEIGHT_IN_PIXELS - downMin - (Zone.SCREEN_WIDTH_IN_PIXELS - primaryCoord)) + downMin; } break; case DirectionEnum.Down: primaryMin = downMin; primaryMax = Zone.SCREEN_HEIGHT_IN_PIXELS; primaryCoord = RandomManager.get().NextDouble() * (primaryMax - primaryMin) + primaryMin; if (secondary == Direction.Left) { secondaryCoord = RandomManager.get().NextDouble() * (leftMax - (Zone.SCREEN_HEIGHT_IN_PIXELS - primaryCoord)) + (Zone.SCREEN_HEIGHT_IN_PIXELS - primaryCoord); } else { secondaryCoord = RandomManager.get().NextDouble() * (Zone.SCREEN_WIDTH_IN_PIXELS - rightMin - (Zone.SCREEN_HEIGHT_IN_PIXELS - primaryCoord)) + rightMin; } break; } if (primary.IsVertical) { double temp = primaryCoord; primaryCoord = secondaryCoord; secondaryCoord = temp; } return new Vector2((float)primaryCoord, (float)secondaryCoord); }
internal static void GetOctant(Vector2 positionInScreen, out Direction primary, out Direction secondary) { Direction topDown; Direction leftRight; if (positionInScreen.X <= Zone.SCREEN_WIDTH_IN_PIXELS / 2) { leftRight = Direction.Left; } else { leftRight = Direction.Right; } if (positionInScreen.Y <= Zone.SCREEN_HEIGHT_IN_PIXELS / 2) { topDown = Direction.Up; } else { topDown = Direction.Down; } if (leftRight == Direction.Left && topDown == Direction.Up && positionInScreen.X >= positionInScreen.Y || leftRight == Direction.Left && topDown == Direction.Down && positionInScreen.X >= Zone.SCREEN_HEIGHT_IN_PIXELS - positionInScreen.Y || leftRight == Direction.Right && topDown == Direction.Up && Zone.SCREEN_WIDTH_IN_PIXELS - positionInScreen.X >= positionInScreen.Y || leftRight == Direction.Right && topDown == Direction.Down && Zone.SCREEN_WIDTH_IN_PIXELS - positionInScreen.X >= Zone.SCREEN_HEIGHT_IN_PIXELS - positionInScreen.Y) { primary = topDown; secondary = leftRight; } else { primary = leftRight; secondary = topDown; } }
public DoorController(Direction side, Zone zone, Point zoneScreenCoord) { AnimationController = new AnimationController(@"Animation/Data/Doors", @"Sprites/Doors"); AnimationController.DrawBottomCenter = false; AnimationController.Scale = Scale; Color = "Metal"; State = DoorState.Closed; Side = side; bool zoneWidthOdd = (Zone.SCREEN_WIDTH_IN_TILES % 2) == 1; bool zoneHeightOdd = (Zone.SCREEN_HEIGHT_IN_TILES % 2) == 1; // Initialize bounding box Point pos = Point.Zero; Rectangle bounds = Rectangle.Empty; if (side == Direction.Up) { pos = zone.getPixelPositionFromScreenPosition(zoneScreenCoord, new Point(Zone.SCREEN_WIDTH_IN_PIXELS / 2 + (zoneWidthOdd ? -Zone.TILE_WIDTH / 2 : 0), 0)); bounds = new Rectangle( pos.X - LongEdge / 2, pos.Y - ShortEdge / 2, LongEdge, ShortEdge); } if (side == Direction.Down) { pos = zone.getPixelPositionFromScreenPosition(zoneScreenCoord, new Point(Zone.SCREEN_WIDTH_IN_PIXELS / 2 + (zoneWidthOdd ? - Zone.TILE_WIDTH / 2 : 0), Zone.SCREEN_HEIGHT_IN_PIXELS)); bounds = new Rectangle( pos.X - LongEdge / 2, pos.Y - ShortEdge / 2, LongEdge, ShortEdge); } if (side == Direction.Left) { pos = zone.getPixelPositionFromScreenPosition(zoneScreenCoord, new Point(0, Zone.SCREEN_HEIGHT_IN_PIXELS / 2 + (zoneHeightOdd ? -Zone.TILE_HEIGHT / 2 : 0))); bounds = new Rectangle( pos.X - ShortEdge / 2, pos.Y - LongEdge / 2, ShortEdge, LongEdge); } if (side == Direction.Right) { pos = zone.getPixelPositionFromScreenPosition(zoneScreenCoord, new Point(Zone.SCREEN_WIDTH_IN_PIXELS, Zone.SCREEN_HEIGHT_IN_PIXELS / 2 + (zoneHeightOdd ? -Zone.TILE_HEIGHT / 2 : 0))); bounds = new Rectangle( pos.X - ShortEdge / 2, pos.Y - LongEdge / 2, ShortEdge, LongEdge); } this.m_position = new Vector2(pos.X, pos.Y); this.m_collider = new Collider(this, bounds, ColliderType.Scenery); this.m_owningZone = zone; this.m_zoneScreenCoord = zoneScreenCoord; }