Ejemplo n.º 1
0
 public void reset()
 {
     rolling = false;
     height  = 0;
     TilemapHandler.getTile(TilemapHandler.getTileAtPosition(transform.position)).setHasBall(false);
     transform.position = startPosition;
     updatePosition();
 }
Ejemplo n.º 2
0
    void FixedUpdate()
    {
        if (rolling)
        {
            Vector3 dir = TilemapHandler.getTile(destination).transform.position - transform.position + new Vector3(0.5f, 0.5f);

            transform.position += new Vector3(dir.x, dir.y).normalized *0.15f;

            if (dir.sqrMagnitude < 0.15f || (TilemapHandler.getTile(TilemapHandler.getTileAtPosition(transform.position)).containsCharacter() && startRoll != TilemapHandler.getTileAtPosition(transform.position)))
            {
                updatePosition();
                rolling = false;
            }
        }
    }
Ejemplo n.º 3
0
    public void updatePosition()
    {
        TilemapHandler.clearBall();
        tilePosition = TilemapHandler.getTileAtPosition(transform.position);
        TilemapHandler.getTile(tilePosition).setHasBall(true);

        if (enemyGoal.GetComponent <Collider2D>().OverlapPoint(transform.position))
        {
            Score.playerScore++;
            TilemapHandler.reset();
        }

        if (ownGoal.GetComponent <Collider2D>().OverlapPoint(transform.position))
        {
            Score.enemyScore++;
            TilemapHandler.reset();
        }
    }
Ejemplo n.º 4
0
    void FixedUpdate()
    {
        if (turnEnded)
        {
            Vector3 dir = TilemapHandler.getTile(targetTile).transform.position - (transform.position - Vector3.up - new Vector3(0.5f, 0.1f));

            Vector3 movement = Vector3.zero;

            if ((dir.x * Vector3.right).sqrMagnitude > 0.02f)
            {
                movement = Vector3.right * (dir.x < 0 ? -1 : 1) * 0.1f;
                anim.SetBool(dir.x < 0 ? "Left" : "Right", true);
                if (state != animationState.LeftRight)
                {
                    anim.SetTrigger("Reset");
                    state = animationState.LeftRight;
                }
            }
            else if ((dir.y * Vector3.up).sqrMagnitude > 0.02f)
            {
                movement = Vector3.up * (dir.y < 0 ? -1 : 1) * 0.1f;
                anim.SetBool(dir.y < 0 ? "Down" : "Up", true);
                anim.SetBool("Left", false);
                anim.SetBool("Right", false);
                if (state != animationState.UpDown)
                {
                    anim.SetTrigger("Reset");
                    state = animationState.UpDown;
                }
            }
            else if (kicksBall)
            {
                kicksBall = false;
                GameObject.Find("Ball").GetComponent <BallController>().kick();
            }
            else
            {
                if (hasBall)
                {
                    GameObject.Find("Ball").GetComponent <BallController>().updatePosition();
                }
                turnEnded = false;
                anim.SetTrigger("Reset");
                anim.SetBool("Left", false);
                anim.SetBool("Right", false);
                anim.SetBool("Up", false);
                anim.SetBool("Down", false);
            }

            transform.position += movement;

            if (hasBall)
            {
                GameObject.Find("Ball").transform.position += movement;
            }
            else if (TilemapHandler.getTile(TilemapHandler.getTileAtPosition(transform.position - Vector3.up * 0.5f)).getHasBall())
            {
                hasBall = true;

                TilemapHandler.getTile(TilemapHandler.getTileAtPosition(transform.position)).GetComponent <TileHandler>().setHasBall(false);
                TilemapHandler.getTile(tilePosition).GetComponent <TileHandler>().setHasBall(true);
            }
        }
    }
