Ejemplo n.º 1
0
 public Bullet(Player owner, float degree)
 {
     //Derive data from the owner, since it's obvious that this owner fired the bullet, aka construction call
     OwnerName = owner.Name;
     PenetratingLevel = owner.PenetratingLevel;
     ShrapnelLevel = owner.ShrapnelLevel;
     PositionX = owner.PositionX;
     PositionY = owner.PositionY;
     VelocityX = owner.VelocityX + (float)(Math.Cos(degree) * (owner.VelocityLevel * 100 + 200));
     VelocityY = owner.VelocityY + (float)(Math.Sin(degree) * (owner.VelocityLevel * 100 + 200));
     Color = Color.White;
     Scale = 1;
     Lifetime = 1;
     Damage = owner.DamageLevel * 5;
     IsShrapnel = false;
 }
Ejemplo n.º 2
0
 public void AddPlayer(Player player)
 {
     _players.Add(player);
 }
Ejemplo n.º 3
0
 public Shockwave(float xPos, float yPos, int size, Player owner)
 {
     TimeTilBoom = 0.2f;
     PositionX = xPos;
     PositionY = yPos;
     Radius = 72 * size;
     Size = size;
     if (owner != null)
     {
         OwnerName = owner.Name;
     }
 }
Ejemplo n.º 4
0
 public void AddShockwave(float xPos, float yPos, int size, Player owner)
 {
     var shockwave = new Shockwave(xPos, yPos, size, owner);
     Shockwaves.Add(shockwave);
 }
Ejemplo n.º 5
0
 public void AddBullet(Player player)
 {
     for (int i = 0; i < player.NumberOfMounts + 1; i++)
     {
         float degree = (float)((((player.Angle - (15f * player.NumberOfMounts / 2) + (15f * i)) - 90) / 180) * Math.PI);
         Bullet bullet = new Bullet(player, degree);
         Bullets.Add(bullet);
     }
 }
Ejemplo n.º 6
0
            public void HandleCollision(Player player, int levelWidth, int levelHeight, Random r, float frameDeltaTime)
            {
                for (int i = 0; i < _asteroidsInCell.Count; i++)
                {
                    var asteroid = _asteroidsInCell[i];
                    if (asteroid.ToBeRemoved || player.IsDead || asteroid.Phase < 100)
                    {
                        //No collision possible
                        continue;
                    }
                    //create variables that'd be easier to read than function calls
                    float x1 = asteroid.PositionX;
                    float y1 = asteroid.PositionY;
                    float x2 = player.PositionX;
                    float y2 = player.PositionY;

                    Utility.GetClosestDistance(x1, y1, x2, y2, levelWidth, levelHeight, out x2, out y2);

                    float v1x = asteroid.VelocityX; //e.FrameDeltaTime is the time between frames, less than 1
                    float v1y = asteroid.VelocityY;
                    float v2x = player.VelocityX;
                    float v2y = player.VelocityY;

                    //get the position plus velocity
                    float tx1 = x1 + v1x * frameDeltaTime;
                    float ty1 = y1 + v1y * frameDeltaTime;
                    float tx2 = x2 + v2x * frameDeltaTime;
                    float ty2 = y2 + v2y * frameDeltaTime;

                    float dx = tx2 - tx1;
                    float dy = ty2 - ty1;
                    float dx2 = x2 - x1;
                    float dy2 = y2 - y1;
                    float r1 = (float)Math.Sqrt(dx * dx + dy * dy); //Get the distance between centers of asteroids
                    float r2 = (float)Math.Sqrt(dx2 * dx2 + dy2 * dy2);

                    if (r1 < (asteroid.Radius + player.ShipSize * 16) && r1 < r2) //Collision!
                    {
                        //Calculate the impulse or change of momentum, or whatever people call it
                        float rx = dx / r1;
                        float ry = dy / r1;
                        float k1 = 2 * player.Mass * (rx * (v2x - v1x) + ry * (v2y - v1y)) / (asteroid.Mass + player.Mass);
                        float k2 = 2 * asteroid.Mass * (rx * (v1x - v2x) + ry * (v1y - v2y)) / (asteroid.Mass + player.Mass);

                        //Adjust the velocities
                        v1x += k1 * rx;
                        v1y += k1 * ry;
                        v2x += k2 * rx * (1 - player.InertialLevel * 0.05f);
                        v2y += k2 * ry * (1 - player.InertialLevel * 0.05f);

                        //Assign the final value to asteroids
                        asteroid.VelocityX = v1x;
                        asteroid.VelocityY = v1y;

                        float xDiff = Math.Abs(player.VelocityX) - Math.Abs(v2x);
                        float yDiff = Math.Abs(player.VelocityY) - Math.Abs(v2y);
                        float amount = (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff) / 2;
                        player.Energy -= amount * (1 - (player.HardnessLevel * 0.05f));
                        if (player.Energy < 0)
                        {
                            player.IsDead = true;
                        }
                        player.VelocityX = v2x;
                        player.VelocityY = v2y;

                        //Deal damage and activate shield for player
                        player.ShieldAlpha = 1;
                    }
                    if (asteroid.AsteroidType == AsteroidType.MAGNETIC && r1 < asteroid.Size * 64) //Within magnetic range
                    {
                        var degree = Math.Atan2(ty2 - ty1, tx2 - tx1);
                        asteroid.VelocityX += (float)(((asteroid.Size * 128) - r1) * Math.Cos(degree) * frameDeltaTime);
                        asteroid.VelocityY += (float)(((asteroid.Size * 128) - r1) * Math.Sin(degree) * frameDeltaTime);
                    }
                    if (asteroid.AsteroidType == AsteroidType.REPULSER && r1 < asteroid.Size * 64)
                    {
                        var degree = Math.Atan2(ty2 - ty1, tx2 - tx1);
                        float repulsingForce = ((asteroid.Size * 96) - r1);
                        player.VelocityX += (float)(repulsingForce * Math.Cos(degree) * frameDeltaTime * (asteroid.Mass / (float)(asteroid.Mass + player.Mass)));
                        player.VelocityY += (float)(repulsingForce * Math.Sin(degree) * frameDeltaTime * (asteroid.Mass / (float)(asteroid.Mass + player.Mass)));
                        asteroid.VelocityX -= (float)(repulsingForce * Math.Cos(degree) * frameDeltaTime * (player.Mass / (float)(asteroid.Mass + player.Mass)));
                        asteroid.VelocityY -= (float)(repulsingForce * Math.Sin(degree) * frameDeltaTime * (player.Mass / (float)(asteroid.Mass + player.Mass)));
                    }
                    if (asteroid.AsteroidType == AsteroidType.GRAVITIC && r1 < asteroid.Size * 64)
                    {
                        var degree = Math.Atan2(ty2 - ty1, tx2 - tx1);
                        float graviticForce = ((asteroid.Size * 96) - r1);
                        player.VelocityX -= (float)(graviticForce * Math.Cos(degree) * frameDeltaTime * (asteroid.Mass / (float)(asteroid.Mass + player.Mass)));
                        player.VelocityY -= (float)(graviticForce * Math.Sin(degree) * frameDeltaTime * (asteroid.Mass / (float)(asteroid.Mass + player.Mass)));
                        asteroid.VelocityX += (float)(graviticForce * Math.Cos(degree) * frameDeltaTime * (player.Mass / (float)(asteroid.Mass + player.Mass)));
                        asteroid.VelocityY += (float)(graviticForce * Math.Sin(degree) * frameDeltaTime * (player.Mass / (float)(asteroid.Mass + player.Mass)));
                    }
                }
            }