Example #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (gameover)
            {
                return;
            }
            for (int i = 0; i < Bullets.Count; ++i)
            {
                Bullets[i]     = new Point(Bullets[i].X, Bullets[i].Y - 20);
                laser          = new PictureBox();
                laser.Location = new Point(Bullets[i].X, Bullets[i].Y);
            }

            while (Bullets.Count > 0 && Bullets[0].Y < 0)
            {
                Bullets.RemoveAt(0);
            }
            Refresh();


            if (pobr == Brushes.White && pobrpen == Pens.White)
            {
                pobr    = Brushes.Black;
                pobrpen = Pens.Black;
            }
            else
            {
                pobr    = Brushes.White;
                pobrpen = Pens.White;
            }
            Refresh();
            for (int i = 0; i < 10; i++)
            {
                labelArray[i].Location = new Point(labelArray[i].Location.X + dx[i], labelArray[i].Location.Y + dy[i]);
                asteroid[i].Location   = labelArray[i].Location;
                asteroid[i].SizeMode   = PictureBoxSizeMode.StretchImage;
                if (labelArray[i].Location.X > Width + 4 || labelArray[i].Location.Y > Height + 4)
                {
                    labelArray[i].Location = new Point(rnd.Next(0, 500), -5);
                    dx[i] = rnd.Next(1, 5);
                    dy[i] = rnd.Next(1, 5);

                    asteroid[i].Location = labelArray[i].Location;
                    asteroid[i].SizeMode = PictureBoxSizeMode.StretchImage;
                }

                for (int j = 0; j < 10; j++)
                {
                    image1 = new Rectangle(labelArray[i].Location.X, labelArray[i].Location.Y, 48, 55);
                    image2 = new Rectangle(labelArray[j].Location.X, labelArray[j].Location.Y, 48, 55);
                    image4 = new Rectangle(pb.Location.X, pb.Location.Y, pb.Width, pb.Height);

                    if (image1.IntersectsWith(image2) && i != j)

                    {
                        dx[i] *= -1;
                        dx[j] *= -1;
                        asteroid[i].Location = labelArray[i].Location;
                        asteroid[i].SizeMode = PictureBoxSizeMode.StretchImage;
                    }
                    if (image4.IntersectsWith(image1) || image4.IntersectsWith(image2))
                    {
                        gameover = true;
                        MessageBox.Show("Game Over");
                        break;
                    }
                    for (int q = 0; q < Bullets.Count; ++q)
                    {
                        image3 = new Rectangle(Bullets[q], new Size(20, 20));
                        if (image3.IntersectsWith(image1))
                        {
                            labelArray[i].Location = new Point(rnd.Next(0, 500), -5);
                            dx[i] = rnd.Next(1, 5);
                            dy[i] = rnd.Next(1, 5);
                        }
                        if (image3.IntersectsWith(image2))
                        {
                            labelArray[j].Location = new Point(rnd.Next(0, 500), -5);
                            dx[j] = rnd.Next(1, 5);
                            dy[j] = rnd.Next(1, 5);
                        }
                    }
                }
            }
        }
