Example #1
0
 public override void Init()
 {
     base.Setup("pincer");
     eyes = Primitives.CreateActor(Sprites.eye);
     Util.SetLayer(eyes, Util.LayerName.Entities, 5);
     eyes.transform.SetParent(transform, false);
 }
Example #2
0
    public static S_OptionSlider CreateSlider(int width)
    {
        GameObject go  = new GameObject("Slider");
        GameObject pip = Primitives.CreateActor(Sprites.pip);
        S_Button   bar = S_Button.CreateButton(Sprites.pixel);

        bar.transform.localScale = new Vector2(width, BAR_HEIGHT);
        bar.GetComponent <BoxCollider2D>().size   = new Vector2(1f, 3.5f);
        bar.GetComponent <SpriteRenderer>().color = Colours.GREEN;


        Util.SetLayer(pip, Util.LayerName.UI, 5);
        pip.transform.SetParent(go.transform, false);
        pip.transform.position = new Vector2((int)(width / 5f * 3), (int)(-Sprites.GetBounds(Sprites.pip).y *S_Camera.scale / 2f + BAR_HEIGHT / 2));
        S_OptionSlider slider = go.AddComponent <S_OptionSlider>();

        slider.width = width;
        bar.transform.SetParent(go.transform, false);
        Util.SetLayer(bar.gameObject, Util.LayerName.UI, 5);
        slider.pipObject = pip.gameObject;
        bar.SetDownAction(() => slider.down = true);
        bar.SetUpAction(() => slider.OnUp());

        S_Camera.SetupScale(pip.transform);
        return(slider);
    }
Example #3
0
    public static GameObject CreateAnimation(Sprite[] frames, float speed, int x, int y)
    {
        GameObject go = Primitives.CreateActor(frames[0], x, y);

        go.name = "animation";
        S_Animation anim = go.AddComponent <S_Animation>();

        anim.Init(frames, speed);
        return(go);
    }
Example #4
0
    private void EndScreen()
    {
        end = true;
        GameObject rect = Primitives.CreateRectangle(Screen.width, Screen.height, Colours.DARK);

        Util.SetLayer(rect, Util.LayerName.Particles, 400);
        GameObject go     = Primitives.CreateActor(Sprites.end);
        int        xScale = (int)(Screen.width / Sprites.GetBounds(Sprites.end).x);
        int        yScale = (int)(Screen.height / Sprites.GetBounds(Sprites.end).y);
        int        scale  = Mathf.Min(xScale, yScale);

        go.transform.localScale = new Vector2(scale, scale);
        go.transform.position   = new Vector2((int)(Screen.width - Sprites.GetBounds(Sprites.end).x *scale) / 2, (int)(Screen.height - Sprites.GetBounds(Sprites.end).y *scale) / 2);
        Util.SetLayer(go, Util.LayerName.Particles, 500);
        PlayerPrefs.SetInt("level", 0);
    }
Example #5
0
    public void SetPosition(int x, int y)
    {
        this.x             = x;
        this.y             = y;
        transform.position = new Vector3(width * x + S_Camera.scale, height * y + S_Camera.scale, 0);
        GameObject highlight = Primitives.CreateActor(Sprites.tile_highlight, 0, 0);

        highlight.name = "highlight";
        highlight.transform.SetParent(transform, false);
        highlight_renderer = highlight.GetComponent <SpriteRenderer>();
        Util.SetLayer(highlight, Util.LayerName.Tiles, 5);
        highlight_renderer.color   = Colours.LIGHT;
        highlight_renderer.enabled = false;
        gameObject.AddComponent <BoxCollider2D>();
        Util.SetZ(gameObject, Util.ZLayer.Gameplay);
    }
Example #6
0
 private void UpdateMystery()
 {
     if (levelNumber >= Sprites.mysteries.Length)
     {
         return;
     }
     if (innerMystery != null)
     {
         GameObject.Destroy(innerMystery);
     }
     innerMystery = Primitives.CreateActor(Sprites.mysteries[levelNumber]);
     innerMystery.transform.SetParent(mysteryButton.transform, false);
     innerMystery.transform.localPosition = new Vector2(1, 1);
     innerMystery.transform.localScale    = new Vector2(2, 2);
     Util.SetLayer(innerMystery, Util.LayerName.UI, 50);
     innerMystery.GetComponent <SpriteRenderer>().color = Colours.ALL[mysteryCol];
 }
Example #7
0
    internal void UpdatePips()
    {
        foreach (GameObject p in pipObjects)
        {
            Destroy(p);
        }
        pipObjects.Clear();
        int pipGap   = (int)((Sprites.GetBounds(Sprites.ability_border).x - 2 - Sprites.GetBounds(Sprites.ability_pip).x *pips) / (pips + 1));
        int currentX = 2 + pipGap;

        for (int i = 0; i < pips; i++)
        {
            GameObject pip = Primitives.CreateActor(Sprites.ability_pip, currentX, 2);
            pipObjects.Add(pip);
            Util.SetLayer(pip, Util.LayerName.UI, 0);
            currentX += (int)(Sprites.GetBounds(Sprites.ability_pip).x);
            currentX += pipGap;
            pip.transform.SetParent(transform, false);
            pip.name = "pip";
        }
    }
