728x90
반응형

초보 독학 코딩러입니다. 제가 생각한 방법보다 더 좋은 방법이 있으시다면, 알려주시기 바랍니다. 

 

 

 

 

 

 

 

안녕하세요~ 오늘은 Bar를 생성하여 올라갈때 어느 지점을 지나면 이 바가 또 생성되게 만드는 방법입니다. 

 

 

 

1. 미리 준비하셔야 할 것은, nextBar존을 만드는 것입니다. 어느 지점을 통과하였을때 Bar를 생성시키고 싶은 부분에 옵젝트를 만듭니다. 

 

 

이런식으로 만들어 주십니다. 

 

2. 그리고 저는 Bar를 두 개 사이에 score존을 만들어 놓고 그 지점을 지나면 점수가 올라가는 방식으로 코딩을 짰는데요.  저는 충돌체크시 인식할 것을 socre존으로 설정을 해 놓았습니다. 

 

socre Zone

 

 

3. 그리고 nextBar 에 넣은 코딩을 아래와 같이 짜줍니다. 

score는 tag이름으로 넣어주고 Nextbar에 관해서는 지난주에 올린 것을 참고해 주세요. 

public class nextbar : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "score")
        {
            FindObjectOfType<Game>().Nextbar();
            Debug.Log("next!");
        }
    }
}

 

이렇게 하고, 주의사항이 있다면, 

 

초록색 사각박스안에 충돌체크로 인식을 시켰는데요. 아래에서 위로 올라가고 마지막 맨위 박스를 지나칠때도 충돌로 인식을 하더라구요. 그래서 화면을 나가면 Bar가 사라지게끔 코딩을 해 놓았습니다. 

 

따로 Bar 에 관한 코딩을 짜준곳에 이 아래를 추가 해 주었습니다. 

y >1일때 이제 위로 올라가 화면에 보이지 않으면 삭제 

반대로 아래로 내려간걸 삭제 시키고 싶을땐 y<0 입니다! 

 void destroybar()
    {
        Vector3 viewPos = Camera.main.WorldToViewportPoint(transform.position);

        if (viewPos.y > 1)
        {
            Destroy(this.gameObject);
           
        }
           
    }

 

안드로이드 앱 게임 추천 _ DownDown :: 잡동구리 (tistory.com)

 

안드로이드 앱 게임 추천 _ DownDown

안녕하세요~ 이번에 게임 앱을 하나더 출시를 하여서 여기에 리뷰를 남겨보아요! 이번에 출시한 게임 앱 이름은 DownDown 유니티로 만든 게임이구요. 이렇게 귀여운 귀신 아이콘이 나와서 아래로

tnqls6375.tistory.com

 

 

반응형
728x90
반응형

 

코딩 초보가 한 코딩이기에 더 좋은 방법이나 잘못된 방법이 있으시면 알려주시기 바랍니다!

 

 

 

 


우선, 올라오는 Bar에 위로 올라가는 속도를 걸어놓은 상태입니다. 

또한, Bar를 따로 만들어 놓은 상태이기도 합니다. 

 

위에와 같이 구멍이 제 각기 다른 Bar들을 넣어 놓았구요

여기서 주의해야 할 점은, Resources에서 barPre라는 폴더에 넣어놓은것을 기억해야 합니다.

아래 코딩시 이름을 잘못 입력하면 안됩니다. 

 

 

    int randomBar;

