示例#1
0
        }                         //This aint no game yet!

        public void InitializeGameState()
        {
            backgroundImage =
                new Entity(new StationaryShape(new Vec2F(0, 0), new Vec2F(1, 1)),
                           new Image("Assets\\Images\\TitleImage.png"));

            textColour         = new Vec3I(255, 255, 255);
            textColourSelected = new Vec3I(255, 0, 0);

            menuButtons = new Text[] {
                new Text(
                    "Start",               //name
                    new Vec2F(0.5f, 0.5f), //pos
                    new Vec2F(0.2f, 0.2f)  //ext
                    ),
                new Text(
                    "Quit",
                    new Vec2F(0.5f, 0.4f),
                    new Vec2F(0.2f, 0.2f)
                    )
            };
            menuButtons[0].SetColor(textColour);
            menuButtons[1].SetColor(textColourSelected);
            activeMenuButton = 0;
            maxMenuButtons   = menuButtons.Length - 1;
        }
示例#2
0
 void ClampCellIndex(ref Vec3I cellIndex)
 {
     if (cellIndex.X < 0)
     {
         cellIndex.X = 0;
     }
     if (cellIndex.Y < 0)
     {
         cellIndex.Y = 0;
     }
     if (cellIndex.Z < 0)
     {
         cellIndex.Z = 0;
     }
     if (cellIndex.X >= cellCount.X)
     {
         cellIndex.X = cellCount.X - 1;
     }
     if (cellIndex.Y >= cellCount.Y)
     {
         cellIndex.Y = cellCount.Y - 1;
     }
     if (cellIndex.Z >= cellCount.Z)
     {
         cellIndex.Z = cellCount.Z - 1;
     }
 }
示例#3
0
 /// <summary>
 /// Change text color
 /// </summary>
 /// <param name="vec">Vec3I containing the RGB color values.</param>
 /// <exception cref="ArgumentOutOfRangeException">Color values must be
 /// between 0 and 255.</exception>
 public void SetColor(Vec3I vec)
 {
     if (vec.X < 0 || vec.X > 255 ||
         vec.Y < 0 || vec.Y > 255 ||
         vec.Z < 0 || vec.Z > 255)
     {
         throw new ArgumentOutOfRangeException($"RGB Color values must be between 0 and 255: {vec}");
     }
     color = Color.FromArgb(vec.X, vec.Y, vec.Z);
     CreateBitmapTexture();
 }
示例#4
0
        public void InitializeGameState()
        {
            activeMenuButton = 0;
            backGroundImage  = new Entity(new StationaryShape(new Vec2F(0, 0), new Vec2F(1, 1)), new Image(Path.Combine("Assets", "Images", "SpaceBackground.png")));
            menuButtons      = new Text[maxMenuButtons];
            continueButton   = new Text("Continue", new Vec2F(0.5f, 0.5f), new Vec2F(0.2f, 0.2f));
            mainMenu         = new Text("Main Menu", new Vec2F(0.5f, 0.3f), new Vec2F(0.2f, 0.2f));
            menuButtons[0]   = continueButton;
            menuButtons[1]   = mainMenu;

            activeColor   = new Vec3I(255, 255, 255);
            inactiveColor = new Vec3I(190, 190, 190);
            HandleButtons();
        }
示例#5
0
        public void InitializeGameState()
        {
            backGroundImage = new Entity(
                new StationaryShape(new Vec2F(0, 0), new Vec2F(1, 1)),
                new Image(Path.Combine("Assets", "Images", "TitleImage.png")));
            menuButtons      = new Text[maxMenuButtons];
            activeMenuButton = 0;
            newGame          = new Text("New Game",
                                        new Vec2F(0.25f, 0.4f),
                                        new Vec2F(0.5f, 0.5f));
            quit = new Text(
                "Quit", new Vec2F(0.25f, 0.2f),
                new Vec2F(0.5f, 0.5f));
            menuButtons[0] = newGame;
            menuButtons[1] = quit;

            activeColor   = new Vec3I(255, 255, 255);
            inactiveColor = new Vec3I(100, 100, 100);

            HandleButtons();
        }
