示例#1
0
 public override void SpawnTileId(int TileId, twin TilePos)
 {
     switch (TileId)
     {
     case 50: banks["player"].Spawn(GetEntLot("player"), tilemap.layoutGrid.GetCellCenterWorld(TilePos)); break;
     }
 }
示例#2
0
        //// IBodCollidable
        public Bod HitRect(Vector2 pos, Vector2 size)
        {
            if (!this.active)
            {
                return(null);
            }

            Bod  hit;
            twin min = PointToCellPos(pos);
            twin max = PointToCellPos(pos + size);

            for (int x = min.x; x <= max.x; x++)
            {
                for (int y = min.y; y <= max.y; y++)
                {
                    if (!CellPosInBounds(new twin(x, y)))
                    {
                        continue;
                    }
                    hit = cells[x, y].HitRect(pos, size);
                    if (hit != null)
                    {
                        return(hit);
                    }
                }
            }

            return(null);
        }
示例#3
0
        public void ResetGen()
        {
            List <twin> cells = new List <twin>();

            extrabounds.DoEach(cell =>
            {
                xxi.Sett(cell, 1);
            });
            bounds.DoEach(cell => {
                cells.Add(cell);
            });
            Util.shufl(ref cells);

            this.open   = new List <twin>();
            this.closed = new List <twin>();

            open.Add(this.firstCell = new twin(
                         Random.Range(bounds.min.x, bounds.max.x + 1),
                         Random.Range(bounds.min.y, bounds.max.y + 1)
                         ));

            for (int i = 0; i < 5; i++)
            {
                NextGenStep();
            }
        }
示例#4
0
        public void PlaceTiles(TiledLevelData levelData, maze.ITileTTs tilemap, System.Action <int, twin> spawnFunction)
        {
            tilemap.ClearAllTiles();

            twin tile_pos = new twin(0, levelData.height - 1);

            foreach (var tile_id in levelData.tile_ids)
            {
                if (spawnTileSet.Contains(tile_id))
                {
                    spawnFunction(tile_id, tile_pos);
                    tilemap.Sett(tile_pos, 0);
                }
                else if (tile_id >= 0)
                {
                    tilemap.Sett(tile_pos, tile_id);
                }

                tile_pos.x++;
                if (tile_pos.x >= levelData.width)
                {
                    tile_pos.x = 0;
                    tile_pos.y--;
                }
            }
        }
示例#5
0
        public AStarPath GetPathToNearestTowerFrom(twin start, bool get_furthest_instead = false, bool include_planned_towers = false)
        {
            var towerpaths = new HashSet <AStarPath>();

            foreach (Transform robotTransform in xxi.GetEntLot("robot towers").transform)
            {
                var tower = robotTransform.GetComponent <BaRobotTower>();
                towerpaths.Add(new AStarPath(robotPather, start, tower.my_cell_pos));
            }

            if (include_planned_towers)
            {
                foreach (var plannedTowerPos in plannedTowers)
                {
                    towerpaths.Add(new AStarPath(robotPather, start, plannedTowerPos));
                }
            }

            if (towerpaths.Count == 0)
            {
                return(null);
            }

            return(Util.findbest(towerpaths, path =>
            {
                if (path.cost <= 0 || path.cost == int.MaxValue)
                {
                    return int.MinValue;                                              // never return impossible paths
                }
                return get_furthest_instead? path.cost: -path.cost;
            }));
        }
示例#6
0
        override public void FrequentStep()
        {
            base.FrequentStep();

            twin cursorPos = UpdateCursorPos();

            if (!xxi.Input_Key_ShowPalette())
            {
                xxi.SetState(xxi.state_edit);
            }
            else
            {
                KeyCode k = xxi.keys.GetCurrentKey();
                if (paletteGrid.CellPosInBounds(cursorPos))
                {
                    AuthorCell cell           = (AuthorCell)paletteGrid.GetCell(cursorPos);
                    bool       cellSelectable = (cell != null && cell.type != (byte)AuthorCell_SuperType.Unused);
                    bool       inputIsNumber  = (k >= KeyCode.Alpha0 && k <= KeyCode.Alpha9);
                    bool       inputIsAlpha   = (k >= KeyCode.A && k <= KeyCode.Z);

                    if (cellSelectable && (inputIsNumber || inputIsAlpha))
                    {
                        xxi.Input_SetKeyCellValue(k, cell.value);
                    }
                }
            }
        }
