Exemplo n.º 1
0
 public static Sprite ToSprite(this Tile tile, Point2i pos)
 {
     return(Sprite.Create(
                tile.isOccupied ? Texture2D.blackTexture : Texture2D.whiteTexture,
                Rect.MinMaxRect((float)pos.x - 0.5f, (float)pos.y - 0.5f, (float)pos.x + 0.5f, (float)pos.y + 0.5f),
                Vector2.zero));
 }
Exemplo n.º 2
0
        private static void DrawChar(uint CharPosX, uint CharPosY, char Chr)
        {
            Point2i CharPos = MapCharToImage(Chr);

            float TexCharSize = 1.0f / 16.0f;                     // There are 16x16 characters (each having 8x8 pixels) in the image

            if (CharPos != null)
            {
                float TexPosX = TexCharSize * (float)CharPos.X;
                float TexPosY = TexCharSize * (float)CharPos.Y;

                GL.BindTexture(GL.GL_TEXTURE_2D, _ConsoleChars.GLTextureNumber);
                GL.Begin(GL.GL_QUADS);
                GL.Color4f(0.0f, 0.0f, 0.0f, 0.0f);
                GL.TexCoord2f(TexPosX, TexPosY);
                GL.Vertex2f(CharPosX, CharPosY);
                GL.TexCoord2f(TexPosX + TexCharSize, TexPosY);
                GL.Vertex2f(CharPosX + 8, CharPosY);
                GL.TexCoord2f(TexPosX + TexCharSize, TexPosY + TexCharSize);
                GL.Vertex2f(CharPosX + 8, CharPosY + 8);
                GL.TexCoord2f(TexPosX, TexPosY + TexCharSize);
                GL.Vertex2f(CharPosX, CharPosY + 8);
                GL.End();
            }
        }
Exemplo n.º 3
0
        public void RecursiveCalcFinalPos(Group group, Size2i size)
        {
            // Compute the LayoutResult.FinalPos for all children

            group.group_layout_info.Sizer.CalcChildrenFinalPos(group, size);

            Point2i org = group.DriverGroup.Origin;

            foreach (Widget w in group.Children)
            {
                //position each child before laying out is child controls, since this might be needed
                //for the layout logic of the childs (for example splitter, needs to access size of splitter panels)
                if (w.DriverObject != null && group.DriverGroup != null)
                {
                    Rect2i bounds = w.LayoutResult.FinalPos;
                    if (org != Point2i.Origin)
                    {
                        //the normal case org is Origin, but forexample winforms frame need another origin
                        bounds = bounds.Translate(org.X, org.Y);
                    }

                    w.DriverControl.Bounds = bounds;
                }


                //and now compute final pos for each child
                Group subgrp = w as Group;
                if (subgrp != null)
                {
                    RecursiveCalcFinalPos(subgrp, subgrp.LayoutResult.FinalPos.Size);
                }
            }
        }
