コード例 #1
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private void drawSmallArms(Zombies[] sh)
 {
     for (int i = 0; i < sh.Length; i++)
     {
         if (sh[i].gun.fired && sh[i].visible)
         {
             sh[i].gun.x += sh[i].gun.vX;
             sh[i].gun.y += sh[i].gun.vY;
             g.FillEllipse(black, sh[i].gun.x, sh[i].gun.y, 3, 3);
             if(sh[i].gun.x < 0 || sh[i].gun.y < 0 || sh[i].gun.x > borderX || sh[i].gun.y > borderY)
             {
                 sh[i].gun.fired = false;
             }
         }
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
        private void drawWeapons()
        {
            for (int i = 0; i < numBunkers; i++)
            {
                if (mortars[i].fired && timeCount % 2 == 0)
                {
                    Zombies z = new Zombies();
                    z.x = mortars[i].x;
                    z.y = mortars[i].y;
                    z.width = 100;
                    z.height = 100;
                    z.alive = true;
                    collision(i, z, buildings, true, true);

                    pics.mY += 100;
                    mortars[i].vY += 100;
                    Rectangle size = new Rectangle(mortars[i].x, mortars[i].y, 60, 60);
                    Image m = pics.explosion;

                    g.DrawImage(m, size, 0, mortars[i].vY, 100, 100, GraphicsUnit.Pixel);
                }
            }
            if (bomb.fired && timeCount % 2 == 0)
            {
                pics.bY += 100;
                //g.FillEllipse(red, (bomb.x), (bomb.y), (150), (150));

                Rectangle size = new Rectangle(bomb.x, bomb.y, 200, 200);
                Image m = pics.explosion;

                g.DrawImage(m, size, 0, pics.bY, 100, 100, GraphicsUnit.Pixel);
            }
            for (int i = 0; i < guns.Length; i++)
            {
                if (guns[i].fired)
                {
                    if ((timeCount - guns[i].timeFired) > 50)
                    {
                        guns[i].fired = false;
                    }
                    g.FillEllipse(black, ((guns[i].x)), ((guns[i].y)), (3), (3));
                }
            }

            if (cannons.fired && timeCount % 2 == 0)
            {
                //g.FillEllipse(red, (cannons.x), (cannons.y), (75), (75));
                pics.cY += 100;
                Rectangle size = new Rectangle(cannons.x, cannons.y, 100, 100);
                Image m = pics.explosion;

                g.DrawImage(m, size, 0, pics.cY, 100, 100, GraphicsUnit.Pixel);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
        private void createBunkers()
        {
            for (int i = 0; i < numBunkers; i++)
            {
                bunkers[i] = new Zombies();
            }
            for (int i = 0; i < numBunkers; i++)
            {
                bunkers[i].vX = 0;
                bunkers[i].vY = 0;
                bunkers[i].width = 20;
                bunkers[i].height = 20;
                bunkers[i].alive = true;

                int j = -1;
                do
                {
                    j++; //= rand.Next() % numBuildings;
                } while ((buildings[j].x > (borderX / 2) || buildings[j].y > (borderY / 2)) || (buildings[j].garrison)&&(j < numBuildings-1));// && buildings[j].bunkerNum != i/2 && i != 0));
                buildings[j].garrison = true;
                bunkers[i].x = buildings[j].x + buildings[j].width - 20;
                bunkers[i].y = buildings[j].y + buildings[j].height - 20;

                buildings[j].bunkerNum = i;
                bunkers[i].visible = false;
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
        private void createZombies(int num)
        {
            for (int i = 0; i < num; i++)
            {
                Zeds[i] = new Zombies();
                do{
                do{
                    Zeds[i].x = rand.Next() % borderX / 2 - 100;
                    Zeds[i].y = rand.Next() % borderY / 2 - 100;
                } while (Zeds[i].x <= 0 || Zeds[i].y <= 0);

                Zeds[i].width = 10;
                Zeds[i].height = 10;
                }while(garrison(i, Zeds[i]));
                Zeds[i].alive = true;
                Zeds[i].startX = Zeds[i].x;
                Zeds[i].startY = Zeds[i].y;
                Zeds[i].visible = false;
            }

            for (int i = 0; i < numAllies; i++)
            {
                allies[i] = new Zombies();
                do{
                do
                {
                    allies[i].x = rand.Next(borderX/2+100, borderX-50);// % 400 + borderX - 250;
                    allies[i].y = rand.Next(borderY/2+100, borderY-50);// % 400 + borderY - 250;
                } while (allies[i].x > borderX || allies[i].y > borderY);

                allies[i].width = 10;
                allies[i].height = 10;
                }while(garrison(i, allies[i]));
                allies[i].alive = true;
                allies[i].startX = allies[i].x;
                allies[i].startY = allies[i].y;
                allies[i].visible = true;
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
        private void smallArms(Zombies[] sh, Zombies[] tgt, int ran, int numAlive)
        {
            for (int i = 0; i < sh.Length; i++)
            {
                if (sh[i].alive && !sh[i].gun.fired && sh[i].visible)
                {
                    if (rand.Next() % ran == 0)
                    {
                        int j = -1;
                        int c = 0;
                        //if (numAlive > 0)
                        {
                            do
                            {
                                c++;
                                j++; //= rand.Next() % tgt.Length;
                                if (c > 1000)
                                {
                                    MessageBox.Show(numAlive.ToString());
                                }
                            } while (!tgt[j].alive && j < tgt.Length-1);
                        }
                        if(getDistance(sh[i], tgt[j]) < 250)
                        {
                            tgt[j].visible = true;
                        }
                        if (tgt[j].visible && tgt[j].alive)
                        {
                            sh[i].gun.x = (int)sh[i].x;
                            sh[i].gun.y = (int)sh[i].y;
                            sh[i].gun.fired = true;

                            int d = getDistance(sh[i], tgt[j]);
                            int diffX = (int)(tgt[j].x - sh[i].x);
                            int diffY = (int)(tgt[j].y - sh[i].y);
                            int comp = 1;

                            sh[i].gun.vX = ((diffX * 25) / d) * comp;
                            sh[i].gun.vY = ((diffY * 25) / d) * comp;
                        }
                    }
                }

            }
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
        /*private void createTanks()
        {
            for (int i = 0; i < numTanks; i++)
            {
                tanks[i] = new Zombies();
            }
            for (int i = 0; i < numTanks; i++)
            {
                tanks[i].width = 30;
                tanks[i].height = 30;
                tanks[i].alive = true;
                do{
                tanks[i].x = rand.Next(20, borderX/3);
                tanks[i].y = rand.Next(20, borderY/3);
                }while(garrison(i, tanks[i]));
            }
        }*/
        private void createBuildings()
        {
            for (int i = 0; i < numBuildings; i++)
            {
                buildings[i] = new Zombies();
            }
                for (int i = 0; i < numBuildings; i++)
                {
                    do
                    {
                        buildings[i].x = rand.Next(50, borderX - 100) - 30;
                        buildings[i].y = rand.Next(50, borderY - 100) - 30;
                        buildings[i].width = rand.Next(50, 140);
                        buildings[i].height = rand.Next(50, 140);
                        buildings[i].alive = true;
                    } while (buildingIntersect(i) || checkBorder(buildings[i]));

                    buildings[i].x += 20;
                    buildings[i].y += 20;

                    buildings[i].width -= 30;
                    buildings[i].height -= 30;
                }
                barracks = rand.Next(0, numBuildings);
                buildings[barracks].barracks = true;
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private void checkShot(int j, Zombies[] tgt)
 {
     Rectangle shooter = new Rectangle((int)(guns[j].x), (int)(guns[j].y), 3, 3);
     for (int i = 0; i < tgt.Length; i++)
     {
         if (tgt[i].alive)
         {
             Rectangle target = new Rectangle((int)(tgt[i].x), (int)(tgt[i].y), (int)(tgt[i].width), (int)(tgt[i].height));
             if(shooter.IntersectsWith(target))
             {
                 tgt[i].alive = false;
                 //numTargets--;
             }
         }
     }
 }
コード例 #8
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 /*private void drawTanks()
 {
     for (int i = 0; i < numTanks; i++)
     {
         if (tanks[i].alive)
         {
             g.FillRectangle(red, tanks[i].x, tanks[i].y, tanks[i].width, tanks[i].height);
         }
     }
 }*/
 private bool getVisual(Zombies sh, Zombies []tgt)
 {
     for (int i = 0; i < tgt.Length; i++)
     {
         if (tgt[i].alive && !tgt[i].visible)
         {
             if (getDistance(sh, tgt[i]) < 300)
             {
                 tgt[i].visible = true;
                 //return true;
             }
         }
     }
     return false;
 }
コード例 #9
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private void checkCannon(Zombies []sh)
 {
     if (cannons.fired)
     {
         Point[] p = new Point[1];
         Rectangle shooter = new Rectangle((int)(cannons.x), (int)(cannons.y), (int)(100), (int)(100));
         for (int i = 0; i < sh.Length; i++)
         {
             if (sh[i].alive)
             {
                 Rectangle target = new Rectangle((int)(sh[i].x), (int)(sh[i].y), (int)(sh[i].width), (int)(sh[i].height));
                 if (target.IntersectsWith(shooter))
                 {
                     sh[i].alive = false;
                    // numTargets--;
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private void checkMortars(Weapons[] sh, Zombies[] tgt, bool enemy)
 {
     for (int i = 0; i < sh.Length; i++)
     {
         Rectangle shooter = new Rectangle(sh[i].x, sh[i].y, 60, 60);
         for (int j = 0; j < tgt.Length; j++)
         {
             if (tgt[j].alive)
             {
                 Rectangle target = new Rectangle((int)tgt[j].x, (int)tgt[j].y, (int)tgt[j].width, (int)tgt[j].height);
                 if (shooter.IntersectsWith(target))
                 {
                     //sh[i].gun.fired = false;
                     tgt[j].alive = false;
                 }
             }
         }
     }
 }
コード例 #11
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private bool checkBorder(Zombies sh)
 {
     return (sh.x + sh.width > borderX || sh.y + sh.height > borderY || sh.x < 5 || sh.y < 5);
 }
コード例 #12
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private void checkBomb(Zombies[] sh)
 {
     Point[] p = new Point[1];
     Rectangle shooter = new Rectangle((int)(bomb.x), (int)(bomb.y), (int)(200), (int)(200));
     if (bomb.fired)
     {
         for (int i = 0; i < sh.Length; i++)
         {
             if (sh[i].alive)
             {
                 Rectangle target = new Rectangle((int)sh[i].x, (int)sh[i].y, (int)sh[i].width, (int)sh[i].height);
                 if (target.IntersectsWith(shooter))
                 {
                     sh[i].alive = false;
                     if (sh.Length == numBuildings)
                     {
                         if (sh[i].barracks && i < sh.Length-1)
                         {
                             sh[i + 1].barracks = true;
                             barracks++;
                         }
                     }
                     if (sh[i].garrison)
                     {
                         if (sh[i].bunkerNum < bunkers.Length)
                         {
                             bunkers[sh[i].bunkerNum].alive = false;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #13
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private void stopAtBorder(Zombies sh)
 {
     if (sh.x < 10)
     {
         sh.x += 5;
     }
     if (sh.y < 10)
     {
         sh.y += 5;
     }
     if (sh.x > borderX - 10)
     {
         sh.x -= 5;
     }
     if (sh.y > borderY - 10)
     {
         sh.y -= 5;
     }
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private bool garrison(int i, Zombies sh)
 {
     Rectangle shooter = new Rectangle((int)sh.x, (int)sh.y, (int)sh.width, (int)sh.height);
     for (int j = 0; j < numBuildings; j++)
     {
         if (buildings[j].alive)
         {
             Rectangle target = new Rectangle((int)buildings[j].x, (int)buildings[j].y, (int)buildings[j].width, (int)buildings[j].height);
             if(shooter.IntersectsWith(target))
             {
                 return true;
             }
         }
     }
         return false;
 }
コード例 #15
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private void checkSmallArms(Zombies []sh, Zombies []tgt, bool enemy, int offSet)
 {
     for (int i = 0; i < sh.Length; i++)
     {
         Rectangle shooter = new Rectangle(sh[i].gun.x, sh[i].gun.y, 5, 5);
         for (int j = 0; j < tgt.Length; j++)
         {
             if (tgt[j].alive)
             {
                 Rectangle target = new Rectangle((int)tgt[j].x, (int)tgt[j].y, (int)tgt[j].width, (int)tgt[j].height);
                 if (shooter.IntersectsWith(target) && rand.Next(0, offSet) == 0)
                 {
                     sh[i].gun.fired = false;
                     tgt[j].alive = false;
                 }
             }
         }
         strayRounds(sh[i].gun);
     }
 }
コード例 #16
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private int getDistance(Zombies sh, Zombies tgt)
 {
     float diffX = sh.x - tgt.x;
     float diffY = sh.y - tgt.y;
     return (int)Math.Sqrt((diffX * diffX)+(diffY * diffY));
 }
コード例 #17
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
 private bool collision(int i, Zombies sh, Zombies[] tgt, bool friendly, bool kill)
 {
     Rectangle shooter = new Rectangle((int)sh.x - stagger, (int)sh.y - stagger, (int)sh.width + stagger, (int)sh.width + stagger);
         for (int j = 0; j < tgt.Length; j++)
         {
             if (i != j || friendly)
             {
                 if (sh.alive && tgt[j].alive)
                 {
                     Rectangle target = new Rectangle((int)tgt[j].x-stagger, (int)tgt[j].y-stagger, (int)tgt[j].width+stagger, (int)tgt[j].width+stagger);
                     if (shooter.IntersectsWith(target))
                     {
                         if (kill)
                         {
                             tgt[j].alive = false;
                         }
                         return true;
                     }
                 }
             }
         }
     return false;
 }
コード例 #18
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
        private void moveToRallyPoint(Zombies[] sh, Point rallyP)
        {
            for (int i = 0; i < sh.Length; i++)
            {
                float diffX = rallyP.X - sh[i].x;
                float diffY = rallyP.Y - sh[i].y;
                double distance = Math.Sqrt((double)((diffX * diffX) + (diffY * diffY)));

                if (sh[i].alive)// && !collision(i, (int)distance))
                {

                    //if (distance > 10)
                    {
                        if (diffX > 0)
                        {
                            sh[i].vX = 1;
                        }
                        if (diffX < 0)
                        {
                            sh[i].vX = -1;
                        }
                        if (diffY > 0)// && Math.Abs(diffX) > 1)
                        {
                            sh[i].vY = diffY / diffX;
                        }
                        if (diffY < 0 && diffX < 0)// && Math.Abs(diffX) > 1)
                        {
                            sh[i].vY = -(diffY / diffX);
                        }
                        if (diffY < 0 && diffX > 0)// && Math.Abs(diffX) > 1)
                        {
                            sh[i].vY = diffY / diffX;
                        }
                        if (diffX == 0 && diffY > 0)
                        {
                            sh[i].vY = 1;
                        }
                        if (diffX == 0 && diffY < 0)
                        {
                            sh[i].vY = -1;
                        }
                        if (Math.Abs(diffX) < 50)
                        {
                            sh[i].vX = 0;
                            if (diffY > 10)
                            {
                                sh[i].vY = 1;
                            }
                            if (diffY < -10)
                            {
                                sh[i].vY = -1;
                            }

                        }
                        if (Math.Abs(diffY) < 50)
                        {
                            sh[i].vY = 0;
                            if (diffX > 10)
                            {
                                sh[i].vX = 1;
                            }
                            if (diffX < -10)
                            {
                                sh[i].vX = -1;
                            }

                        }

                        sh[i].vX = sh[i].vX * 5;
                        sh[i].vY = sh[i].vY * 5;

                        if (Math.Abs(sh[i].vX) < 8)
                        {
                            sh[i].x += sh[i].vX;
                        }
                        if (collision(i, sh[i], sh, false, false) || garrison(i, sh[i]))
                        {
                            if (Math.Abs(sh[i].vX) < 8)
                            {
                                sh[i].x -= (float)1.3 * sh[i].vX;
                            }
                        }
                        if (Math.Abs(sh[i].vY) < 8)
                        {
                            sh[i].y += sh[i].vY;
                        }

                        if (collision(i, sh[i], sh, false, false) || garrison(i, sh[i]))
                        {
                            if (Math.Abs(sh[i].vY) < 8)
                            {
                                sh[i].y -= (float)1.3 * sh[i].vY;
                            }
                        }
                        getVisual(sh[i], Zeds);
                        getVisual(sh[i], bunkers);
                        collision(i, sh[i], Zeds, false, false);
                        if (sh[i].x < visual.X && sh[i].y < visual.Y)
                        {
                            visual.X = (int)sh[i].x;
                            visual.Y = (int)sh[i].y;
                        }

                    }
                }
                if(sh.Length == numAllies)
                {
                    collision(i, sh[i], Zeds, false, true);
                    if (sh[i].alive && sh[i].x < 100 && sh[i].y < 100)
                    {
                        nextLevel(false);
                    }
                }
                stopAtBorder(sh[i]);
            }
        }
コード例 #19
0
ファイル: Form1.cs プロジェクト: AnthonySimmons/ZombieShooter
        private void respawnEnemies(Zombies[] tgt, int rS)
        {
            for (int i = 0; i < tgt.Length; i++)
            {
                if (!tgt[i].alive)// && rand.Next(0, rS) == 0)
                {

                    //int j = -1;
                    //do{
                        //barracks++;
                        //j = barracks;
                    //}while(!buildings[j].alive && (j < buildings.Length - 1));// && !(buildings[j].x < borderX/2 && buildings[j].y < borderY/2)));
                    if (buildings[barracks].alive)// && buildings[j].x < borderX*0.7 && buildings[j].y < borderY*0.7)
                    {
                        //j = barracks;
                        tgt[i].alive = true;
                        tgt[i].x = buildings[barracks].x;
                        tgt[i].y = buildings[barracks].y;
                        //buildings[j].barracks = true;
                    }
                }
            }
        }