Example #2
0
        public bool FBInterect(Entity FireBall)
        {
            Rectangle fireball1 = new Rectangle(FireBall.posX, FireBall.posY, 5, 5);

            if (fireball1.IntersectsWith(wu1) || fireball1.IntersectsWith(wu2) || fireball1.IntersectsWith(wu3) ||
                fireball1.IntersectsWith(wu4) || fireball1.IntersectsWith(wu5) ||
                fireball1.IntersectsWith(wu6) || fireball1.IntersectsWith(wu7) || fireball1.IntersectsWith(wu8) ||
                fireball1.IntersectsWith(wu9) || fireball1.IntersectsWith(wu10) || fireball1.IntersectsWith(wu11) ||
                fireball1.IntersectsWith(wr1) || fireball1.IntersectsWith(wr2) || fireball1.IntersectsWith(wr3) ||
                fireball1.IntersectsWith(wr4) || fireball1.IntersectsWith(wr5) ||
                fireball1.IntersectsWith(wr6) || fireball1.IntersectsWith(wr7) || fireball1.IntersectsWith(wr8) ||
                fireball1.IntersectsWith(wr9) ||
                fireball1.IntersectsWith(wl1) || fireball1.IntersectsWith(wl2) || fireball1.IntersectsWith(wl3) ||
                fireball1.IntersectsWith(wl4) || fireball1.IntersectsWith(wl5) ||
                fireball1.IntersectsWith(wl6) || fireball1.IntersectsWith(wl7) || fireball1.IntersectsWith(wl8) ||
                fireball1.IntersectsWith(wl9) ||
                fireball1.IntersectsWith(wd1) || fireball1.IntersectsWith(wd2) || fireball1.IntersectsWith(wd3) ||
                fireball1.IntersectsWith(wd4) || fireball1.IntersectsWith(wd5) ||
                fireball1.IntersectsWith(wd6) || fireball1.IntersectsWith(wd7) || fireball1.IntersectsWith(wd8) ||
                fireball1.IntersectsWith(wd9) || fireball1.IntersectsWith(wd10) || fireball1.IntersectsWith(wd11) ||
                fireball1.IntersectsWith(wur1) || fireball1.IntersectsWith(wur2) || fireball1.IntersectsWith(wur3) ||
                fireball1.IntersectsWith(wur4) || fireball1.IntersectsWith(wur5) || fireball1.IntersectsWith(wur6) ||
                fireball1.IntersectsWith(wdr1) || fireball1.IntersectsWith(wdr2) || fireball1.IntersectsWith(wdr3) ||
                fireball1.IntersectsWith(wdr4) || fireball1.IntersectsWith(wdr5) ||
                fireball1.IntersectsWith(wdl1) || fireball1.IntersectsWith(wdl2) || fireball1.IntersectsWith(wdl3) ||
                fireball1.IntersectsWith(wdl4) || fireball1.IntersectsWith(wdl5) || fireball1.IntersectsWith(wdl6) ||
                fireball1.IntersectsWith(wul1) || fireball1.IntersectsWith(wul2) || fireball1.IntersectsWith(wul3) ||
                fireball1.IntersectsWith(wul4) || fireball1.IntersectsWith(wul5))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        public void Update(object sender, EventArgs e)
        {
            q = new Rectangle(new Point(player.posX - 16, player.posY), new Size(player.size, player.size));

            if (player.isMoving)
            {
                player.Move();
            }
            if (q.IntersectsWith(room1))
            {
                imp1.Move();
                Skelet1.Move();
            }

            if (q.IntersectsWith(room2))
            {
                Slime1.Move();
                Slime2.Move();
                Slime3.Move();
            }

            if (q.IntersectsWith(room3))
            {
                imp2.Move();
                Skelet2.Move();
                Skelet3.Move();
            }

            if (q.IntersectsWith(room4))
            {
                Skelet4.Move();
                Slime4.Move();
            }

            if (q.IntersectsWith(room5))
            {
                imp3.Move();
                imp4.Move();
            }

            if (q.IntersectsWith(room6))
            {
                Skelet5.Move();
                Skelet6.Move();
                Skelet7.Move();
            }

            if (q.IntersectsWith(room7))
            {
                imp5.Move();
                imp6.Move();
                imp7.Move();
            }

            if (q.IntersectsWith(room8))
            {
                imp8.Move();
                Skelet8.Move();
                Slime5.Move();
            }

            Invalidate();
        }
Example #4
0
        public void UpdateCollision(object sender, EventArgs e)
        {
            Col1 = !q.IntersectsWith(wu1) && !q.IntersectsWith(wu2) && !q.IntersectsWith(wu3) &&
                   !q.IntersectsWith(wu4) && !q.IntersectsWith(wu5) &&
                   !q.IntersectsWith(wu6) && !q.IntersectsWith(wu7) && !q.IntersectsWith(wu8) &&
                   !q.IntersectsWith(wu9) && !q.IntersectsWith(wu10) && !q.IntersectsWith(wu11) &&
                   !q.IntersectsWith(wl1) && !q.IntersectsWith(wl2) && !q.IntersectsWith(wl3) &&
                   !q.IntersectsWith(wl4) && !q.IntersectsWith(wl5) &&
                   !q.IntersectsWith(wl6) && !q.IntersectsWith(wl7) && !q.IntersectsWith(wl8) &&
                   !q.IntersectsWith(wl9) &&
                   !q.IntersectsWith(wr1) && !q.IntersectsWith(wr2) && !q.IntersectsWith(wr3) &&
                   !q.IntersectsWith(wr4) &&
                   !q.IntersectsWith(wr5) && !q.IntersectsWith(wr6) && !q.IntersectsWith(wr7) &&
                   !q.IntersectsWith(wr8) && !q.IntersectsWith(wr9) &&
                   !q.IntersectsWith(wdl1) && !q.IntersectsWith(wdl2) && !q.IntersectsWith(wdl3) &&
                   !q.IntersectsWith(wdl4) && !q.IntersectsWith(wdl5) && !q.IntersectsWith(wdl6) &&
                   !q.IntersectsWith(wdr1) && !q.IntersectsWith(wdr2) && !q.IntersectsWith(wdr3) &&
                   !q.IntersectsWith(wdr4) && !q.IntersectsWith(wdr5);

            Col2 = !q.IntersectsWith(wd1) && !q.IntersectsWith(wd2) && !q.IntersectsWith(wd3) &&
                   !q.IntersectsWith(wd4) && !q.IntersectsWith(wd5) &&
                   !q.IntersectsWith(wd6) && !q.IntersectsWith(wd7) && !q.IntersectsWith(wd8) &&
                   !q.IntersectsWith(wd9) && !q.IntersectsWith(wd10) && !q.IntersectsWith(wd11) &&
                   !q.IntersectsWith(wl1) && !q.IntersectsWith(wl2) && !q.IntersectsWith(wl3) &&
                   !q.IntersectsWith(wl4) && !q.IntersectsWith(wl5) &&
                   !q.IntersectsWith(wl6) && !q.IntersectsWith(wl7) && !q.IntersectsWith(wl8) &&
                   !q.IntersectsWith(wl9) &&
                   !q.IntersectsWith(wr1) && !q.IntersectsWith(wr2) && !q.IntersectsWith(wr3) &&
                   !q.IntersectsWith(wr4) &&
                   !q.IntersectsWith(wr5) && !q.IntersectsWith(wr6) && !q.IntersectsWith(wr7) &&
                   !q.IntersectsWith(wr8) && !q.IntersectsWith(wr9) &&
                   !q.IntersectsWith(wul1) && !q.IntersectsWith(wul2) && !q.IntersectsWith(wul3) &&
                   !q.IntersectsWith(wul4) && !q.IntersectsWith(wul5) &&
                   !q.IntersectsWith(wur1) && !q.IntersectsWith(wur2) && !q.IntersectsWith(wur3) &&
                   !q.IntersectsWith(wur4) && !q.IntersectsWith(wur5) && !q.IntersectsWith(wur6);

            Col3 = !q.IntersectsWith(wu1) && !q.IntersectsWith(wu2) && !q.IntersectsWith(wu3) &&
                   !q.IntersectsWith(wu4) && !q.IntersectsWith(wu5) &&
                   !q.IntersectsWith(wu6) && !q.IntersectsWith(wu7) && !q.IntersectsWith(wu8) &&
                   !q.IntersectsWith(wu9) && !q.IntersectsWith(wu10) && !q.IntersectsWith(wu11) &&
                   !q.IntersectsWith(wd1) && !q.IntersectsWith(wd2) && !q.IntersectsWith(wd3) &&
                   !q.IntersectsWith(wd4) && !q.IntersectsWith(wd5) &&
                   !q.IntersectsWith(wd6) && !q.IntersectsWith(wd7) && !q.IntersectsWith(wd8) &&
                   !q.IntersectsWith(wd9) && !q.IntersectsWith(wd10) && !q.IntersectsWith(wd11) &&
                   !q.IntersectsWith(wl1) && !q.IntersectsWith(wl2) && !q.IntersectsWith(wl3) &&
                   !q.IntersectsWith(wl4) && !q.IntersectsWith(wl5) &&
                   !q.IntersectsWith(wl6) && !q.IntersectsWith(wl7) && !q.IntersectsWith(wl8) &&
                   !q.IntersectsWith(wl9) &&
                   !q.IntersectsWith(wdr1) && !q.IntersectsWith(wdr2) && !q.IntersectsWith(wdr3) &&
                   !q.IntersectsWith(wdr4) && !q.IntersectsWith(wdr5) &&
                   !q.IntersectsWith(wur1) && !q.IntersectsWith(wur2) && !q.IntersectsWith(wur3) &&
                   !q.IntersectsWith(wur4) && !q.IntersectsWith(wur5) && !q.IntersectsWith(wur6);

            Col4 = !q.IntersectsWith(wu1) && !q.IntersectsWith(wu2) && !q.IntersectsWith(wu3) &&
                   !q.IntersectsWith(wu4) && !q.IntersectsWith(wu5) &&
                   !q.IntersectsWith(wu6) && !q.IntersectsWith(wu7) && !q.IntersectsWith(wu8) &&
                   !q.IntersectsWith(wu9) && !q.IntersectsWith(wu10) && !q.IntersectsWith(wu11) &&
                   !q.IntersectsWith(wd1) && !q.IntersectsWith(wd2) && !q.IntersectsWith(wd3) &&
                   !q.IntersectsWith(wd4) && !q.IntersectsWith(wd5) &&
                   !q.IntersectsWith(wd6) && !q.IntersectsWith(wd7) && !q.IntersectsWith(wd8) &&
                   !q.IntersectsWith(wd9) && !q.IntersectsWith(wd10) && !q.IntersectsWith(wd11) &&
                   !q.IntersectsWith(wr1) && !q.IntersectsWith(wr2) && !q.IntersectsWith(wr3) &&
                   !q.IntersectsWith(wr4) &&
                   !q.IntersectsWith(wr5) && !q.IntersectsWith(wr6) && !q.IntersectsWith(wr7) &&
                   !q.IntersectsWith(wr8) && !q.IntersectsWith(wr9) &&
                   !q.IntersectsWith(wdl1) && !q.IntersectsWith(wdl2) && !q.IntersectsWith(wdl3) &&
                   !q.IntersectsWith(wdl4) && !q.IntersectsWith(wdl5) && !q.IntersectsWith(wdl6) &&
                   !q.IntersectsWith(wul1) && !q.IntersectsWith(wul2) && !q.IntersectsWith(wul3) &&
                   !q.IntersectsWith(wul4) && !q.IntersectsWith(wul5);

            if (q.IntersectsWith(wu1) && q.IntersectsWith(wu2) && q.IntersectsWith(wu3) && q.IntersectsWith(wu4) &&
                q.IntersectsWith(wu5) &&
                q.IntersectsWith(wu6) && q.IntersectsWith(wu7) && q.IntersectsWith(wu8) && q.IntersectsWith(wu9) &&
                q.IntersectsWith(wu10) && q.IntersectsWith(wu11) &&
                q.IntersectsWith(wl1) && q.IntersectsWith(wl2) && q.IntersectsWith(wl3) && q.IntersectsWith(wl4) &&
                q.IntersectsWith(wl5) &&
                q.IntersectsWith(wl6) && q.IntersectsWith(wl7) && q.IntersectsWith(wl8) && q.IntersectsWith(wl9))
            {
                player.isMoving = true;
                player.dirX     = 8;
                player.dirY     = 8;
            }

            if (q.IntersectsWith(wd1) && q.IntersectsWith(wd2) && q.IntersectsWith(wd3) && q.IntersectsWith(wd4) &&
                q.IntersectsWith(wd5) &&
                q.IntersectsWith(wd6) && q.IntersectsWith(wd7) && q.IntersectsWith(wd8) && q.IntersectsWith(wd9) &&
                q.IntersectsWith(wd10) && q.IntersectsWith(wd11) &&
                q.IntersectsWith(wr1) && q.IntersectsWith(wr2) && q.IntersectsWith(wr3) && q.IntersectsWith(wr4) &&
                q.IntersectsWith(wr5) && q.IntersectsWith(wr6) && q.IntersectsWith(wr7) && q.IntersectsWith(wr8) &&
                q.IntersectsWith(wr9))
            {
                player.isMoving = true;
                player.dirX     = -8;
                player.dirY     = -8;
            }

            if (q.IntersectsWith(wu1) && q.IntersectsWith(wu2) && q.IntersectsWith(wu3) && q.IntersectsWith(wu4) &&
                q.IntersectsWith(wu5) &&
                q.IntersectsWith(wu6) && q.IntersectsWith(wu7) && q.IntersectsWith(wu8) && q.IntersectsWith(wu9) &&
                q.IntersectsWith(wu10) && q.IntersectsWith(wu11) &&
                q.IntersectsWith(wr1) && q.IntersectsWith(wr2) && q.IntersectsWith(wr3) && q.IntersectsWith(wr4) &&
                q.IntersectsWith(wr5) && q.IntersectsWith(wr6) && q.IntersectsWith(wr7) && q.IntersectsWith(wr8) &&
                q.IntersectsWith(wr9))
            {
                player.isMoving = true;
                player.dirX     = -8;
                player.dirY     = 8;
            }

            if (q.IntersectsWith(wd1) && q.IntersectsWith(wd2) && q.IntersectsWith(wd3) && q.IntersectsWith(wd4) &&
                q.IntersectsWith(wd5) &&
                q.IntersectsWith(wd6) && q.IntersectsWith(wd7) && q.IntersectsWith(wd8) && q.IntersectsWith(wd9) &&
                q.IntersectsWith(wd10) && q.IntersectsWith(wd11) &&
                q.IntersectsWith(wl1) && q.IntersectsWith(wl2) && q.IntersectsWith(wl3) && q.IntersectsWith(wl4) &&
                q.IntersectsWith(wl5) &&
                q.IntersectsWith(wl6) && q.IntersectsWith(wl7) && q.IntersectsWith(wl8) && q.IntersectsWith(wl9))
            {
                player.isMoving = true;
                player.dirX     = 8;
                player.dirY     = -8;
            }
        }