본문 바로가기
Programing/C#

c# 벽충돌 감지,반사

by 고니피즈 2017. 2. 16.
반응형

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace WindowsFormsApplication15

{

    public partial class Form1 : Form

    {

        int dx=10;

        int dy=10;

        bool rm;

        bool bm;

        public Form1()

        {

            InitializeComponent();

        }


        private void timer1_Tick(object sender, EventArgs e)

        {

            radioButton1.Left += dx;

            radioButton1.Top += dy;

           

            if (radioButton1.Top < ClientRectangle.Top   )

            {

                bm = true;

            }

            else if (radioButton1.Top > ClientRectangle.Height)

            {

                bm = false;



            }

            else if (radioButton1.Left > ClientRectangle.Width)

            {

                rm = false;


            }

            else if (radioButton1.Left < ClientRectangle.Left)

            {

                rm = true;

            }

            

            if (rm)

            {

                dx = 10;

            }

            else {

                dx = -10;

            }




            if (bm)

            {

                dy = 10;

            }

            else

            {

                dy = -10;

            }

        }

    }

}


반응형