Beispiel #1
0
        protected override void OnUpdate()
        {
            Entity tag = Entity.Null;

            Entities.ForEach((Entity entity, ref Spawn spawn) => {
                if (spawn.Delay > 0)
                {
                    spawn.Delay--;
                    return;
                }
                tag = entity;
            });

            if (tag == Entity.Null)
            {
                return;
            }

            EntityCommandBuffer buffer = BufferSystem.CreateCommandBuffer();

            buffer.DestroyEntity(tag);

            if (!GameController.CanMove(GameController.SpawnX, GameController.SpawnY, 0))
            {
                GameController.GameOver();
                return;
            }

            Entity pieceCenter = buffer.CreateEntity(GameController.PieceArchetype);

            buffer.SetComponent(pieceCenter, new PiecePosition {
                CenterX = GameController.SpawnX,
                CenterY = GameController.SpawnY
            });

            PieceBlueprint piece = GameController.PiecesInfo[GameController.CurrentPiece];

            int2[]     map   = piece.BlockMap;
            int        l     = map.Length;
            RenderMesh rmesh = World.EntityManager.GetSharedComponentData <RenderMesh>(GameController.BlocKPrefab);

            rmesh.material = piece.PieceMaterial;

            for (int i = 0; i < l; i++)
            {
                int2   pos   = map[i];
                Entity block = buffer.Instantiate(GameController.BlocKPrefab);
                buffer.SetSharedComponent(block, rmesh);
                buffer.SetComponent(block, new BlockOffset {
                    Center  = pieceCenter,
                    OffsetX = pos.x,
                    OffsetY = pos.y
                });
                buffer.SetComponent(block, new Translation {
                    Value = new float3(GameController.SpawnX + pos.x, GameController.SpawnY + pos.y, 0f)
                });
            }
        }
Beispiel #2
0
        public static bool CanMove(int x, int y, int rotation)
        {
            PieceBlueprint piece = PiecesInfo[CurrentPiece];

            int2[] map = piece.BlockMap;
            int    l   = map.Length;

            x--;
            y--;
            for (int i = 0; i < l; i++)
            {
                int  tx, ty;
                int2 pos = map[i];
                switch (rotation)
                {
                case 90:
                    tx = x + pos.y;
                    ty = y - pos.x;
                    break;

                case 180:
                    tx = x - pos.x;
                    ty = y - pos.y;
                    break;

                case 270:
                    tx = x - pos.y;
                    ty = y + pos.x;
                    break;

                default:
                    tx = x + pos.x;
                    ty = y + pos.y;
                    break;
                }

                if (tx < 0 || tx >= Width || ty < 0 || (ty < Height && Grid[LinearPosition(tx, ty)] != Entity.Null))
                {
                    return(false);
                }
            }
            return(true);
        }