예제 #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (rightArrowDown == true && x < Width - 50)
            {
                x = x + 7;
            }
            else if (leftArrowDown == true && x > 0)
            {
                x = x - 7;
            }
            else if (upArrowDown == true && y > 500)
            {
                y = y - 7;
            }
            else if (downArrowDown == true && y < Height - 80)
            {
                y = y + 7;
            }
            else if (x < 10)
            {
                timer1.Enabled = false;
                Thread.Sleep(1000);

                Form f = this.FindForm();
                f.Controls.Remove(this);

                ExitScreen es = new ExitScreen();
                f.Controls.Add(es);

                return;
            }

            //check for collisions
            Rectangle characterRec = new Rectangle(x, y, 80, 80);
            Rectangle ball1Rec     = new Rectangle(198, 702, 52, 46);
            Rectangle ball2Rec     = new Rectangle(506, 726, 50, 46);
            Rectangle ball3Rec     = new Rectangle(836, 702, 50, 46);
            Rectangle ball4Rec     = new Rectangle(350, 585, 52, 46);
            Rectangle ball5Rec     = new Rectangle(668, 585, 52, 46);
            Rectangle ball6Rec     = new Rectangle(198, 541, 52, 46);
            Rectangle ball7Rec     = new Rectangle(1008, 541, 52, 46);
            Rectangle ball8Rec     = new Rectangle(636, 794, 52, 46);


            if (characterRec.IntersectsWith(ball1Rec) || characterRec.IntersectsWith(ball2Rec) || characterRec.IntersectsWith(ball3Rec) || characterRec.IntersectsWith(ball4Rec) || characterRec.IntersectsWith(ball5Rec) || characterRec.IntersectsWith(ball6Rec) || characterRec.IntersectsWith(ball7Rec) || characterRec.IntersectsWith(ball8Rec))
            {
                timer1.Enabled = false;
                Thread.Sleep(1500);

                Form f = this.FindForm();
                f.Controls.Remove(this);

                ExitScreen es = new ExitScreen();
                f.Controls.Add(es);

                return;
            }

            Refresh();
        }
예제 #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (rightArrowDown == true && drawX < Width)
            {
                drawX = drawX + 3;
            }
            else if (leftArrowDown == true && drawX > 0)
            {
                drawX = drawX - 3;
            }
            else if (upArrowDown == true && drawY > 0)
            {
                drawY = drawY - 3;
            }
            else if (downArrowDown == true && drawY < Height)
            {
                drawY = drawY + 5;
            }
            else if (drawX > Width - 21)
            {
                timer1.Enabled = false;
                Thread.Sleep(2000);

                Form f = this.FindForm();
                f.Controls.Remove(this);

                ExitScreen es = new ExitScreen();
                f.Controls.Add(es);

                return;
            }

            //monster mouvement

            if (drawX > monsterX)
            {
                monsterX++;
            }
            if (drawX < monsterX)
            {
                monsterX--;
            }
            if (drawY > monsterY)
            {
                monsterY++;
            }
            if (drawY < monsterY)
            {
                monsterY--;
            }

            //collisions checks and other processing

            Rectangle monsterRec = new Rectangle(monsterX, monsterY, 40, 40);

            Rectangle characterRec = new Rectangle(drawX, drawY, 40, 40);

            for (int i = 0; i < monstersX.Count; i++)
            {
                //   Rectangle monRec = new Rectangle(monstersX[i], monstersY[i], );
            }

            if (monsterRec.IntersectsWith(characterRec))
            {
                SoundPlayer player = new SoundPlayer(Properties.Resources.Beep);
                player.Play();

                timer1.Enabled = false;
                Thread.Sleep(2000);

                Form f = this.FindForm();
                f.Controls.Remove(this);

                ExitScreen es = new ExitScreen();
                f.Controls.Add(es);

                return;
            }

            Refresh();
        }