public Interface(IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer viewer) : base(renderView, audioInterface) { RenderView = renderView; AudioInterface = audioInterface; Viewer = viewer; TextRenderer = new TextRenderer(renderView); displayed = true; config = UserConfig.Game.Options; mapCursorSprites[0] = new SpriteLocation { Sprite = 31 }; mapCursorSprites[1] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[2] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[3] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[4] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[5] = new SpriteLocation { Sprite = 32 }; mapCursorSprites[6] = new SpriteLocation { Sprite = 32 }; cursorSprite = renderView.SpriteFactory.Create(16, 16, 0, 0, false, false, 255); cursorSprite.Layer = renderView.GetLayer(Freeserf.Layer.Cursor); cursorSprite.Visible = true; SetSize(640, 480); // original size Viewport = null; PanelBar = new PanelBar(this); AddChild(PanelBar, 0, 0, false); Layout(); }
/// <summary> /// Moves the mouse in the correct direction and within the correct boundaries. /// </summary> /// <param name="screenWidth">The width of the screen</param> /// <param name="screenHeight">The height of the screen</param> public override void Move(int screenWidth, int screenHeight) { //The limits for each direction the mouse can move in int upperLimit = 40; int lowerLimit = screenHeight - 40; int leftLimit = 40; int rightLimit = screenWidth - 40; /*FOREACH stationary object, if the mouse intersects with it THEN * the movement of the mouse is limited based on whether the stationary * object is located*/ foreach (StationaryObject s in safetyZoneList_) { if (SpriteLocation.IntersectsWith(s.XLocation) || SpriteLocation.IntersectsWith(s.YLocation)) { if (s.Y == 0 || s.Y == screenHeight - 40) { upperLimit = 0; lowerLimit = screenHeight; leftLimit = (int)s.X; rightLimit = (int)s.X + BodyHeight + 8; if (Y < 2 || Y > (screenHeight - BodyHeight) - 2) { isSafe_ = true; } break; } else { upperLimit = (int)s.Y - 5; if (s is MouseDen) { lowerLimit = (int)s.Y + BodyHeight + 22; } else { lowerLimit = (int)s.Y + BodyHeight + 8; } leftLimit = 0; rightLimit = screenWidth; if (X < 2 || X > (screenWidth - BodyHeight) - 2) { isSafe_ = true; } break; } } else { isSafe_ = false; } } if (Direction == Direction.UP && Y > upperLimit) { Y -= Speed; } else if (Direction == Direction.DOWN && Y + BodyHeight < lowerLimit) { Y += Speed; } else if (Direction == Direction.LEFT && X > leftLimit) { X -= Speed; } else if (Direction == Direction.RIGHT && X + BodyHeight < rightLimit) { X += Speed; } }