Ejemplo n.º 5
0
    void Update()
    {
        if (!TilemapHandler.hasTurnEnded())
        {
            return;
        }

        if (turn == players.player)
        {
            Vector3 tile = tmh.roundToTilePosition(Camera.main.ScreenToWorldPoint(Input.mousePosition));

            if (selectedTile == null)
            {
                cursor.transform.position = tile + new Vector3(0.5f, 0.5f);
            }
            else
            {
                if (Input.GetButton("Kick"))
                {
                    cursor.transform.position = tile + new Vector3(0.5f, 0.5f);

                    br.SetActive(true);
                    ma.SetActive(false);
                    isKicking = true;
                }
                else
                {
                    br.SetActive(false);
                    ma.SetActive(true);
                    isKicking = false;

                    generateArrow(tile - GameObject.Find("Playing Area").GetComponent <Tilemap>().origin);
                }
            }

            if (Input.GetButtonDown("Next Round"))
            {
                TilemapHandler.endTurn();

                selectedTile = null;
                ma.SetActive(false);
                selected.SetActive(false);
                br.GetComponent <Tilemap>().ClearAllTiles();

                turn = players.enemy;
            }

            if (Input.GetMouseButtonDown(0))
            {
                Vector2Int highlightedTile = TilemapHandler.getTileAtPosition(Camera.main.ScreenToWorldPoint(Input.mousePosition));
                if (selectedTile == null)
                {
                    if (TilemapHandler.getTile(highlightedTile.x, highlightedTile.y).containsPlayer())
                    {
                        selectedTile = TilemapHandler.getTile(highlightedTile.x, highlightedTile.y);

                        selected.transform.position = selectedTile.transform.position + new Vector3(0.5f, 0.5f);
                        selected.SetActive(true);

                        br.SetActive(true);
                        selectedTile.getCharacter().GetComponent <PlayerHandler>().generateField();
                        br.transform.position += br.GetComponent <Tilemap>().WorldToCell(selectedTile.getCharacter().transform.position) * new Vector3Int(1, 1, 0) - new Vector3Int(0, 1, 0);
                        br.SetActive(false);
                    }
                }
                else if (!isKicking)
                {
                    if (selectedTile.tilemapPosition != highlightedTile)
                    {
                        selectedTile.getCharacter().GetComponent <PlayerHandler>().move(tmh, highlightedTile);
                    }

                    selectedTile = null;
                    ma.SetActive(false);
                    selected.SetActive(false);
                    br.GetComponent <Tilemap>().ClearAllTiles();
                }
                else
                {
                    selectedTile.getCharacter().GetComponent <PlayerHandler>().kick(tmh, highlightedTile);

                    selectedTile = null;
                    ma.SetActive(false);
                    selected.SetActive(false);
                    br.GetComponent <Tilemap>().ClearAllTiles();
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                selectedTile = null;
                ma.SetActive(false);
                selected.SetActive(false);
                br.GetComponent <Tilemap>().ClearAllTiles();
            }
        }
        else
        {
            List <Transform> enemies = new List <Transform>();
            enemies.AddRange(TilemapHandler.enemies);

            Transform hasBall = null;

            foreach (Transform enemy in enemies)
            {
                PlayerHandler ph = enemy.GetComponent <PlayerHandler>();

                if (TilemapHandler.getTile(ph.tilePosition).getHasBall())
                {
                    hasBall = enemy;
                    enemies.Remove(enemy);
                    break;
                }

                if (!ph.tooFarAway(GameObject.Find("Ball").GetComponent <BallController>().tilePosition))
                {
                    ph.move(tmh, GameObject.Find("Ball").GetComponent <BallController>().tilePosition);
                    enemies.Remove(enemy);
                    break;
                }
            }

            //Goal
            enemies.Sort((p1, p2) => p2.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(7, 20)).CompareTo(p1.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(7, 20))));

            enemies[enemies.Count - 1].GetComponent <PlayerHandler>().tryMove(tmh, new Vector2Int(7, 20));
            enemies.Remove(enemies[enemies.Count - 1]);

            //Right
            enemies.Sort((p1, p2) => p2.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(12, 3)).CompareTo(p1.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(12, 3))));

            enemies[enemies.Count - 1].GetComponent <PlayerHandler>().tryMove(tmh, new Vector2Int(12, 3));
            enemies.Remove(enemies[enemies.Count - 1]);

            //Left
            enemies.Sort((p1, p2) => p2.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(2, 3)).CompareTo(p1.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(2, 3))));

            enemies[enemies.Count - 1].GetComponent <PlayerHandler>().tryMove(tmh, new Vector2Int(2, 3));
            enemies.Remove(enemies[enemies.Count - 1]);

            //Middle
            enemies.Sort((p1, p2) => p2.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(7, 3)).CompareTo(p1.GetComponent <PlayerHandler>().moveDistanceTo(new Vector2Int(7, 3))));

            enemies[enemies.Count - 1].GetComponent <PlayerHandler>().tryMove(tmh, new Vector2Int(7, 3));
            enemies.Remove(enemies[enemies.Count - 1]);

            if (hasBall != null)
            {
                enemies.Clear();
                enemies.AddRange(TilemapHandler.enemies);
                enemies.Remove(hasBall);
                enemies.Sort((p1, p2) => p2.GetComponent <PlayerHandler>().moveDistanceTo(hasBall.GetComponent <PlayerHandler>().tilePosition).CompareTo(p1.GetComponent <PlayerHandler>().moveDistanceTo(hasBall.GetComponent <PlayerHandler>().tilePosition)));

                foreach (Transform player in TilemapHandler.players)
                {
                    if ((player.GetComponent <PlayerHandler>().tilePosition - hasBall.GetComponent <PlayerHandler>().tilePosition).sqrMagnitude < 4)
                    {
                        hasBall.GetComponent <PlayerHandler>().kick(tmh, enemies[enemies.Count - 1].GetComponent <PlayerHandler>().tilePosition);
                    }
                }

                if (!hasBall.GetComponent <PlayerHandler>().outOfKickingRange(new Vector2Int(7, 0)))
                {
                    hasBall.GetComponent <PlayerHandler>().kick(tmh, new Vector2Int(7, 0));
                }
            }

            TilemapHandler.endEnemyTurn();
            turn = players.player;
        }
    }
Ejemplo n.º 6
0
 public void kick()
 {
     rolling   = true;
     startRoll = TilemapHandler.getTileAtPosition(transform.position);
 }