Ejemplo n.º 1
0
    void Start()
    {
        _systems = CreateSystems(_contexts, _services);
        _systems.Initialize();

        _contexts.game.isMainGameScreen = true;

        _contexts.level.ReplaceLevelId(0);

        var level  = _services.level.CreateLevel();
        var player = _services.gameEntity.CreatePlayer();

        player.ReplacePosition(GameBoardElementPosition.Create(level.level.id, 0, 0));

        for (var i = 0; i < 1; i++)
        {
            var npc = _services.gameEntity.CreateNpc();
            npc.ReplacePosition(GameBoardElementPosition.Create(level.level.id, 1, 1));
        }
        for (var i = 0; i < 10000; i++)
        {
            var npc = _services.gameEntity.CreateInvisibleNpc();
            npc.ReplacePosition(GameBoardElementPosition.Create(level.level.id, 1, 1));
        }
    }
Ejemplo n.º 2
0
    public void ReplaceInitiateAttack(GameBoardElementPosition newTargetPosition)
    {
        var index     = GameComponentsLookup.InitiateAttack;
        var component = CreateComponent <InitiateAttack>(index);

        component.targetPosition = newTargetPosition;
        ReplaceComponent(index, component);
    }
Ejemplo n.º 3
0
    public void ReplacePosition(GameBoardElementPosition newValue)
    {
        var index     = GameComponentsLookup.Position;
        var component = CreateComponent <PositionComponent>(index);

        component.value = newValue;
        ReplaceComponent(index, component);
    }
    public void ReplaceMoveAction(GameBoardElementPosition newTargetPosition)
    {
        var index     = GameComponentsLookup.MoveAction;
        var component = CreateComponent <MoveActionComponent>(index);

        component.targetPosition = newTargetPosition;
        ReplaceComponent(index, component);
    }
    public void ReplaceAttackCommand(GameBoardElementPosition newTargetPosition)
    {
        var index     = GameComponentsLookup.AttackCommand;
        var component = CreateComponent <AttackCommand>(index);

        component.targetPosition = newTargetPosition;
        ReplaceComponent(index, component);
    }
    public void ReplaceAttackMoveCommand(IntVector2 newDirection, GameBoardElementPosition newTargetPosition)
    {
        var index     = GameComponentsLookup.AttackMoveCommand;
        var component = CreateComponent <AttackMoveCommand>(index);

        component.direction      = newDirection;
        component.targetPosition = newTargetPosition;
        ReplaceComponent(index, component);
    }
Ejemplo n.º 7
0
    public override void OnPosition(GameEntity entity, GameBoardElementPosition position)
    {
//    Debug.Log($"Set Position: {position.x},{position.y}");
//        var isTopRow = value.y == Contexts.sharedInstance.game.gameBoard.rows - 1;
//        if (isTopRow) {
//            transform.localPosition = new Vector3(value.x, value.y + 1);
//        }
        transform.position = new Vector3(position.x, position.y);
//        transform.DOMove(new Vector3(value.x, value.y, 0f), 0.3f);
    }
Ejemplo n.º 8
0
    protected override void Execute(List <GameEntity> entities)
    {
        foreach (var entity in entities)
        {
            var position       = entity.position.value;
            var targetPosition = entity.moveAction.targetPosition;

            entity.ReplacePosition(GameBoardElementPosition.Create(position.levelId, targetPosition.x, targetPosition.y));
        }
    }
Ejemplo n.º 9
0
 private void AddMoveCommand(IntVector2 direction)
 {
     foreach (var entity in _interactiveEntities)
     {
         var position       = entity.position.value;
         var targetPosition = GameBoardElementPosition.Create(position.levelId, position.x + direction.x, position.y + direction.y);
         if (targetPosition != null)
         {
             entity.ReplaceMoveCommand(direction, targetPosition);
         }
     }
 }
    private void GenerateLevel(LevelEntity levelEntity)
    {
        var level = levelEntity.level;

        for (var x = 0; x < level.columns; x++)
        {
            for (var y = 0; y < level.rows; y++)
            {
                var tile = _game.CreateEntity();
                tile.isTile = true;
                tile.AddPosition(GameBoardElementPosition.Create(level.id, x, y));
                tile.AddFloor("dirt");
                tile.AddAsset("GameBoardElement");
//    entity.AddAsciiSprite("DejaVuSansMono_2");
                tile.AddAsciiSprite("dot");
                tile.isVisible = true;
            }
        }

        levelEntity.isUngeneratedLevel = false;
    }
