Tråd bedømmelse:
  • 0 Stemmer - 0 Gennemsnit
  • 1
  • 2
  • 3
  • 4
  • 5
Simpelt program med point tæller med kollesion
15-11-2017, 21:33
#1
Simpelt program med point tæller med kollesion
Hej Shellsec, 

Jeg skal prøve at skrive et simpelt program, hvor programmet skal smide random pictureboxe ned, når man enten har "fanget" den picturebox som er droppet ned eller hvis man ikke når og fange den og den timeout'er. 

Jeg kan ikke få min point-tæller til kun at tælle point, samt hvordan jeg få den til at smide random pictureboxe ned, når pictureboxen enten er blevet fanget eller timeout'et. 

En som kan hjælpe mig?

Min kode ser således ud: 

namespace Animation
{
    public partial class Form1 : Form
    {
        Point p1 = new Point();
        Point p2 = new Point();
        int bredde;
        int højde;
        int score;
        public Form1()
        {
            InitializeComponent();
            p1.X = pictureBox1.Location.X;
            p1.Y = pictureBox1.Location.Y;
            p2.X = pictureBox2.Location.X;
            p2.Y = pictureBox2.Location.Y;
            højde = ClientSize.Height;
            bredde = ClientSize.Width;
        }
        Boolean max = true;
        void kollesion()
        {
           
            if (pictureBox1.Bounds.IntersectsWith(pictureBox2.Bounds))
            {
                score++;
                label1.Text = Convert.ToString(score);
                max = true;
            }
           
        }
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.W && p1.Y > 0)
                p1.Y -= 3;
               
            if (e.KeyData == Keys.D && p1.X + pictureBox1.Width < bredde)
                p1.X +=3;
               
            if (e.KeyData == Keys.A && p1.X > 0)
                p1.X -=3;
               
            if (e.KeyData == Keys.S && p1.Y + pictureBox1.Height < højde)
                p1.Y +=3;
            pictureBox1.Location = p1;
           
            if (e.KeyData == Keys.W && p2.Y > 0)
               
            if (e.KeyData == Keys.D && p2.X + pictureBox2.Width < bredde)
               
            if (e.KeyData == Keys.A && p2.X > 0)
               
            if (e.KeyData == Keys.S && p2.Y + pictureBox2.Height < højde)
           
            pictureBox2.Location = p2;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            kollesion();
            p2.Y +=5;
            pictureBox2.Location = p2;
          
           
        }
        private void buttonStart_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }
        private void buttonStop_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }
    }
}
Find alle beskeder fra denne bruger
Citer denne besked i et svar
« Ældre | Nyere »




User(s) browsing this thread: 1 Gæst(er)