예제 #1
0
    void Start()
    {
        //if (Application.platform == RuntimePlatform.WindowsPlayer)
        //{
        //    string temp_url = "file://"; /// www 를 쓰기 위해선 uri 경로 앞에 file:// 붙어야함

        //    string url = Application.dataPath + "/Resources/Saved_Drawing_Charoctor/" + this.name + ".png"; // 사진이 있는 경로
        //    www = new WWW(temp_url + url);
        //    Texture2D t = www.texture;
        //    Rect rect = new Rect(0, 0, t.width, t.height);
        //    GetComponent<SpriteRenderer>().sprite = Sprite.Create(t, rect, new Vector2(0.5f, 0.5f));
        //}
        //else
        //GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Saved_Drawing_Charoctor/" + this.name);
        //WWW www;

        //string temp_url = "file://"; /// www 를 쓰기 위해선 uri 경로 앞에 file:// 붙어야함
        //string url = Application.dataPath + "/Saved_Drawing_Charoctor/" + this.name + ".png"; // 사진이 있는 경로
        //www = new WWW(temp_url + url);
        //Texture2D t = www.texture;
        //Rect rect = new Rect(0, 0, t.width, t.height);
        //GetComponent<SpriteRenderer>().sprite = Sprite.Create(t, rect, new Vector2(0.5f, 0.5f));

        drawable = this;

        drawable_sprite  = this.GetComponent <SpriteRenderer>().sprite;
        drawable_texture = drawable_sprite.texture;

        DrawStack.Push(drawable_texture.GetPixels32());


        clean_colors_array = new Color[(int)drawable_sprite.rect.width * (int)drawable_sprite.rect.height]; //그리는 부분의 픽셀의 겟수가 배열 크기
        for (int x = 0; x < clean_colors_array.Length; x++)
        {
            clean_colors_array[x] = Reset_Color;
        }

        if (Reset_Canvas_On_Play) //캔버스 리셋
        {
            ResetCanvas();
        }
    }