Ejemplo n.º 11
0
    public static GameBoardElementPosition Create(int levelId, int x, int y)
    {
        if (x < 0 || y < 0)
        {
            return(null);
        }

        GameBoardElementPosition[][] levelPositions;
        if (positions.TryGetValue(levelId, out levelPositions))
        {
            if (levelPositions.Length <= x)
            {
                return(null);
            }

            var column = levelPositions[x];
            if (column.Length <= y)
            {
                return(null);
            }

            return(column[y]);
        }

        var level = Contexts.sharedInstance.level.GetEntityWithLevel(levelId).level;

        levelPositions = new GameBoardElementPosition[level.columns][];
        for (var col = 0; col < levelPositions.Length; col++)
        {
            var rows = levelPositions[col] = new GameBoardElementPosition[level.rows];
            for (var row = 0; row < rows.Length; row++)
            {
                rows[row] = new GameBoardElementPosition(levelId, col, row);
            }
        }

        positions.Add(levelId, levelPositions);
        return(levelPositions[x][y]);
    }
    private bool CheckForBlockers(GameBoardElementPosition targetPosition)
    {
        UnityEngine.Profiling.Profiler.BeginSample("Get Position");

        var entities = _gameContext
                       .GetEntitiesWithPosition(targetPosition);

        UnityEngine.Profiling.Profiler.EndSample();

//    int i = 0;
        UnityEngine.Profiling.Profiler.BeginSample("Iterate count");

        foreach (var entity in entities)
        {
            if (entity.isPhysicalBarrier)
            {
                return(true);
            }
//      i++;
        }
        UnityEngine.Profiling.Profiler.EndSample();

//    UnityEngine.Profiling.Profiler.BeginSample("Iterate null check");
//
//    foreach (var entity in entities)
//    {
////      if (entity.isPhysicalBarrier)
////      {
////        return true;
////      }
//      if (entity == null)
//      {
//        return true;
//      }
//    }
//    UnityEngine.Profiling.Profiler.EndSample();

        return(false);
    }
Ejemplo n.º 13
0
 public static System.Collections.Generic.HashSet <GameEntity> GetEntitiesWithPosition(this GameContext context, GameBoardElementPosition value)
 {
     return(((Entitas.EntityIndex <GameEntity, GameBoardElementPosition>)context.GetEntityIndex(Contexts.Position)).GetEntities(value));
 }
Ejemplo n.º 14
0
 public static System.Collections.Generic.HashSet <GameEntity> GetPhysicalBarrierEntitiesWithPosition(this GameContext context, GameBoardElementPosition index)
 {
     return(((PositionPhysicalBarrierIndex)(context.GetEntityIndex(Contexts.PositionPhysicalBarrierIndex))).GetPhysicalBarrierEntitiesWithPosition(index));
 }
    private bool CheckForBlockers2(GameBoardElementPosition position)
    {
//    return false;
        return(_gameContext.GetPhysicalBarrierEntitiesWithPosition(position).Count > 0);
    }
Ejemplo n.º 16
0
 public virtual void OnPosition(GameEntity entity, GameBoardElementPosition position)
 {
     transform.localPosition = new Vector3(position.x, position.y);
 }
Ejemplo n.º 17
0
    public void Execute()
    {
        foreach (var entity in _entities)
        {
            var position = entity.position.value;
            var level    = _levelContext.GetEntityWithLevel(position.levelId).level;
            var x        = GetRandomPosition(position.x, level.columns);
            var y        = GetRandomPosition(position.x, level.rows);

            entity.ReplaceMoveCommand(new IntVector2(x - position.x, y - position.y), GameBoardElementPosition.Create(position.levelId, x, y));
        }
    }