Exemplo n.º 1
0
        public bool collision(bulletClass bc, monsterClass mc)
        {
            Rectangle bcRec = new Rectangle(bc.x, bc.y, bc.size, bc.size);
            Rectangle mcRec = new Rectangle(mc.x, mc.y, mc.size, mc.size);

            if (bcRec.IntersectsWith(mcRec))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 public void move(bulletClass bc)
 {
     if (bc.direction == 2)
     {
         bc.x -= bc.speed;
     }
     else if (bc.direction == 3)
     {
         bc.x += bc.speed;
     }
     else if (bc.direction == 1)
     {
         bc.y -= bc.speed;
     }
     else //down
     {
         bc.y += bc.speed;
     }
 }
        private void timer1_Tick(object sender, EventArgs e)
        {
            #region button
            if (downArrowDown == true)
            {
                direction = 0;
                pc.move(pc, "down");
            }
            else if (upArrowDown == true)
            {
                direction = 1;
                pc.move(pc, "up");
            }
            else if (leftArrowDown == true)
            {
                direction = 2;
                pc.move(pc, "left");
            }
            else if (rightArrowDown == true)
            {
                direction = 3;
                pc.move(pc, "right");
            }
            Refresh();
            #endregion
            #region Monster following player

            //Monster following player
            if (pc.x - mc.x < 0)
            {
                mc.move(mc, "left");
            }
            else if (pc.x - mc.x > 0)
            {
                mc.move(mc, "right");
            }
            if (pc.y - mc.y < 0)
            {
                mc.move(mc, "up");
            }
            else if (pc.y - mc.y > 0)
            {
                mc.move(mc, "down");
            }
            Refresh();
            #endregion
            #region bullet
            foreach (bulletClass bc in ammo)
            {
                bc.move(bc);

                if (bc.x > this.Width || bc.x < 0 || bc.y > this.Height || bc.y < 0)
                {
                    ammo.Remove(bc);
                    break;
                }
            }
            if (spaceDown == true && ammo.Count() < 4)
            {
                bulletClass bc = new bulletClass(pc.x + (pc.size / 2), pc.y + (pc.size / 2), 2, 10, direction);
                ammo.Add(bc);
            }
            #endregion
            #region scoreScreen
            foreach (monsterClass mc in monster)
            {
                if (pc.collision(pc, mc) == true)
                {
                    Form scoreScreen = this.FindForm();
                    scoreScreen.Controls.Remove(this);
                    scoreScreen ss = new scoreScreen();
                    scoreScreen.Controls.Add(ss);
                    break;
                }
            }
            #endregion
        }