예제 #2
0
        //How A Left MouseClick is Handled.
        private void MouseClicked()
        {
            //Code To CheckIf We ClickedOnAnEnemy.
            foreach (Enemies enem in EnemiesInGame)
            {
                if (enem.CheckIfClicked(MouseWorldRect))
                {
                    NullifyEverything();
                    EnemySelected = enem;
                    if (!(EnemySelected.Type.ToString().Equals("Composite")))
                    {
                        GetEnemyElement();
                    }
                    EnemySelected.spriteAnimation.Shader = shader;
                    return;
                }
            }

            //Check if the SpinButtonIsClicked,
            if (spinButton.CheckIfClicked(MouseWorldRect))
            {
                SpinButtonClicked();
            }
            //If We are on the the Tower SelectionScreen.
            if (spinButton.isAnimation1)
            {
                //Check If any of the towers have been Clicked.
                foreach (Tower T in TowersInGame)
                {
                    if (T.CheckIfClicked(MouseWorldRect))
                    {
                        NullifyEverything();
                        CircleEffect = new DrawAble(new SpriteAnimation(CreateCircle((int)T.TowerRange)), T.Location, 0, 0);
                        Vector2 CricleEffectLocation = CircleEffect.Location;
                        CricleEffectLocation.X -= CircleEffect.spriteAnimation.CurrentAnimation.CurrentRect.Width / 2;
                        CricleEffectLocation.Y -= CircleEffect.spriteAnimation.CurrentAnimation.CurrentRect.Height / 2;
                        CricleEffectLocation.X += T.spriteAnimation.CurrentAnimation.CurrentRect.Width / 2;
                        CricleEffectLocation.Y += T.spriteAnimation.CurrentAnimation.CurrentRect.Height / 2;
                        CircleEffect.Location   = CricleEffectLocation;
                        CircleEffect.spriteAnimation.TintColor = Color.Red;
                        CurrentlySelected = T;
                        CurrentlySelected.spriteAnimation.Shader = shader;
                        CurrentlySelected.TurretAnim.Shader      = shader;
                        CreateSellButton();
                        DisplayNewButtons();
                        return;
                    }
                }
                //How To Handle A ButtonClick in TowerSection.
                foreach (Button b in ButtonsToDisplay)
                {
                    ButtonTower BT = b as ButtonTower; //We Know it is of the ButtonTower Kind.

                    if (b.CheckIfClicked(MouseWorldRect))
                    {
                        if (CurrentlySelected != null && CurrentlyClicked == null) //This Statement is True If We Want To update a tower.
                        {
                            Tower t = BT.Value;
                            if (CheckIfElementsRequirementMet(CurrentlySelected, t))
                            {
                                if (Gold >= BT.GoldToCreate)
                                {
                                    Game1.sound.playSound("OnTowerCreation");
                                    //if (r.Next(1, 9) < 4)
                                    //{
                                    //    Game1.sound.playSound("FoolishDecision");
                                    //}
                                    //else if (r.Next(1, 9) > 6)
                                    //{
                                    //    Game1.sound.playSound("SoYouThink");
                                    //}
                                    Gold -= BT.GoldToCreate;
                                    TowersInGame.Add(t.Copy(CurrentlySelected.Location, BT.GoldToCreate / 2));
                                    TowersInGame.Remove(CurrentlySelected);
                                    NullifyEverything();
                                    FlipFlopButtons();
                                }
                                else
                                {
                                    EffectsManager.NoGoldEffect();
                                }
                            }
                            else
                            {
                                EffectsManager.NotEnoughElements();
                            }
                        }
                        else // This Runs When We are making a base Tower
                        {
                            CurrentlyClicked = BT.Value;
                            TowerToDisplay   = CurrentlyClicked.Copy(BT.Location, BT.GoldToCreate / 2);
                        }
                        return;
                    }
                } // End Of Button Looping Code for Tower Panel.

                // This Runs When We have Clicked On a Button to Create a tower and we are not intersecting with the panel. It shows the red and green tower.
                if (CurrentlyClicked != null && !(PanelRec.Intersects(MouseScreenRect)))
                {
                    Vector2 TileAtClick = tilemap.GetCollTileAtPixel(new Vector2(MouseWorldRect.X, MouseWorldRect.Y));
                    if (tilemap.GetCollCellIndex(TileAtClick) == 1)
                    {
                        if (Gold >= DefaultTowerCost)
                        {
                            //This Code will Create A Default Tower if you have selected it.C:\Users\Arsinx\documents\visual studio 2010\Projects\EleTD\EleTD\EleTD\EffectsManager.cs
                            Gold -= DefaultTowerCost;
                            Game1.sound.playSound("OnTowerCreation");
                            //if (r.Next(1, 9) < 4)
                            //{
                            //    Game1.sound.playSound("FoolishDecision");
                            //}
                            //else if (r.Next(1, 9) > 6)
                            //{
                            //    Game1.sound.playSound("SoYouThink");
                            //}
                            TileAtClick *= 64;
                            TowersInGame.Add(CurrentlyClicked.Copy(TileAtClick, DefaultTowerCost));  // We are not Dividing the Tower Cost By 2 Because the basic tower has full Sell price.
                            tilemap.SetCollisionTile((int)TileAtClick.X, (int)TileAtClick.Y, 0);
                            CurrentlyClicked = null;
                            TowerToDisplay   = null;
                            return;
                        }
                        else
                        {
                            EffectsManager.NoGoldEffect();
                        }
                    }
                    else
                    {
                        EffectsManager.CantBuildEffect();
                        Game1.sound.playSound("CannotBuildTower");
                        return;
                    }
                } // End OF Selected Tower Display Code.

                //If We Click the Sell Button.
                if (CurrentlySelected != null)
                {
                    if (sellButton.CheckIfClicked(MouseWorldRect))
                    {
                        TowersInGame.Remove(sellButton.Value);
                        Game1.sound.playSound("OnTowerSell");
                        if (r.Next(1, 9) > 6)
                        {
                            Game1.sound.playSound("FoolishDecision");
                        }

                        EffectsManager.WritingEffect(sellButton.Value.CenterofSprite, sellButton.Value.SellPrice);
                        Gold += sellButton.Value.SellPrice;
                        NullifyEverything();
                        FlipFlopButtons();
                        return;
                    }
                } // End of Sell Code
            }
            else  //If Elements Screen is the main screen.
            {
                //How to handle elements if we are in the screen for Elements.
                foreach (Button b in ButtonsToDisplay)
                {
                    if (b.CheckIfClicked(MouseWorldRect))
                    {
                        ButtonElement BE = b as ButtonElement;
                        if (Materia > 0)
                        {
                            BoughtElementsList.Add(BE.Type);
                            Materia--;
                            return;
                        }
                        else
                        {
                            EffectsManager.NotEnoughMateria();
                        }
                    }
                }

                //TowerClick In Elements Section.
                foreach (Tower T in TowersInGame)
                {
                    if (T.CheckIfClicked(MouseWorldRect))
                    {
                        SpinButtonClicked();
                        CurrentlySelected = T;
                        CurrentlySelected.spriteAnimation.Shader = shader;
                        CurrentlySelected.TurretAnim.Shader      = shader;
                        CreateSellButton();
                        DisplayNewButtons();

                        return;
                    }
                }
            }
            NullifyEverything();
            FlipFlopButtons();
        }