void Start()
    { randomBar = 0; 
    Nextbar(); }
    
     public void Nextbar()
    {
           
        GameObject barsobj = Instantiate(Resources.Load(GetRandomBar(), typeof(GameObject)), new Vector2(0f, 2f), Quaternion.identity) as GameObject;
            bars.Add(barsobj);

          

        
    }
    
    
    string GetRandomBar()
    {
       

        randomBar = GetControlledRandom();


        string randomBarName = "barPre/bar_1";

        switch (randomBar)
        {

            case 1:
                randomBarName = "barPre/bar_2";
                break;
            case 2:
                randomBarName = "barPre/bar_3";
                break;
            case 3:
                randomBarName = "barPre/bar_4";
                break;
            case 4:
                randomBarName = "barPre/bar_5";
                break;



        }

        return randomBarName;

        int GetControlledRandom()
        {
            List<int> possibleChoices = new List<int> {
            1, 2, 3,4,5
        };

            // Removes what was spawned before from the possible choices.
            possibleChoices.Remove(randomBar);

            return possibleChoices[Random.Range(0, possibleChoices.Count)];
        }

    }

아래에 GetControllRandom()이 여러개가 연속으로 똑같은게 겹치지 않게 해주는 코딩이며

그 위에 Case로 시작하는 부분이 제가 따로 저장해놓은 Bar들 입니다. 

 

 

이렇게 해놓고, 어느 시점에서 Nextbar를 연결 시켜놓으면 계속해서 Bar가 나오게 됩니다 

 

이 부분은 다음에 다루도록 하겠습니다~

 

다운다운 - Google Play 앱

 

DownDown - Google Play 앱

불을 피해서 아래로 내려가자 - 불을 피해서 아래로 하나씩 내려가면 +10 포인트 - 내려오는 과일 아이템을 먹으면 +30포인트 - 레벨이 올라갈수록 빨라져 긴장감 업!

play.google.com

 

반응형
728x90
반응형

 

독학하는 초보의 코딩입니다.

저는 이렇게 코딩을 하였지만 더 좋은 방법이 있으시다면 언제든지 댓글로 알려주세요~

 

 

 

 

 

 

안녕하세요 오늘은 코딩을 최고점수 그리고 2등과 3등의 점수를 나타내는 법을 알려드리려 합니다. 

 

그럼 시작해 볼까용??

 


우선, 처음으로 스코어가 메인 Scenes에 따로 있다는 가정하에 코딩해 보도록 하겠습니다. 

 

1. 게임을 하는  Scenes의 코딩에 입력할 코드입니다. 

여기서 전 게임 오버가 될 시에  그때의 스코어와 최고 스코어만 나오게 코딩해 논 것입니다. 

 

current Score 와 last score 는 내가 지금 게임을 한 스코어

 

startinghighscore = 최고 스코어

startinghighscore2 = 2등 스코어

startinghighscore3 = 3등 스코어

 

mino는 캐릭터 이름입니다. 

캐릭터가 사라질시에 게임오버가 되어 updatehighscore가 작동하게 해 논것입니다. 

 

아래는 참고로 텍스트 넣어준 것입니다, 그냥 참고 해 주세요

  currentScore = 0;
 
 private int startinghighscore;
    private int startinghighscore2;
    private int startinghighscore3;


    public Text highscoreText;
   

    public Text lastScore;


  void Start()
    {
      startinghighscore = PlayerPrefs.GetInt("highscore");
        startinghighscore2 = PlayerPrefs.GetInt("highscore2");
        startinghighscore3 = PlayerPrefs.GetInt("highscore3");  }
        
        
         void Update()
    { savesocre();
        }
        
        
           public void UpdateHighScore()
    {
        if (currentScore > startinghighscore)
        {
            PlayerPrefs.SetInt("highscore3", startinghighscore2);
            PlayerPrefs.SetInt("highscore2", startinghighscore);
            PlayerPrefs.SetInt("highscore", currentScore);

        }
        else if (currentScore > startinghighscore2)
        {
            PlayerPrefs.SetInt("highscore3", startinghighscore2);
            PlayerPrefs.SetInt("highscore2", currentScore);
        }
        else if (currentScore > startinghighscore3)
        {
            PlayerPrefs.SetInt("highscore3", currentScore);
        }

        PlayerPrefs.SetInt("lastscore", currentScore);


    }
    
      public void Gameover()
    {
       
        if (mino == null)
        { UpdateHighScore();}
        
        }
    
     void savesocre()
    {
       

        if (highscoreText != null)
            highscoreText.text = PlayerPrefs.GetInt("highscore").ToString();

      

        if (lastScore != null)
            lastScore.text = PlayerPrefs.GetInt("lastscore").ToString();
    }
      

 

 

 

