Example #1
0
 protected void Setup(string name)
 {
     positionSetter   = new GameObject(name);
     transform.parent = positionSetter.transform;
     S_Camera.SetupScale(transform);
     transform.position = new Vector3(7.5f * S_Camera.scale, 7.5f * S_Camera.scale, 0);
 }
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
    internal void AddPickup()
    {
        GameObject pickup = (GameObject)(Instantiate(Resources.Load("prefabs/pickup")));

        content     = pickup.GetComponent <S_Pickup>();
        pickup.name = "pickup";
        S_Camera.SetupScale(pickup.transform);
        pickup.transform.position = transform.position;
        pickup.transform.parent   = transform;
    }
Example #4
0
    void Setup(int x, int y)
    {
        transform.position = new Vector2(x, y);
        gameObject.SetActive(true);
        speed = Random.Range(MAX_SPEED / 3, MAX_SPEED);

        dx = Random.Range(-speed, speed);
        dy = Mathf.Sqrt((speed * speed) - (dx * dx));
        if (Random.Range(0, 1f) > .5)
        {
            dy = -dy;
        }
        initialTime = Random.Range(0, MAX_TIME);
        timeLeft    = initialTime;
        S_Camera.SetupScale(transform);
    }
Example #5
0
    public void AddTutorial(TutorialType type, bool initial)
    {
        if (initial)
        {
            this.currentTutorial = type;
        }
        if (tutorialAnimation != null)
        {
            GameObject.Destroy(tutorialAnimation);
        }

        if (!Game.KEYBOARD)
        {
            abilityPanel.Flash(type == TutorialType.Ability);
            if (type == TutorialType.Ability)
            {
                return;
            }
        }

        Sprite[] sprites = null;
        switch (type)
        {
        case TutorialType.Move: sprites = Game.KEYBOARD ? Sprites.tutorial_0_keyboard : Sprites.tutorial_0_touch; break;

        case TutorialType.Ability: sprites = Game.KEYBOARD ? Sprites.tutorial_1_keyboard : Sprites.tutorial_1_touch; break;
        }
        int x = (int)(mapObject.transform.position.x + gridWidth / 2 - Sprites.GetBounds(sprites[0]).x / 2 * S_Camera.scale);

        if (type == TutorialType.Ability)
        {
            x = (int)(abilityPanel.gameObject.transform.position.x + Sprites.GetBounds(Sprites.ability_border).x *S_Camera.scale / 2 - Sprites.GetBounds(sprites[0]).x / 2 * S_Camera.scale);
        }
        int y = (int)(Screen.height / 2 + gridHeight / 2 + (Screen.height - gridHeight) / 4 - Sprites.GetBounds(sprites[0]).y / 2 * S_Camera.scale);

        if (type == TutorialType.Ability)
        {
            y = (int)(Screen.height / 2 - gridHeight / 2 - (Screen.height - gridHeight) / 4 - Sprites.GetBounds(sprites[0]).y / 2 * S_Camera.scale) + 20 * S_Camera.scale;
        }
        tutorialAnimation = S_Animation.CreateAnimation(sprites, .45f, x, y);
        Util.SetLayer(tutorialAnimation, Util.LayerName.UI, 0);
        S_Camera.SetupScale(tutorialAnimation.transform);
        tutorialAnimation.transform.SetParent(slider.transform, false);
        Util.SetZ(tutorialAnimation.gameObject, Util.ZLayer.Gameplay);
    }
Example #6
0
 // Update is called once per frame
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag.Equals("Player"))
     {
         InpList = new List <byte>(other.GetComponent <S_PlayerMovement>().InputList);
         other.GetComponent <S_PlayerMovement>().GetInput   = false;
         other.GetComponent <S_PlayerMovement>().ReplayMode = false;
         S_Camera CamScrRef = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <S_Camera>();
         CamScrRef.ResetCamera(gameObject.transform.position);
         UIScript.endlevel = true;
         UIScript.running  = false;
         Done  = true;
         ALock = Input.GetKey(KeyCode.A);
         SLock = Input.GetKey(KeyCode.S);
         DLock = Input.GetKey(KeyCode.D);
         int time;
         time = UIScript.time;
         if (PlayerPrefs.GetInt("LevelTime" + Application.loadedLevel) == -1 || PlayerPrefs.GetInt("LevelTime" + Application.loadedLevel) > time)
         {
             PlayerPrefs.SetInt("LevelTime" + Application.loadedLevel, time);
         }
     }
 }
Example #7
0
    public Game()
    {
        levelNumber = PlayerPrefs.GetInt("level", 0);
        GameObject background = Primitives.CreateRectangle(Screen.width, Screen.height, Colours.DARK);

        background.name = "backdrop";
        background.transform.SetParent(GetMisc("UI").transform, false);

        int gap = 5 * S_Camera.scale;

        mysteryButton = S_Button.CreateButton(Sprites.outline);
        S_Camera.SetupScale(mysteryButton.transform);
        mysteryButton.transform.position = new Vector2(gap, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y *S_Camera.scale);
        mysteryButton.SetDownAction(() => { MysteryButton(); });
        mysteryButton.name = "mystery";
        mysteryButton.transform.SetParent(GetMisc("UI").transform, false);
        Util.SetZ(mysteryButton.gameObject, Util.ZLayer.Buttons);

        S_Button optionsButton = S_Button.CreateButton(Sprites.options);

        S_Camera.SetupScale(optionsButton.transform);
        optionsButton.transform.position = new Vector2(gap * 2 + Sprites.GetBounds(Sprites.options).x *S_Camera.scale, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y *S_Camera.scale);
        optionsButton.SetDownAction(() => { PauseButton(); });
        optionsButton.name = "options_button";
        optionsButton.transform.SetParent(GetMisc("UI").transform, false);
        Util.SetZ(optionsButton.gameObject, Util.ZLayer.Buttons);

        S_Button restartButton = S_Button.CreateButton(Sprites.restart);

        S_Camera.SetupScale(restartButton.transform);
        restartButton.transform.position = new Vector2(gap * 3 + Sprites.GetBounds(Sprites.options).x *S_Camera.scale * 2, Screen.height - 5 * S_Camera.scale - Sprites.GetBounds(Sprites.restart).y *S_Camera.scale);
        restartButton.SetDownAction(() => { RestartButton(); });
        restartButton.name = "restart_button";
        restartButton.transform.SetParent(GetMisc("UI").transform, false);
        Util.SetZ(restartButton.gameObject, Util.ZLayer.Buttons);
    }
Example #8
0
 public T_Camera(S_Camera myState) : base(myState)
 {
 }
Example #9
0
 public T_DelayEvent(S_Camera state) : base(state)
 {
 }
Example #10
0
 public T_LevelChange(S_Camera state) : base(state)
 {
 }
Example #11
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 #12
0
 void Awake()
 {
     S_Camera.SetupScale(transform);
     spr_renderer        = GetComponent <SpriteRenderer>();
     spr_renderer.sprite = Sprites.tile;
 }
Example #13
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);
    }