Example #8
0
 void UpdateTargeting()
 {
     if (Game.Get().state != Game.GameState.Normal)
     {
         return;
     }
     ClearTargets();
     if (charging > 0)
     {
         S_Tile playerTile = Level.Get(gameObject).player.currentTile;
         int    dx         = Util.ProperSign(playerTile.x - currentTile.x);
         int    dy         = Util.ProperSign(playerTile.y - currentTile.y);
         foreach (S_Tile tile in currentTile.GetTilesInLine(dx, dy))
         {
             GameObject go = Primitives.CreateActor(dx == 0 ? Sprites.charge_v : Sprites.charge_h);
             Util.SetLayer(go, Util.LayerName.Tiles, 20);
             go.transform.SetParent(tile.transform, false);
             go.GetComponent <SpriteRenderer>().color = charging == 1 ? Colours.GREEN : Colours.LIGHT;
             targets.Add(go);
         }
     }
 }
Example #9
0
    public void Setup(int[] headerData)
    {
        List <S_Button> buttons = new List <S_Button>();

        name = "Ability Panel";
        int numAbilities = Util.ProperSign(headerData[0]) + Util.ProperSign(headerData[1]) + Util.ProperSign(headerData[2]);

        //
        for (int i = 0; i < headerData.Length; i++)
        {
            int datum = headerData[i];
            if (datum == 0)
            {
                continue;
            }
            S_Button  buttonScrip = S_Button.CreateButton(Sprites.ability_border);
            S_Ability ability     = null;
            switch (datum & 3)
            {
            case 1: ability = buttonScrip.gameObject.AddComponent <S_Ability_Move3>(); break;

            case 2: ability = buttonScrip.gameObject.AddComponent <S_Ability_Eye>(); break;

            case 3: ability = buttonScrip.gameObject.AddComponent <S_Ability_Swap>(); break;
            }
            abilities.Add(ability);
            ability.init((datum & 28) >> 2);
            buttonScrip.SetDownAction(() => {
                if (Game.IsPaused())
                {
                    return;
                }
                ability.Click();
            });
            GameObject button = buttonScrip.gameObject;
            button.name = "Button";
            Util.SetColour(button, Colours.RED);
            buttons.Add(button.GetComponent <S_Button>());
            S_Camera.SetupScale(buttonScrip.transform);
            GameObject image = Primitives.CreateActor(ability.GetSprite(), 1, 9);
            image.name = "image";
            Util.SetLayer(image, Util.LayerName.Tiles, 0);
            image.transform.SetParent(buttonScrip.gameObject.transform, false);
            if (Game.KEYBOARD)
            {
                GameObject text     = Primitives.CreateText("[" + ability.GetKey() + "]", 0, 0);
                S_Follower follower = text.AddComponent <S_Follower>();
                follower.Follow(button, -20 * S_Camera.scale, (int)((Sprites.GetBounds(Sprites.ability_border).y *S_Camera.scale / 2f - 7 * S_Camera.scale)));
                ability.SetText(text);
            }
            Util.SetZ(button, Util.ZLayer.Gameplay);
        }

        int gap      = 10 * S_Camera.scale;
        int currentY = -gap;

        foreach (S_Button butt in buttons)
        {
            currentY += gap;
            butt.transform.position = new Vector2(0, currentY);
            currentY += (int)(butt.GetBounds().size.y);
        }

        width  = 37 * S_Camera.scale;;
        height = currentY;
        foreach (S_Button butt in buttons)
        {
            butt.transform.SetParent(transform, false);
        }
    }
