GameCoords.cs :  » Game » SokoSolve-Sokoban » SokoSolve » Core » UI » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » Core » UI » GameCoords.cs
using System;
using System.Collections.Generic;
using System.Text;
using SokoSolve.Common.Math;
using SokoSolve.Core.Game;

namespace SokoSolve.Core.UI{
    /// <summary>
    /// Encapsulate the 2D game coordinate system
    /// </summary>
    public class GameCoords
    {
        /// <summary>
        /// Strong Construction
        /// </summary>
        /// <param name="aGameUI"></param>
        public GameCoords(GameUI aGameUI)
        {
            GameUI = aGameUI;
            GlobalOffset = new VectorInt(10, 30);
      GlobalTileSize = new SizeInt(16, 16);
            windowRegion =  new RectangleInt(new VectorInt(0, 0), new SizeInt(400, 300));
        }

        /// <summary>
        /// The gobal offset/distance from 0,0 to draw the topleft of the puzzle
        /// </summary>
        public VectorInt GlobalOffset
        {
            get { return globalOffset; }
            set { globalOffset = value; }
        }

        /// <summary>
        /// Pixel size of each tile/cell
        /// </summary>
        public SizeInt GlobalTileSize
        {
            get { return globalTileSize; }
            set { globalTileSize = value; }
        }

      

        /// <summary>
        /// Get the absolute pixel coords from a puzzle position
        /// </summary>
        /// <param name="PuzzlePosition"></param>
        /// <returns></returns>
    public VectorInt PositionAbsoluteFromPuzzle(VectorInt PuzzlePosition)
        {
      return new VectorInt(PuzzlePosition.X * GlobalTileSize.X + GlobalOffset.X, PuzzlePosition.Y * GlobalTileSize.Y + GlobalOffset.Y);
        }

        /// <summary>
        /// Get the puzzle position from the absolute pixel position (taking into accout the GlobalOffset)
        /// </summary>
        /// <param name="AbsolutePosition"></param>
        /// <returns></returns>
    public VectorInt PuzzleFromPositionAbs(VectorInt AbsolutePosition)
        {
      return new VectorInt((AbsolutePosition.X - GlobalOffset.X) / GlobalTileSize.X, (AbsolutePosition.Y - GlobalOffset.Y) / GlobalTileSize.Y);
        }

        /// <summary>
        /// Get the puzzle position from the pixel position (NOT taking into accout the GlobalOffset)
        /// </summary>
        /// <param name="LogicalPosition"></param>
        /// <returns></returns>
        public VectorInt PuzzleFromPositionLogical(VectorInt LogicalPosition)
        {
            return new VectorInt((LogicalPosition.X) / GlobalTileSize.X, (LogicalPosition.Y ) / GlobalTileSize.Y);
        }

        /// <summary>
        /// Define a rectangle for the puzzle region
        /// </summary>
        public RectangleInt PuzzleRegion
        {
            get
            {
        return new RectangleInt(GlobalOffset,
                   new VectorInt(GlobalTileSize.X * GameUI.Current.Size.X, GlobalTileSize.Y* GameUI.Current.Size.Y));
            }
        }

        /// <summary>
        /// Define a rectangle for the puzzle region
        /// </summary>
        public RectangleInt WindowRegion
        {
            get { return windowRegion;  }
            set
            {
                windowRegion = value;
                if (windowRegion.Size.ToVectorInt < PuzzleRegion.Size.ToVectorInt)
                {
                    GlobalOffset = new VectorInt((windowRegion.Width - PuzzleRegion.Width) / 2, (windowRegion.Height - PuzzleRegion.Height) / 2);
                }
            }
        }

        /// <summary>
        /// Region to display the status information
        /// </summary>
        public VectorInt PositionStatus
        {
            get { return WindowRegion.TopRight.Add(-80, 50); }
        }

        /// <summary>
        /// Region to display the status information
        /// </summary>
        public RectangleInt PositionMovementCommands
        {
            get { return new RectangleInt(WindowRegion.BottomRight.Subtract(movementCommands).Subtract(20, 20), movementCommands); }
        }

        /// <summary>
        /// Region to display the status information
        /// </summary>
        public RectangleInt PositionGeneralCommands
        {
            get { return new RectangleInt(WindowRegion.TopRight.Subtract(generalCommands).Subtract(20, 0), generalCommands); }
        }

        /// <summary>
        /// Region to display the status information
        /// </summary>
        public RectangleInt PositionWayPoints
        {
            get { return new RectangleInt(WindowRegion.TopLeft.Add(10, 10), new SizeInt(30, 300)); }
        }

        private GameUI GameUI;
        private RectangleInt windowRegion;
        private SizeInt movementCommands = new SizeInt(75, 75);
        private SizeInt generalCommands = new SizeInt(75, -40);
        /// <summary>
        /// The gobal offset/distance from 0,0 to draw the topleft of the puzzle
        /// </summary>
        VectorInt globalOffset;

        /// <summary>
        /// Pixel size of each tile/cell
        /// </summary>
        SizeInt globalTileSize;

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.