コード例 #1
0
    void Update()
    {
        // The player is grounded if a linecast to the groundcheck position hits anything on the ground layer.
        RaycastHit2D hit = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));

        grounded = hit;

        // If the jump button is pressed and the player is grounded then the player should jump.
        if (Input.GetButtonDown("Jump") && grounded)
        {
            jump = true;
        }

        Gridlike.Grid grid = Gridlike.Grid.GetFirstGrid();

        if (grid != null)
        {
            int x;
            int y;

            grid.WorldToGrid(Camera.main.ScreenToWorldPoint(Input.mousePosition), out x, out y);

            if (Input.GetMouseButton(0))
            {
                grid.showOnSet = true;
                grid.SetId(x, y, 1);
            }
            else if (Input.GetMouseButton(1))
            {
                grid.Clear(x, y);
            }
        }
    }
コード例 #2
0
        public void Damage(GSCharacter character, int x, int y, int damage, Vector2 position)
        {
            Tile tile = grid.Get(x, y);

            if (tile != null)
            {
                GSTileBehaviour behaviour = grid.GetTileComponent(x, y) as GSTileBehaviour;
                int             id        = tile.id;
                int             HP        = (int)tile.state1;

                if (behaviour != null)
                {
                    id = behaviour.tile.id;
                    x  = behaviour.x;
                    y  = behaviour.y;

                    HP = (int)grid.Get(x, y).state1;
                }

                if (GSConsts.TileExists(id))
                {
                    int hpLost;

                    if (HP + damage >= GSConsts.tiles [id].HP)
                    {
                        hpLost = Mathf.Min(damage, GSConsts.tiles [id].HP - HP);
                        grid.Clear(x, y);
                    }
                    else
                    {
                        hpLost = damage;
                        grid.SetState(x, y, HP + damage, 0, 0);
                    }

                    if (position == Vector2.zero)
                    {
                        position = grid.TileCenterInWorld(x, y);
                    }

                    CubeParticle.CreateParticles(position, character, Mathf.CeilToInt(hpLost * GSConsts.tiles [id].cubePerHP));
                }
                else
                {
                    grid.Clear(x, y);
                }
            }
        }