Exemplo n.º 4
0
        private static bool TileTypeInRange(Tile[,] tiles,
                                            Point2i mapSize,
                                            Tile.Type type,
                                            Point2i centerTile,
                                            int range)
        {
            Assert.IsTrue(range >= 0);

            int xBegin = Math.Max(0, centerTile.x - range);
            int xEnd   = Math.Min(centerTile.x + range + 1, mapSize.x);
            int yBegin = Math.Max(0, centerTile.y - range);
            int yEnd   = Math.Min(centerTile.y + range + 1, mapSize.y);

            for (int x = xBegin; x < xEnd; ++x)
            {
                for (int y = yBegin; y < yEnd; ++y)
                {
                    if (tiles[x, y].type == type)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 5
0
 public Rect2i(Point2i pos, Size2i size)
 {
     X      = pos.X;
     Y      = pos.Y;
     Width  = size.Width;
     Height = size.Height;
 }
Exemplo n.º 6
0
        internal void Regenerate(int level,
                                 HumanFriendlySeed rngSeed = null)
        {
            Level     = level;
            LevelSeed = rngSeed ?? new HumanFriendlySeed(rng.Next());
            rng       = new System.Random(LevelSeed.IntValue);

            ClearClones();

            Point2i mapSize = new Point2i(110, 110);

            layout = Generator.Generate(rng, mapSize.x, mapSize.y);

            Point2i spiderStartPos = GetSpiderStartPos();

            SpawnTiles();
            SpawnEnemies();
            SpawnDecorations(spiderStartPos);

            if (Player == null)
            {
                GameObject playerObj = (GameObject)GameObject.Instantiate(Resources.Load("SpiderBody"));
                Player = playerObj.GetComponent <PlayerControl>();
                GameStatistics.Reset();
            }

            Player.StopMovement();
            Player.transform.position = new Vector3(spiderStartPos.x, spiderStartPos.y);
        }
Exemplo n.º 7
0
 public MapDefinition(string name, Point2i startingPosition, Actor[] NPCs, Dictionary <Point2i, Item> items, string tiles)
 {
     Name = name;
     PlayerStartingPosition = startingPosition;
     this.NPCs = NPCs;
     Items     = items;
     Tiles     = tiles;
 }
Exemplo n.º 8
0
            public int DistanceTo(Point2i p)
            {
                int tx = this.x - p.x;
                int ty = this.y - p.y;

                return(MathUtils
                       .Sqrt(MathUtils.Mul(tx, tx) + MathUtils.Mul(ty, ty)));
            }
Exemplo n.º 9
0
 protected virtual void Reset()
 {
     layoutBlock = new CssBoxArea();
     layoutPos   = new Point2i();
     lineHeight  = 0;
     Previous    = null;
     Line        = new List <LineBox_Element>(1);
     Lines       = new List <LineBox>(1);
 }
Exemplo n.º 10
0
        private void SpawnDecorations(Point2i spiderStartPos)
        {
            GameObject decorationsObj = new GameObject("Decorations");

            decorationsObj.transform.SetParent(transform);

            SpawnFires(decorationsObj);
            SpawnCornerWebs(decorationsObj);
        }
Exemplo n.º 11
0
        private static Point2i MapCharNumberToImage(byte CharNumber)
        {
            Point2i Result = new Point2i();

            byte CharPosX = (byte)(CharNumber % 16);
            byte CharPosY = (byte)(CharNumber / 16);

            Result.MoveTo(CharPosX, CharPosY);

            return(Result);
        }
Exemplo n.º 12
0
        public static bool StealData(Actor?stealer, Point2i _, GameState gameState)
        {
            if (stealer != gameState.Player)
            {
                return(false);
            }

            gameState.Player.Inventory.Add(new Item(ItemDefinitions.StolenData));
            gameState.Messages.Push("You have stolen the data! Now get out!");
            return(true);
        }
Exemplo n.º 13
0
 public Actor(string name, Point2i position, GameTile presentation, Direction direction, ActorBrain brain, ActorRole role, List <string> dialogue)
 {
     Name         = name;
     Position     = position;
     Presentation = presentation;
     Direction    = direction;
     Brain        = brain;
     Role         = role;
     Inventory    = new List <Item>();
     Dialogue     = dialogue;
     Conditions   = new List <Condition>();
 }
Exemplo n.º 14
0
        /// <summary>
        /// Amplia el recubrimiento para que contenga al punto indicado.
        /// </summary>
        /// <param name="point">Punto.</param>
        public BoundingBox2i Union(Point2i point)
        {
            int rxMin, rxMax;

            BoundingBox2iUtils.Union(this.XMin, this.XMax, point.X, out rxMin, out rxMax);

            int ryMin, ryMax;

            BoundingBox2iUtils.Union(this.YMin, this.YMax, point.Y, out ryMin, out ryMax);

            return(new BoundingBox2i(rxMin, rxMax, ryMin, ryMax));
        }
Exemplo n.º 15
0
        private void Window_MouseButtonPressed(object?sender, MouseButtonEventArgs e)
        {
            if (e.X > mainDisplay.Offset.X && e.X < (mainDisplay.Offset.X + mainDisplay.SizePx.X)
                &&
                e.Y > mainDisplay.Offset.Y && e.Y < (mainDisplay.Offset.Y + mainDisplay.SizePx.Y))
            {
                Point2i pixelPositionInside = (e.X - mainDisplay.Offset.X, e.Y - mainDisplay.Offset.Y);
                Point2i gridPositionInside  = (pixelPositionInside.X / DisplayConsts.MainFontWidth, pixelPositionInside.Y / DisplayConsts.MainFontHeight);

                ((PlayerBrain)gameState.Player.Brain).StoredCommand = new LookCommand(gameState.Player, gridPositionInside);
            }
        }
Exemplo n.º 16
0
        private static Tile[,] GenerateTiles(int width,
                                             int height,
                                             IList <Chamber> chambers,
                                             IList <Corridor> corridors)
        {
            Tile[,] tiles = new Tile[width, height];
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    tiles[x, y] = new Tile(Tile.Type.Wall, true);
                }
            }

            const int CORRIDOR_WIDTH = 3;

            foreach (Corridor c in corridors)
            {
                for (int i = 0; i < c.intermediatePoints.Count - 1; ++i)
                {
                    Point2i src = c.intermediatePoints[i];
                    Point2i dst = c.intermediatePoints[i + 1];

                    Point2i pointer = src;
                    Point2i delta   = pointer.DeltaTowards(dst);
                    Assert.IsTrue((delta.x == 0) || (delta.y == 0));

                    while (pointer != c.intermediatePoints[i + 1])
                    {
                        PlaceCorridor(tiles, pointer, CORRIDOR_WIDTH);
                        pointer += delta;
                    }
                    PlaceCorridor(tiles, pointer, CORRIDOR_WIDTH);
                }
            }

            List <Point2i> chamberTiles = new List <Point2i>();

            foreach (Chamber c in chambers)
            {
                for (int y = c.bottom; y < c.top; ++y)
                {
                    for (int x = c.left; x < c.right; ++x)
                    {
                        tiles[x, y] = new Tile(Tile.Type.Chamber, false);
                        chamberTiles.Add(new Point2i(x, y));
                    }
                }
            }

            return(tiles);
        }
Exemplo n.º 17
0
			public int DistanceTo(Point2i p1, Point2i p2) {
				int tx = p2.x - p1.x;
				int ty = p2.y - p1.y;
				int u = MathUtils.Div(
						MathUtils.Mul(x - p1.x, tx) + MathUtils.Mul(y - p1.y, ty),
						MathUtils.Mul(tx, tx) + MathUtils.Mul(ty, ty));
				int ix = p1.x + MathUtils.Mul(u, tx);
				int iy = p1.y + MathUtils.Mul(u, ty);
				int dx = ix - x;
				int dy = iy - y;
				return MathUtils
						.Sqrt(MathUtils.Mul(dx, dx) + MathUtils.Mul(dy, dy));
			}
Exemplo n.º 18
0
 public static bool MoveToNewMap(Actor?mover, Point2i portalPosition, GameState gameState)
 {
     if (mover == gameState.Player && gameState.CurrentMapName != MapData.Office.Name)
     {
         gameState.ChangeMap(MapData.Office);
         return(true);
     }
     else if (mover == gameState.Player && gameState.CurrentMapName == MapData.Office.Name && gameState.Player.Inventory.Any(i => i.Template == ItemDefinitions.StolenData))
     {
         gameState.ChangeMap(MapData.Floor38);
         gameState.Messages.Push("You have stolen the data and escaped alive! You have won!");
         gameState.Messages.Push("Congratulations!");
     }
     return(false);
 }
Exemplo n.º 19
0
            public int DistanceTo(Point2i p1, Point2i p2)
            {
                int tx = p2.x - p1.x;
                int ty = p2.y - p1.y;
                int u  = MathUtils.Div(
                    MathUtils.Mul(x - p1.x, tx) + MathUtils.Mul(y - p1.y, ty),
                    MathUtils.Mul(tx, tx) + MathUtils.Mul(ty, ty));
                int ix = p1.x + MathUtils.Mul(u, tx);
                int iy = p1.y + MathUtils.Mul(u, ty);
                int dx = ix - x;
                int dy = iy - y;

                return(MathUtils
                       .Sqrt(MathUtils.Mul(dx, dx) + MathUtils.Mul(dy, dy)));
            }
Exemplo n.º 20
0
        private static void PlaceCorridor(Tile[,] tiles,
                                          Point2i center,
                                          int width)
        {
            int left  = width / 2;
            int right = width - left;

            for (int x = -left; x < right; ++x)
            {
                for (int y = -left; y < right; ++y)
                {
                    tiles[center.x + x, center.y + y] = new Tile(Tile.Type.Corridor, false);
                }
            }
        }
Exemplo n.º 21
0
 public static bool OpenSecureDoor(Actor?opener, Point2i doorPosition, GameState gameState)
 {
     if (opener is null)
     {
         return(false);
     }
     else if (opener.Inventory.Any(i => i.Template == ItemDefinitions.Keycard))
     {
         gameState.CurrentMap.ReplaceObject(doorPosition, TileDefinitions.OpenDoor);
     }
     else if (opener == gameState.Player)
     {
         gameState.Messages.Push("You can't open those doors without a keycard.");
     }
     return(true);
 }
Exemplo n.º 22
0
        public override Point2i GetClientOrigin()
        {
            if (frame is GroupBox)
            {
                int xb = SystemInformation.Border3DSize.Width;
                int yb = SystemInformation.Border3DSize.Height;
                int fh = frame.Font.Height;

                var res = new Point2i(xb, fh + yb);
                return(res);
            }
            else
            {
                return(Point2i.Empty); //borderless frame has origin @ 0,0
            }
        }
Exemplo n.º 23
0
        public override void OnTracking(Point2i dcs, Point2d wcs, Painter painter)
        {
            painter.Color = RGB.White;
            painter.DrawMark(dcs.X, dcs.Y, MarkType.Cross, 50);

            if (trackingCallback != null)
            {
                Point2d trackpt = trackingCallback(wcs, painter);
            }


            if (basePoint != null)
            {
                painter.DrawLineT(basePoint.X, basePoint.Y, wcs.X, wcs.Y);
            }
        }
        private void AddPoint3d(PixelGrid2D pg, Point3d pt)
        {
            pg.Plane.RemapToPlaneSpace(pt, out var p);
            var ix = (p.X - pg.BBox.X.Min - pg.PixelSize.X / 2) / pg.PixelSize.X;
            var iy = (p.Y - pg.BBox.Y.Min - pg.PixelSize.Y / 2) / pg.PixelSize.Y;


            var pti = pg.ClosestPoint(pt);

            pti = new Point2i(ix, iy);
            if (new Point2i(0, 0) > pti || pti >= pg.SizeUV)
            {
                return;
            }
            pg[pti] = true;
        }
Exemplo n.º 25
0
        private int CountAdjacentTilesOfType(Tile[,] tiles,
                                             Point2i pos,
                                             Tile.Type type)
        {
            int counter = 0;

            for (int dx = -1; dx <= 1; ++dx)
            {
                for (int dy = -1; dy <= 1; ++dy)
                {
                    if (tiles[pos.x + dx, pos.y + dy].type == type)
                    {
                        ++counter;
                    }
                }
            }
            return(counter);
        }
        public List <Point2i> GetPath(Point2i start, Point2i end)
        {
            var frontier = new Queue <Point2i>();

            frontier.Enqueue(start);
            var cameFrom = new Dictionary <Point2i, Point2i>();

            var current = start;

            while (frontier.Count > 0)
            {
                current = frontier.Dequeue();

                if (current == end)
                {
                    break;
                }

                foreach (var dir in Directions)
                {
                    var neighbor = current + dir;
                    if (PassabilityGrid[neighbor] && !cameFrom.ContainsKey(neighbor))
                    {
                        frontier.Enqueue(neighbor);
                        cameFrom[neighbor] = current;
                    }
                }
            }

            if (current != end)
            {
                return(new List <Point2i>());
            }

            var path = new List <Point2i>();

            while (current != start)
            {
                path.Add(current);
                current = cameFrom[current];
            }
            path.Reverse();
            return(path);
        }
Exemplo n.º 27
0
        public GameTile[] GetMaskedViewportWithViewcones(Point2i size, Point2i position, GameGrid <bool> visibilityGrid, GameGrid <bool> guardVisibilityGrid)
        {
            var maskedViewport = GetMaskedViewport(size, position, visibilityGrid);

            foreach (var kvp in Items)
            {
                if (visibilityGrid[kvp.Key] && !Actors.Any(a => a.Position == kvp.Key))
                {
                    maskedViewport[PositionToIndex(kvp.Key)] = kvp.Value.Presentation;
                }
            }

            for (var i = 0; i < maskedViewport.Length; i++)
            {
                if (guardVisibilityGrid[i] && visibilityGrid[i])
                {
                    maskedViewport[i] = new GameTile(maskedViewport[i].Glyph, maskedViewport[i].Foreground, Colors.GuardVisibility);
                }
            }

            return(maskedViewport);
        }
Exemplo n.º 28
0
        public static Corridor JoiningChambers(System.Random rng, Chamber src, Chamber dst)
        {
            IList <Point2i> intermediatePoints = new List <Point2i>();

            intermediatePoints.Add(src.center);

            Point2i delta = dst.center - src.center;

            if (rng.Next(2) == 0)
            {
                delta.x = 0;
            }
            else
            {
                delta.y = 0;
            }

            intermediatePoints.Add(src.center + delta);
            intermediatePoints.Add(dst.center);

            return(new Corridor(intermediatePoints));
        }
Exemplo n.º 29
0
        void OnDrawAreaMotion(object sender, MotionEventArgs e)
        {
            Drawing drw = CurrentDrawing;

            if (drw != null)
            {
                var size = drawarea.PhysicalSize;
                drawarea.Focused = true; //need focus for accepting wheel events

                var    newcursorpixel = new Point2i(e.X, size.Height - e.Y - 1);
                double dx             = newcursorpixel.X - cursorpixel.X;
                double dy             = newcursorpixel.Y - cursorpixel.Y;
                cursorpixel = newcursorpixel;

                if (e.Status.HasFlag(KeyStatus.MiddleButton))
                {
                    drw.ViewTransform = drw.ViewTransform * Transform2d.Translate(dx, dy);
                    drawarea.Redraw();
                    return;
                }


                RedrawOverlay();
            }
            else
            {
                trackingpos = null;
            }



            // w.Caption = viewtransform.ToString(); // pt.ToString() + "    " + e.Status.ToString();

            //Caption = e.X.ToString();
            SetCoordText();
        }
Exemplo n.º 30
0
			public void Set(Point2i p) {
				this.x = p.x;
				this.y = p.y;
			}
Exemplo n.º 31
0
 private void onMouseMove(object sender, MouseEventArgs e)
 {
     Point2i p = new Point2i(e.X, e.Y);
     hasMoved = new Option<Point2i>(p);
 }
Exemplo n.º 32
0
			public int DistanceTo(Point2i p) {
				int tx = this.x - p.x;
				int ty = this.y - p.y;
				return MathUtils
						.Sqrt(MathUtils.Mul(tx, tx) + MathUtils.Mul(ty, ty));
			}
Exemplo n.º 33
0
 // Finds if the given 2d point is inside the volume
 public override bool contains(ref Point2i pt)
 {
     return contains((float)pt.x, 0f, (float)pt.y);
 }
Exemplo n.º 34
0
 internal Rect2i(Point2i tl, Point2i br)
 {
     m_tl = tl;
     m_br = br;
 }
Exemplo n.º 35
0
 public static Rect2i ByCorners(Point2i tl, Point2i br)
 {
     return(new Rect2i(tl, br));
 }
Exemplo n.º 36
0
			public Point2i(Point2i p) {
				this.x = p.x;
				this.y = p.y;
			}