示例#7
0
    private void FixedUpdate()
    {
        toNextSpawn--;
        if (toNextSpawn < 0)
        {
            toNextSpawn = 120;
            queuedSpawns++;
        }

        if (queuedSpawns > 0)
        {
            var spawnTileCount = GetEntLot("enters").transform.childCount;
            if (spawnTileCount > 0)
            {
                var spawnTile = GetEntLot("enters").transform.GetChild(Random.Range(0, spawnTileCount));
                var cell      = new twin(master.grid.WorldToCell(spawnTile.transform.position));

                if (Random.value < .5f)
                {
                    banks["pillbug"].Spawn <BroMazer>(CreaturesLot).Setup(master, cell);
                }
                else
                {
                    banks["pregghost"].Spawn <BroMazer>(CreaturesLot).Setup(master, cell);
                }

                queuedSpawns--;
            }
        }
    }
示例#8
0
    private void Start()
    {
        GetSolidTileIds();

        Instance = this;
        InitializeManualTT();
        new twinrect(twin.zero, new twin(32, 32) - twin.one).DoEach(cell =>
        {
            Sett(cell, 2);     // initialize whole screen to solid
        });

        twin center = new twin(Random.Range(5, 32 - 5), Random.Range(5, 32 - 5));

        new twinrect(center - twin.one, center + twin.one).DoEach(cell =>
        {
            Dig(cell, dirty: false);
        });

        Sett(center, 1);

        player = banks["tinyplayer"].Spawn <PlayerBodyCtrl>(GetEntLot("player"), tilemap.GetCellCenterWorld(center + twin.down));
        cursor = banks["tinycursor"].Spawn(GetEntLot("cursor"));
        cursor.gameObject.SetActive(false);

        banks["badghost"].Spawn <BadGhost>(GetEntLot("ghosts")).Setup(mazeMaster, center + twin.up);
        banks["badghost"].Spawn <BadGhost>(GetEntLot("ghosts")).Setup(mazeMaster, center + twin.up);
        banks["pigeon"].Spawn <BadPigeon>(GetEntLot("ghosts")).Setup(mazeMaster, center + twin.up);
        banks["pigeon"].Spawn <BadPigeon>(GetEntLot("ghosts")).Setup(mazeMaster, center + twin.up);
    }
示例#9
0
    private void FixedUpdate()
    {
        if (body.velocity.magnitude < speed * 0.95f)
        {
            stuckFrames++;
            if (stuckFrames > 60)
            {
                lastMove    = -lastMove;
                my_cell_pos = new twin(master.grid.WorldToCell(this.transform.position));
                TryMove(lastMove);
                stuckFrames = 0;
            }
        }
        else
        {
            stuckFrames = 0;
        }

        anim          += animSpeed;
        anim          %= 2;
        spriter.sprite = sprs[11 + (int)anim];

        if (IsWithinDistOfCentered(2f))
        {
            TryDWMove();
        }

        body.velocity = ((Vector2)this.ToCentered()).normalized * speed; // go! go! go!
        if (Mathf.Abs(body.velocity.x) > speed * 0.5f)
        {
            spriter.flipX = body.velocity.x < 0;
        }
    }
示例#10
0
        override public void OnMoved(twin prev_pos, twin target_pos)
        {
            base.OnMoved(prev_pos, target_pos); // important.

            if (this.isWandering && !isGoingHome)
            {
                var index = pathNestToFood.IndexOf(target_pos);
                if (index >= 0)
                {
                    pathNestToFood.RemoveRange(index, pathNestToFood.Count - index);
                }
                else if (pathNestToFood.Count == 0 || (pathNestToFood[pathNestToFood.Count - 1] - target_pos).taxicabLength == 1)
                {
                    pathNestToFood.Add(target_pos);
                }
                else
                {
                    this.isGoingHome = true;
                }

                if (pathNestToFood.Count > maxPathLength)
                {
                    isGoingHome = true;
                }
            }
            else
            {
                // otherwise the path is locked-in! don't change a thing!
            }
        }