이제 이걸 가지고 메인의 스코어 랭킹으로 가줍니다. 

 

 

 public Text highscoreText;
    public Text highscoreText2;
    public Text highscoreText3;

    public Text lastScore;


  void Start()
    {if (highscoreText != null)
            highscoreText.text = PlayerPrefs.GetInt("highscore").ToString();

        if (highscoreText2 != null)
            highscoreText2.text = PlayerPrefs.GetInt("highscore2").ToString();

        if (highscoreText3 != null)
            highscoreText3.text = PlayerPrefs.GetInt("highscore3").ToString();

        if (lastScore != null)
            lastScore.text = PlayerPrefs.GetInt("lastscore").ToString();
    }

 

이렇게 코딩을 해 주면 됩니다. 

lastscore는 비교 대상은 있어야 하기에 전에 게임화면에서 코딩했던 그 이름 그대로 적어주셔야 합니다!

 

 "   " 안에 있는 말은 꼭 그대로 적어주세요~~~

 

참고로 이렇게 코딩을 한 후에, 

빌드를 해도 스코어에 저장된 경우가 있습니다. 

 

그럴때는 코딩한 곳

void Start()
    { PlayerPrefs.SetInt("highscore", 0);
        PlayerPrefs.SetInt("highscore2", 0);
        PlayerPrefs.SetInt("highscore3", 0);*/ }

이렇게 다 넣어주세요!!! 

 

 

 

 

다운다운 - Google Play 앱

 

DownDown - Google Play 앱

불을 피해서 아래로 내려가자 - 불을 피해서 아래로 하나씩 내려가면 +10 포인트 - 내려오는 과일 아이템을 먹으면 +30포인트 - 레벨이 올라갈수록 빨라져 긴장감 업!

play.google.com

 

 

반응형
728x90
반응형

안녕하세요~ 초보 코딩러 입니당~

 

오늘은 퀴즈앱에서 사용되는 간단한 애니메이션 효과를 넣어볼까 합니다. 

 


우선 처음에는 이 모양대로 layout을 만들어 줍니다!

 

여기서 

저는 색은 따로 Colors 에서 지정을 하여 colorPrimary , colorPrimaryDark , colorAccent 를 색을 지정해 준 색깔이고

drawble에서 끝을 둥굴게 하는 원형을 따로 만들어 준 상태입니다. 

 

drawble에서 둥굴게 하는 것이 궁금하신 분들은 클릭! 

 


