Exemplo n.º 1
0
    public bool CheckPos(Vector2Int aOffset)
    {
        bool isValid = true;

        for (int x = this.entity.pos.x + aOffset.x; x < this.entity.pos.x + aOffset.x + this.entity.size.x; x++)
        {
            for (int y = this.entity.pos.y + aOffset.y; y < this.entity.pos.y + aOffset.y + this.entity.size.y; y++)
            {
                Vector2Int  checkPos    = new Vector2Int(x, y);
                BlockObject maybeABlock = BoardManager.GetBlockOnPosition(checkPos);
                MobObject   maybeAMob   = BoardManager.GetMobOnPosition(checkPos);
                if (maybeABlock != null)
                {
                    return(false);
                }
                if (maybeAMob != null)
                {
                    if (maybeAMob == this.entity)
                    {
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }
        return(isValid);
    }
Exemplo n.º 2
0
    public void OnMobTimerTimeout()
    {
        mobSpawnLocation.SetOffset(randomGenerator.Next());
        MobObject mobObject = (MobObject)mob.Instance();

        AddChild(mobObject);
        var direction = mobSpawnLocation.GetRotation();

        mobObject.SetPosition(mobSpawnLocation.GetPosition());
        direction += (float)RandomRange(-Math.PI / 4.0, Math.PI / 4.0);
        mobObject.SetRotation(direction);
        Vector2 linearVelocity = new Vector2(randomGenerator.Next(mobObject.minSpeed, mobObject.maxSpeed), 0);

        mobObject.SetLinearVelocity(linearVelocity.Rotated(direction));
    }
Exemplo n.º 3
0
    public void Init(LevelData aLevelData)
    {
        this.levelData = aLevelData;
        Vector3    backgroundOffset    = new Vector3(0, 0, 1);
        Vector3    backgroundThiccness = new Vector3(0, 0, 0.1f);
        GameObject newBackground       = Instantiate(this.backgroundMaster, GameUtil.V2IOffsetV3(this.levelData.boardSize, Vector2Int.zero) + backgroundOffset, Quaternion.identity);

        newBackground.transform.localScale = GameUtil.V2IToV3(this.levelData.boardSize) + backgroundThiccness;
        newBackground.name = "Background";
        foreach (BlockData blockData in aLevelData.blockDataList)
        {
            BlockObject currentGameObject;
            if (blockData.type == BlockTypeEnum.FAN)
            {
                currentGameObject = this.fanMaster;
            }
            else
            {
                currentGameObject = this.blockMaster;
            }
            BlockObject newBlockObject = Instantiate(currentGameObject, GameUtil.V2IOffsetV3(blockData.size, blockData.pos), Quaternion.identity);
            newBlockObject.transform.parent = this.transform;
            newBlockObject.Init(blockData);
            this.blockList.Add(newBlockObject);
        }
        foreach (MobData mobData in aLevelData.mobDataList)
        {
            MobObject mobPrefab = this.mobMaster;
            switch (mobData.mobPrefabName)
            {
            case "Player":
                mobPrefab = this.playerMaster;
                break;
            }

            MobObject newMobObject = Instantiate(mobPrefab, GameUtil.V2IOffsetV3(mobData.size, mobData.pos), Quaternion.identity);
            newMobObject.transform.parent = this.transform;
            newMobObject.Init(mobData);
            this.mobList.Add(newMobObject);
            if (newMobObject.tag == "MyPlayer")
            {
                this.player = newMobObject;
            }
        }
    }
Exemplo n.º 4
0
    public static bool CheckValidMove(Vector2Int aOffset, List <BlockObject> aSelectedList)
    {
        // print("CHECKING VALID MOVE");
        HashSet <Vector2Int> checkTopPositions = new HashSet <Vector2Int>();
        HashSet <Vector2Int> checkBotPositions = new HashSet <Vector2Int>();

        foreach (BlockObject block in aSelectedList)
        {
            // for each position inside block
            for (int x = 0; x < block.size.x; x++)
            {
                for (int y = 0; y < block.size.y; y++)
                {
                    Vector2Int currentPos = block.pos + aOffset + new Vector2Int(x, y);
                    // check if in bounds of level
                    if (!GameUtil.IsInside(currentPos, Vector2Int.zero, BoardManager.Instance.levelData.boardSize))
                    {
                        // print("IS BLOCKED! NOT IN LEVEL BOUNDS");
                        return(false);
                    }
                    BlockObject maybeABlock = GetBlockOnPosition(currentPos);
                    // check if this position is occupied by something not itself
                    if (maybeABlock != null && !aSelectedList.Contains(maybeABlock))
                    {
                        // print("IS BLOCKED! INVALID MOVE!!!");
                        return(false);
                    }
                    // check if a mob exists on this position
                    MobObject maybeAMob = GetMobOnPosition(currentPos);
                    if (maybeAMob != null)
                    {
                        // print("IS BLOCKED! MOB EXISTS HERE");
                        return(false);
                    }
                }
            }
            // fill in checktop/checkbot positions as a list of pos that need to be checked
            for (int x = block.ghostPos.x; x < block.ghostPos.x + block.size.x; x++)
            {
                int        aboveY = block.ghostPos.y + block.size.y;
                int        belowY = block.ghostPos.y - 1;
                Vector2Int topPos = new Vector2Int(x, aboveY);
                Vector2Int botPos = new Vector2Int(x, belowY);
                foreach (BlockObject otherBlock in aSelectedList)
                {
                    if (PlayingManager.GetSelectedBlockOnPosition(topPos) == null)
                    {
                        // print("toppos does not contain a selected block");
                        Vector2Int checkPos = new Vector2Int(x, aboveY);
                        checkTopPositions.Add(checkPos);
                    }
                    if (PlayingManager.GetSelectedBlockOnPosition(botPos) == null)
                    {
                        // print("botpos does not contain a selected block");
                        Vector2Int checkPos = new Vector2Int(x, belowY);
                        checkBotPositions.Add(checkPos);
                    }
                }
            }
        }
        bool connectedOnTop = false;
        bool connectedOnBot = false;

        foreach (Vector2Int pos in checkTopPositions)
        {
            // print("examining pos " + pos);
            if (GetBlockOnPosition(pos) != null && !aSelectedList.Contains(GetBlockOnPosition(pos)))
            {
                connectedOnTop = true;
                // print("connected on top at" + pos);
            }
        }
        foreach (Vector2Int pos in checkBotPositions)
        {
            // print("examining pos " + pos);
            if (GetBlockOnPosition(pos) != null && !aSelectedList.Contains(GetBlockOnPosition(pos)))
            {
                connectedOnBot = true;
                // print("connected on bot at" + pos);
            }
        }
        if (connectedOnTop == true && connectedOnBot == true)
        {
            // print("IS SANDWICHED! INVALID MOVE!!!");
            return(false);
        }
        else if (connectedOnTop == false && connectedOnBot == false)
        {
            // print("IS FLOATING! INVALID MOVE!!!");
            return(false);
        }
        else
        {
            // print ("VALID MOVE");
            return(true);
        }
    }