Example #10
0
    public static GameObject CreatePauseScreen()
    {
        //all this code is a big pile of rubbish, I need to try unity unity ui next time!

        //background
        GameObject pauseScreen = new GameObject("pause_screen");
        GameObject pauseBG     = Primitives.CreateRectangle(pauseWidth, pauseHeight, Colours.RED);

        pauseBG.transform.SetParent(pauseScreen.transform, false);
        BoxCollider2D pausebgcol = pauseBG.AddComponent <BoxCollider2D>();

        pausebgcol.size   = new Vector2(1, 1);
        pausebgcol.offset = new Vector2(.5f, .5f);
        Util.SetLayer(pauseBG, Util.LayerName.UI, 0);
        Util.SetZ(pauseBG, Util.ZLayer.PauseLayer);
        GameObject pauseBGInner = Primitives.CreateRectangle(pauseWidth - border * 2, pauseHeight - border * 2, Colours.DARK);

        pauseBGInner.transform.position = new Vector2(border, border);
        pauseBGInner.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(pauseBGInner, Util.LayerName.UI, 1);
        Util.SetLayer(pauseBG, Util.LayerName.UI, 1);
        pauseScreen.transform.position = new Vector2((int)(Screen.width / 2 - pauseWidth / 2), (int)(Screen.height / 2 - pauseHeight / 2));

        //sliders
        int barWidth = (int)(pauseWidth - border * 2 - gap * 3 - Sprites.GetBounds(Sprites.sound).x *S_Camera.scale);
        int barX     = (int)(border + gap * 2 + Sprites.GetBounds(Sprites.sound).x *S_Camera.scale);
        int currentY = pauseHeight - border;

        currentY            -= gap + S_OptionSlider.TOTAL_HEIGHT;
        S_OptionSlider.music = S_OptionSlider.CreateSlider(barWidth);
        S_OptionSlider.music.transform.position = new Vector2(barX, currentY);
        S_OptionSlider.music.transform.SetParent(pauseScreen.transform, false);
        Util.SetZ(S_OptionSlider.music.gameObject, Util.ZLayer.Sliders);
        GameObject music = Primitives.CreateActor(Sprites.music);

        S_Camera.SetupScale(music.transform);
        music.transform.position = new Vector2(border + gap, currentY + S_OptionSlider.BAR_HEIGHT / 2 - Sprites.GetBounds(Sprites.music).y *S_Camera.scale / 2);
        music.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(music, Util.LayerName.UI, 50);
        currentY -= gap + S_OptionSlider.TOTAL_HEIGHT;
        S_OptionSlider.music.SetUpAction(() => { PlayerPrefs.SetFloat("music", S_OptionSlider.music.GetValue()); });
        S_OptionSlider.music.SetRatio(PlayerPrefs.GetFloat("music", .7f));

        S_OptionSlider.sfx = S_OptionSlider.CreateSlider(barWidth);
        S_OptionSlider.sfx.transform.position = new Vector2(barX, currentY);
        S_OptionSlider.sfx.transform.SetParent(pauseScreen.transform, false);
        Util.SetZ(S_OptionSlider.sfx.gameObject, Util.ZLayer.Sliders);
        GameObject sound = Primitives.CreateActor(Sprites.sound);

        S_Camera.SetupScale(sound.transform);
        sound.transform.position = new Vector2(border + gap, currentY + S_OptionSlider.BAR_HEIGHT / 2 - Sprites.GetBounds(Sprites.music).y *S_Camera.scale / 2);
        sound.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(sound, Util.LayerName.UI, 50);
        currentY -= gap + S_OptionSlider.TOTAL_HEIGHT;
        S_OptionSlider.sfx.SetUpAction(() => { PlayerPrefs.SetFloat("sfx", S_OptionSlider.sfx.GetValue()); });
        S_OptionSlider.sfx.SetRatio(PlayerPrefs.GetFloat("sfx", .7f));

        //icons
        int codeX  = (pauseWidth - border * 2) / 3 + border;
        int musicX = (pauseWidth - border * 2) / 3 * 2 + border;

        int iconY    = currentY;
        int twitterY = (int)(iconY - gap - Sprites.GetBounds(Sprites.twitter).y *S_Camera.scale / 2f);

        iconY += gap / 2;

        GameObject code = Primitives.CreateActor(Sprites.code);

        S_Camera.SetupScale(code.transform);
        code.transform.position = new Vector2(codeX - Sprites.GetBounds(Sprites.code).x *S_Camera.scale / 2f, iconY - Sprites.GetBounds(Sprites.code).y *S_Camera.scale / 2f);
        code.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(code, Util.LayerName.UI, 50);

        music = Primitives.CreateActor(Sprites.music);
        S_Camera.SetupScale(music.transform);
        music.transform.position = new Vector2(musicX - Sprites.GetBounds(Sprites.music).x *S_Camera.scale / 2f, iconY - Sprites.GetBounds(Sprites.music).x *S_Camera.scale / 2f);
        music.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(music, Util.LayerName.UI, 50);


        //bottom info
        S_Button myTwitter = S_Button.CreateButton(Sprites.twitter);

        S_Camera.SetupScale(myTwitter.transform);
        myTwitter.transform.position = new Vector2(codeX - Sprites.GetBounds(Sprites.twitter).x *S_Camera.scale / 2f, twitterY - Sprites.GetBounds(Sprites.twitter).y *S_Camera.scale / 2f);
        myTwitter.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(myTwitter.gameObject, Util.LayerName.UI, 50);
        myTwitter.SetDownAction(() => Application.OpenURL("https://twitter.com/ColourTann"));

        S_Button website = S_Button.CreateButton(Sprites.website);

        S_Camera.SetupScale(website.transform);
        website.transform.position = new Vector2(musicX - Sprites.GetBounds(Sprites.website).x *S_Camera.scale / 2f, twitterY - Sprites.GetBounds(Sprites.website).x *S_Camera.scale / 2f);
        website.transform.SetParent(pauseScreen.transform, false);
        Util.SetLayer(website.gameObject, Util.LayerName.UI, 50);
        website.SetDownAction(() => Application.OpenURL("http://chriszabriskie.com/"));

        return(pauseScreen);
    }