示例#11
0
    virtual protected void FixedUpdate()
    {

        if (GetComponent<Rigidbody2D>().velocity.sqrMagnitude < speed * speed * 0.5f) // being slowed down?
        {
            framesStuckFor++;
            if (framesStuckFor>=patience)
            {
                // react!
                my_cell_pos = new twin(master.grid.WorldToCell(transform.position));
                lastMove = -lastMove;
                ChooseMove_no180();
                //TryMove(-lastMove); // move backwards, reset pos.
                patience = Random.Range(10, 50);
            }
        } else
        {
            framesStuckFor = 0;
        }

        if (IsWithinDistOfCentered(2f))
        {
            // choose new dir
            ChooseMove_no180();
        } else
        {
            GetComponent<Rigidbody2D>().velocity = speed * ((Vector2)ToCentered()).normalized;
        }
    }
示例#12
0
        twin[] MagicWand(twin startingCellPos)
        {
            List <twin> wandedPositions = new List <twin>();

            wandedPositions.Add(startingCellPos);
            ushort magicValue = editGrid.GetCell(startingCellPos).value;

            for (int i = 0; i < wandedPositions.Count; i++)
            {
                twin   here = wandedPositions[i];
                twin[] ns   = new twin[4];
                ns[0] = here + twin.right;
                ns[1] = here + twin.up;
                ns[2] = here + twin.left;
                ns[3] = here + twin.down;
                foreach (twin n in ns)
                {
                    if (editGrid.CellPosInBounds(n) && editGrid.GetCell(n).value == magicValue && !wandedPositions.Contains(n))
                    {
                        wandedPositions.Add(n);
                    }
                }
            }
            if (wandedPositions.Count <= 1)
            {
                return(null);
            }
            twin[] poses = wandedPositions.ToArray();
            UpdateCursors(poses);
            return(poses);
        }
示例#13
0
 public void Unregister(MazeBody being, twin cell_pos)
 {
     if (bodyHeaps.ContainsKey(cell_pos))
     {
         bodyHeaps[cell_pos].Remove(being);
     }
 }
示例#14
0
 public AuthorXXIOptions(
     twin size_gridScreen,
     twin size_pixelsInCell,
     twin pos_gridScreen       = default(twin),
     twin size_palette         = default(twin),
     twin pos_startingRoom     = default(twin),
     char separator_grid_cells = ',',
     char separator_grid_codes = '×'
     )
 {
     this.size_gridScreen   = size_gridScreen;
     this.size_pixelsInCell = size_pixelsInCell;
     this.pos_gridScreen    = pos_gridScreen;
     if (size_palette > twin.zero)
     {
         this.size_palette = size_palette;
     }
     else
     {
         this.size_palette = new twin(10, 10);
     }
     this.pos_startingRoom     = pos_startingRoom;
     this.separator_grid_cells = separator_grid_cells;
     this.separator_grid_codes = separator_grid_codes;
 }
示例#15
0
 public GridCell Setup_RequiresGrid(NavdiGrid grid, twin cellPos)
 {
     base.Setup();
     this.grid = grid;
     this.SetCellPos(cellPos);
     // this.SetValue(0);
     return(this);
 }
示例#16
0
 public void Register(MazeBody body, twin cell_pos)
 {
     if (!bodyHeaps.ContainsKey(cell_pos))
     {
         bodyHeaps[cell_pos] = new HashSet <MazeBody>();
     }
     bodyHeaps[cell_pos].Add(body);
 }
示例#17
0
 void FloodPathAdd(twin nextPos, int distance)
 {
     if (CellPosInBounds(nextPos) && !floodPathQueue.Contains(nextPos) && GetCell(nextPos) > distance)
     {
         SetCell(nextPos, distance);
         floodPathQueue.Add(nextPos);
     }
 }
示例#18
0
 public AStarNode(twin pos, twin?parent = null, int g = 0, int h = 0, int f = 0)
 {
     this.pos    = pos;
     this.parent = parent;
     this.g      = g;
     this.h      = h;
     this.f      = f;
 }
示例#19
0
 public bool TryTakeNextMoveTo(twin target)
 {
     GetPathTo(target, out var move, out var path); // path is unused
     if (move == twin.zero || (no_turn_around && move == -lastMove))
     {
         return(false);                                                            // failed
     }
     return(TryMove(move));
 }
示例#20
0
        public void BoardSetup(Board board, twin cell)
        {
            this.board = board;
            this.board.AddAgent(this); // do better tracking
            this.xxi = board.xxi;
            base.Setup(board.master, cell);

            RandomizeSubtileOffset();
        }