<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@color/colorPrimary"
    android:orientation="vertical">




            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="0dp"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimary"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="퀴즈퀴즈퀴즈"
                    android:gravity="center"
                    android:textSize="16sp"
                    android:textStyle="bold"
                    android:textColor="@android:color/white"/>

            </androidx.appcompat.widget.Toolbar>

            <LinearLayout
                android:id="@+id/linearLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorPrimary"
                android:orientation="vertical"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/toolbar">

                <TextView
                    android:id="@+id/question"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="8dp"
                    android:background="@drawable/category_background2"
                    android:padding="16dp"
                    android:text="TextView"
                    android:textSize="30dp"
                    android:textColor="@android:color/black" />

                <TextView
                    android:id="@+id/no_indicator"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="16dp"
                    android:text="5/10"
                    android:textColor="@android:color/white"
                    android:textSize="16sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/options_container"
                android:layout_width="409dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="120dp"
                android:background="@drawable/category_background2"
                android:orientation="vertical"
                android:padding="16dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/linearLayout">

                <Button
                    android:id="@+id/button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="8dp"
                    android:background="@drawable/rounded_borders"
                    android:backgroundTint="#989898"
                    android:text="Button"
                    android:textColor="@android:color/black"/>

                <Button
                    android:id="@+id/button2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="8dp"
                    android:background="@drawable/rounded_borders"
                    android:backgroundTint="#989898"
                    android:text="Button"
                    android:textColor="@android:color/black"/>

                <Button
                    android:id="@+id/button3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="8dp"
                    android:background="@drawable/rounded_borders"
                    android:backgroundTint="#989898"
                    android:text="Button"
                    android:textColor="@android:color/black"/>

                <Button
                    android:id="@+id/button4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="8dp"
                    android:background="@drawable/rounded_borders"
                    android:backgroundTint="#989898"
                    android:text="Button"
                    android:textColor="@android:color/black"/>
            </LinearLayout>

            <Button
                android:id="@+id/next_btn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_margin="30dp"
                android:text="NEXT!!"
            
                android:textColor="@android:color/white"
                android:textSize="20dp"
                android:background="@drawable/rounded_corner"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/options_container" />



        </androidx.constraintlayout.widget.ConstraintLayout>

 

 


  

 

그 다음에 java로 가줍니다.  

ipublic class MainActivity extends AppCompatActivity {
    private TextView question,noIndicator;

    private LinearLayout optionsContainer;
    private Button nextBtn;
    private  int count;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        question = findViewById(R.id.question);
        noIndicator = findViewById(R.id.no_indicator);

        optionsContainer = findViewById(R.id.options_container);
        nextBtn = findViewById(R.id.next_btn);

        nextBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                count = 0;
                playAnim(question,0);
            }
        });
    }

    private void playAnim(final View view, final int  value){
         view.animate().alpha(value).scaleX(value).scaleY(value).setDuration(500).setStartDelay(100).setInterpolator(new DecelerateInterpolator())
                .setListener(new Animator.AnimatorListener() {

                    @Override
                    public void onAnimationStart(Animator animation) {
                        if (value ==0 && count <4){
                            playAnim(optionsContainer.getChildAt(count),0);
                            count ++;
                        }
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (value == 0){
                            playAnim(view,1);
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });

    }

}

 

 

이렇게 넣어주시면, 끄읕!

 

 

 

 

 

반응형
728x90
반응형

1. darwable - new - drawble Resource file을 새로 만들어 줍니다. 

 

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/transparent"/>
    <corners android:radius="250dp"/>
    <stroke android:color="@color/colorPrimary" android:width="5dp"> </stroke>
</shape>

색과 라운드 간격은 원하시는 것으로 해주세요. 

 

 

 

2. layout으로 가셔서 

 

android:background="@drawable/파일이름"

 

이렇게 넣어주세요. 

 

 

---------------------

 

 저는 버튼에 넣어서 만들어 보았습니다. 

 

                <Button
                    android:id="@+id/button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="8dp"
                    android:background="@drawable/rounded_borders"
                    android:backgroundTint="#989898"
                    android:text="Button"
                    android:textColor="@android:color/black"/>

 

그러면 

 

이렇게 선이 나오게 됩니다. 

반응형
728x90
반응형

안녕하세요~ 오늘은 drawble에서 라운드 코너를 만드는 방법을 설명 드릴까 합니다. 

 

 

 

간단한 방법이기에 쉽게 따라하실수 있으실 겁니다. 그럼 시~작

 


1. res - drawable에 새로운 drawable Resource File을 만들어 줍니다 

 

 

 

<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="100dp"/>
    <solid android:color="#E17B90"/>
</shape>

 

입력해 줍니다. radius와 color는 각자 원하시는 둥글기와 색을 선택하여 주세용~

 

 

2. 그리고 layout에서 원하는 곳에 

 android:background="@drawable/파일이름"

이렇게 파일 이름을 넣어주시면 됩니다!! 

반응형

+ Recent posts