示例#6
0
        bool CalculateFrozenState(MapObject obj)
        {
            if (!IsReallyEnabled())
            {
                return(false);
            }
            if (obj._FreezeObjectsManagerNeverFreeze)
            {
                return(false);
            }

            //check by camera distance
            {
                Camera camera = RendererWorld.Instance.DefaultCamera;

                if (unfreezeByCameraZDistance != 0)
                {
                    float length2 = (camera.Position.ToVec2() - obj.Position.ToVec2()).Length();
                    if (length2 < unfreezeByCameraDistance)
                    {
                        return(false);
                    }
                    float lengthZ = Math.Abs(camera.Position.Z - obj.Position.Z);
                    if (lengthZ < unfreezeByCameraZDistance)
                    {
                        return(false);
                    }
                }
                else
                {
                    float length = (camera.Position - obj.Position).Length();
                    if (length < unfreezeByCameraDistance)
                    {
                        return(false);
                    }
                }
            }

            //check by areas
            if (grid != null)
            {
                Vec3  indexF = (obj.Position - gridStartPosition) * gridCellSizeInv;
                Vec3I index  = indexF.ToVec3I();
                if (index.X >= 0 && index.Y >= 0 && index.Z >= 0 && index.X < cellCount.X && index.Y < cellCount.Y && index.Z < cellCount.Z)
                {
                    GridItem item = grid[index.X, index.Y, index.Z];

                    for (int n = 0; n < item.count; n++)
                    {
                        FreezeObjectsArea area = gridAreas[n + item.startIndex];

                        bool unfreezing;
                        area._UpdateLastCheckState(out unfreezing);
                        if (unfreezing)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
示例#7
0
 public bool AllLower(Vec3I compareTo)
 {
     return(AllLower(compareTo.x, compareTo.y, compareTo.z));
 }
示例#8
0
 public static int Dot(Vec3I v1, Vec3I v2)
 {
     return(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z);
 }
示例#9
0
        Bounds GetCellBounds(Vec3I cellIndex)
        {
            Vec3 min = gridStartPosition + gridCellSize * cellIndex.ToVec3();

            return(new Bounds(min, min + gridCellSize));
        }
示例#10
0
 public static int Manhattan(Vec3I a, Vec3I b)
 {
     return(Mathf.Abs(a.x - b.x) + Mathf.Abs(a.y - b.y) + Mathf.Abs(a.z - b.z));
 }
示例#11
0
 public static int Min(Vec3I a, Vec3I b)
 {
     return(Mathf.Min(Mathf.Min(Mathf.Abs(a.x - b.x), Mathf.Abs(a.y - b.y)), Mathf.Abs(a.z - b.z)));
 }
示例#12
0
 public bool AllHigherOrEqual(Vec3I compareTo)
 {
     return(AllHigherOrEqual(compareTo.x, compareTo.y, compareTo.z));
 }
示例#13
0
 public static Vec3I SelectMax(Vec3I a, Vec3I b)
 {
     return(new Vec3I(Mathf.Max(a.x, b.x), Mathf.Max(a.y, b.y), Mathf.Max(a.z, b.z)));
 }
 public static Vec3I CreateMin(Vec3I a, Vec3I b)
 {
     return(new Vec3I(Mathf.Min(a.x, b.x), Mathf.Min(a.y, b.y), Mathf.Min(a.z, b.z)));
 }
示例#15
0
 public static float SqrDistance(Vec3I a, Vec3I b)
 {
     return((a - b).sqrMagnitude);
 }
示例#16
0
 public bool AnyLowerOrEqual(Vec3I compareTo)
 {
     return(AnyLowerOrEqual(compareTo.x, compareTo.y, compareTo.z));
 }
示例#17
0
 public static float Distance(Vec3I a, Vec3I b)
 {
     return((a - b).magnitude);
 }
示例#18
0
 public bool AnyHigher(Vec3I compareTo)
 {
     return(AnyHigher(compareTo.x, compareTo.y, compareTo.z));
 }
示例#19
0
		void GetShapeSubmergedSpheres( ref Mat3 bodyRotation, Shape shape,
			List<SubmergedCheckItem> outSubmergedItems )
		{
			Body body = shape.Body;

			Vec3 shapePosition = body.Position + bodyRotation * shape.Position;

			switch( shape.ShapeType )
			{
			case Shape.Type.Box:
				{
					BoxShape boxShape = (BoxShape)shape;

					Quat shapeRotation = shape.Body.Rotation;
					if( !shape.IsIdentityTransform )
						shapeRotation *= shape.Rotation;

					Vec3 halfD = boxShape.Dimensions * .5f;

					float r = Math.Min( Math.Min( halfD.X, halfD.Y ), halfD.Z );

					Vec3I stepsCount = new Vec3I( 1, 1, 1 );
					if( halfD.X > r * .3f )
						stepsCount.X = 2;
					if( halfD.Y > r * .3f )
						stepsCount.Y = 2;
					if( halfD.Z > r * .3f )
						stepsCount.Z = 2;

					for( int z = 0; z < stepsCount.Z; z++ )
					{
						for( int y = 0; y < stepsCount.Y; y++ )
						{
							for( int x = 0; x < stepsCount.X; x++ )
							{
								Vec3 localPos = Vec3.Zero;

								if( stepsCount.X == 2 )
									localPos.X = ( x == 0 ) ? ( -halfD.X + r ) : ( halfD.X - r );
								if( stepsCount.Y == 2 )
									localPos.Y = ( y == 0 ) ? ( -halfD.Y + r ) : ( halfD.Y - r );
								if( stepsCount.X == 2 )
									localPos.Z = ( z == 0 ) ? ( -halfD.Z + r ) : ( halfD.Z - r );

								Vec3 pos = shapePosition + shapeRotation * localPos;

								outSubmergedItems.Add( GetSphereSubmergedCoef( new Sphere( pos, r ) ) );
							}
						}
					}
				}
				break;

			case Shape.Type.Capsule:
				{
					CapsuleShape capsuleShape = (CapsuleShape)shape;
					float r = capsuleShape.Radius;
					float l = capsuleShape.Length;

					Quat shapeRotation = shape.Body.Rotation;
					if( !shape.IsIdentityTransform )
						shapeRotation *= shape.Rotation;

					Vec3 pos;
					pos = shapePosition + shapeRotation * new Vec3( 0, 0, -l * .5f );
					outSubmergedItems.Add( GetSphereSubmergedCoef( new Sphere( pos, r ) ) );
					pos = shapePosition + shapeRotation * new Vec3( 0, 0, l * .5f );
					outSubmergedItems.Add( GetSphereSubmergedCoef( new Sphere( pos, r ) ) );
				}
				break;

			case Shape.Type.Sphere:
				{
					SphereShape sphereShape = (SphereShape)shape;
					float r = sphereShape.Radius;
					outSubmergedItems.Add( GetSphereSubmergedCoef( new Sphere( shapePosition, r ) ) );
				}
				break;

			case Shape.Type.Mesh:
				{
					MeshShape meshShape = (MeshShape)shape;
					Bounds b;
					if( meshShape.GetDataBounds( out b ) )
					{
						float r = b.GetRadius();
						outSubmergedItems.Add( GetSphereSubmergedCoef( new Sphere( shapePosition, r ) ) );
					}
				}
				break;
			}
		}
示例#20
0
        void GenerateGrid()
        {
            ClearGrid();

            if (FreezeObjectsArea.Instances.Count != 0)
            {
                //init grid
                {
                    Bounds bounds = Bounds.Cleared;
                    foreach (FreezeObjectsArea area in FreezeObjectsArea.Instances)
                    {
                        bounds.Add(area.MapBounds);
                    }
                    if (bounds.GetSize().X < 1)
                    {
                        bounds.Expand(new Vec3(1, 0, 0));
                    }
                    if (bounds.GetSize().Y < 1)
                    {
                        bounds.Expand(new Vec3(0, 1, 0));
                    }
                    if (bounds.GetSize().Z < 1)
                    {
                        bounds.Expand(new Vec3(0, 0, 1));
                    }

                    gridStartPosition = bounds.Minimum;

                    gridCellSize = bounds.GetSize() / cellCount.ToVec3();
                    for (int n = 0; n < 3; n++)
                    {
                        if (gridCellSize[n] < cellMinSize[n])
                        {
                            gridCellSize[n] = cellMinSize[n];
                        }
                    }
                    gridCellSizeInv = 1.0f / gridCellSize;
                    grid            = new GridItem[cellCount.X, cellCount.Y, cellCount.Z];
                }

                //fill areas

                GridAreasIndexByListOfAreasKey        comparer = new GridAreasIndexByListOfAreasKey();
                Dictionary <FreezeObjectsArea[], int> gridAreasIndexByListOfAreas = new Dictionary <FreezeObjectsArea[], int>(comparer);
                List <FreezeObjectsArea> gridAreasList = new List <FreezeObjectsArea>();

                foreach (FreezeObjectsArea area in FreezeObjectsArea.Instances)
                {
                    Box    box    = area.GetBox();
                    Bounds bounds = box.ToBounds();

                    Vec3I startIndex = GetCellIndexWithoutClamp(bounds.Minimum);
                    Vec3I endIndex   = GetCellIndexWithoutClamp(bounds.Maximum);
                    ClampCellIndex(ref startIndex);
                    ClampCellIndex(ref endIndex);

                    for (int z = startIndex.Z; z <= endIndex.Z; z++)
                    {
                        for (int y = startIndex.Y; y <= endIndex.Y; y++)
                        {
                            for (int x = startIndex.X; x <= endIndex.X; x++)
                            {
                                Vec3I  cellIndex  = new Vec3I(x, y, z);
                                Bounds cellBounds = GetCellBounds(cellIndex);
                                if (box.IsIntersectsBounds(cellBounds))
                                {
                                    GridItem item = grid[cellIndex.X, cellIndex.Y, cellIndex.Z];

                                    FreezeObjectsArea[] array = new FreezeObjectsArea[item.count + 1];
                                    for (int n = 0; n < item.count; n++)
                                    {
                                        array[n] = gridAreas[item.startIndex + n];
                                    }
                                    array[array.Length - 1] = area;

                                    int gridAreasIndex;
                                    if (!gridAreasIndexByListOfAreas.TryGetValue(array, out gridAreasIndex))
                                    {
                                        gridAreasIndex = gridAreasList.Count;

                                        gridAreasIndexByListOfAreas.Add(array, gridAreasIndex);
                                        gridAreasList.AddRange(array);
                                    }

                                    item.startIndex = gridAreasIndex;
                                    item.count      = array.Length;
                                    grid[cellIndex.X, cellIndex.Y, cellIndex.Z] = item;
                                }
                            }
                        }
                    }

                    gridAreas = gridAreasList.ToArray();
                }
            }
        }