示例#21
0
        override public void FrequentStep()
        {
            base.FrequentStep();

            twin cursorPos = editGrid.PointToCellPos(xxi.pcam.MouseWorldPoint());

            if (xxi.Input_MouseDown_LeftButton() && editGrid.CellPosInBounds(cursorPos))
            {
                if (cursorPositions == null)
                {
                    cursorPositions = MagicWand(cursorPos);
                }
                else
                {
                    cursorPositions = null;
                }
            }
            if (cursorPositions == null)
            {
                UpdateCursors(cursorPos);
            }

            twin dir;

            if (xxi.Input_KeyDown_PushToggle())
            {
                xxi.SaveRoom(editGrid);
                xxi.SetState(xxi.state_play);
            }
            else if (xxi.Input_Key_ShowPalette())
            {
                xxi.SaveRoom(editGrid);
                xxi.SetState(xxi.state_editpalette);
            }
            else if (xxi.Input_KeyDown_Dir(out dir))
            {
                MoveRoomCoord(dir);
            }
            else
            {
                ushort cellValue;
                if (xxi.Input_Key_CellValue(out cellValue))
                {
                    if (cursorPositions != null)                       // multi select cursor
                    {
                        foreach (twin pos in cursorPositions)
                        {
                            Paint(pos, cellValue);
                        }
                    }
                    else                         // basic hover cursor
                    {
                        Paint(cursorPos, cellValue);
                    }
                }
            }
        }
示例#22
0
 void MoveRoomCoord(twin dir)
 {
     ushort[] edge = CopyGridsEdge(dir, editGrid);
     xxi.SetRoomCoord(xxi.currentRoomCoord + dir, editGrid);
     if (edge != null)
     {
         PasteGridsEdge(edge, -dir, editGrid);
     }
 }
示例#23
0
 override public void OnMoved(twin prev_pos, twin target_pos)
 {
     hp--;
     transform.localScale = Vector3.one * 2 * hp / 8f;
     if (hp <= 0)
     {
         Destroy(gameObject); // boom
     }
 }
示例#24
0
    public BonsaiNode SpawnChildNode(BonsaiNode parent, twin verifiedDir)
    {
        var childNode = banks["node"].Spawn <BonsaiNode>(GetEntLot("nodes"));

        childNode.Setup(mazeMaster, parent.my_cell_pos + verifiedDir);
        childNode.SetParent(parent);
        AddNode(childNode);
        return(childNode);
    }
示例#25
0
    void SpawnDirtParts(twin cell, twinrect subpartrect)
    {
        var bottomleftpos = tilemap.CellToWorld(cell) + twin.one;

        subpartrect.DoEach(subpart =>
        {
            banks["dirtpart"].Spawn(GetEntLot("dirts"), bottomleftpos + subpart * 2);
        });
    }
示例#26
0
 void StartFlying(twin?target)
 {
     if (target.HasValue)
     {
         my_cell_pos  = target.Value;
         flying       = true;
         flyingToCell = target.Value;
         GetComponent <Collider2D>().isTrigger = true;
     }
 }
示例#27
0
 public void DoEach(twin pos, System.Action <twin, Tile> doWithTile)
 {
     for (var y = 0; y < height; y++)
     {
         for (var x = 0; x < width; x++)
         {
             doWithTile(pos + new twin(x, y), tileGrid[x, y]);
         }
     }
 }
示例#28
0
        public void Setup(Board board, twin cell)
        {
            base.BoardSetup(board, cell);
            this.thriving    = 0.5f;
            this.heart       = 1.0f;
            this.mature      = 0.0f;
            this.toNextCycle = this.cycleLength;

            transform.localScale = Vector3.one * 0.5f;
        }
示例#29
0
 public void FactionSetup(int faction, MazeMaster master, twin cell_pos)
 {
     this.faction = faction;
     if (this.faction == 2)
     {
         spriter.sprite = blueboySprite;
     }
     Setup(master, cell_pos);
     GetComponent <DotFactionizer>().faction = faction;
 }
示例#30
0
 public HashSet <MazeBody> GetBodiesAt(twin cell_pos)
 {
     if (bodyHeaps.TryGetValue(cell_pos, out var bodies))
     {
         return(bodies);
     }
     else
     {
         return(noBodies);
     }
 }