예제 #1
0
 public bool isHit(ShipUpgrade upgrade)
 {
     if (upgrade.hitbox.IntersectsWith(hitbox))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #2
0
        public void setUpgrade(ShipUpgrade upgrade)
        {
            if (base.hitpoints + upgrade.hitpoints <= 36)
            {
                base.hitpoints += upgrade.hitpoints;
            }

            if (base.projectileDamage + upgrade.projectileDamage <= 4)
            {
                base.projectileDamage += upgrade.projectileDamage;
            }

            //za da ne se pretvori vo cist laser, ima crash povrzan so hit detection-ot  koga ke se sluci toa
            if (base.shootCooldown - upgrade.projectileCooldown > 50)
            {
                base.shootCooldown -= upgrade.projectileCooldown;
            }
        }
예제 #3
0
        //HIT DETECTION ZA ENEMIES,PLAYER I PROEKTILI POVRZANI SO NIV
        public void enemyCollisionLogic()
        {
            if (player.hitpoints <= 0)
            {
                stopGame();
            }
            for (int i = 0; i < enemies.Count; i++)
            {
                //Se brisat enemies offscreen , mora continue inace ke iterira posle vo index koj sto e prazen
                if (enemies[i].hitbox.Y > screenHeight)
                {
                    enemies.RemoveAt(i);
                    continue;
                }

                //Hit detection za kolizija
                if (player.isHit(enemies[i]))
                {
                    player.PureDamage(enemies[i].hitpoints);
                    enemies.RemoveAt(i);
                    continue;
                }
                //idna iteracija dokolku sakam , piercing bullets samo mozam duplicat od forot vo poseben if bez projectiles.removeat;

                //Hit detection za proektili od enemies i player
                for (int j = 0; j < projectiles.Count; j++)
                {
                    if (projectiles[j].projectileHitbox.Y > screenHeight || projectiles[j].projectileHitbox.Y < 0)
                    {
                        projectiles.RemoveAt(j);
                        continue;
                    }

                    if (enemies[i].isHit(projectiles[j]))
                    {
                        enemies[i].Damage(projectiles[j]);

                        if (enemies[i].hitpoints <= 0)
                        {
                            switch (enemies[i].type)
                            {
                            case (Type.Regular):
                                score += 10;
                                //Napraviv losa implementacija i upgrade.assigned e patchwork za da raboti, ako imam vreme ke go sredam
                                ShipUpgrade upgrade = new ShipUpgrade(randSeed.Next(1, 100), enemies[i]);
                                if (upgrade.assigned)
                                {
                                    shipUpgrades.Add(upgrade);
                                }
                                break;

                            case (Type.Shooter):
                                score  += 20;
                                upgrade = new ShipUpgrade(randSeed.Next(1, 100), enemies[i]);
                                if (upgrade.assigned)
                                {
                                    shipUpgrades.Add(upgrade);
                                }
                                break;

                            case (Type.Tanky):
                                score  += 30;
                                upgrade = new ShipUpgrade(randSeed.Next(1, 100), enemies[i]);
                                if (upgrade.assigned)
                                {
                                    shipUpgrades.Add(upgrade);
                                }
                                break;
                            }
                            lblScore.Text = "Score:" + score;


                            enemies.RemoveAt(i);
                        }

                        projectiles.RemoveAt(j);

                        continue;
                    }
                    else if (player.isHit(projectiles[j]))
                    {
                        player.Damage(projectiles[j]);
                        projectiles.RemoveAt(j);
                    }
                }
            }
        }