Beispiel #1
0
    protected override void HoldingItem(bool use, bool startUse, bool endUse, bool doubleUse)
    {
        //When the holder first presses this Item's key, create a LazerShot to charge
        if (startUse)
        {
            if (chargingShot != null)
            {
                chargingShot.DestroyThis();
            }

            chargingShot                = (LazerShot)level.CreateObject("LazerShotPF");
            chargingShot.team           = holder.team;
            chargingShot.color          = color;
            chargingShot.timeToLiveSecs = shotLifeSecs;
            chargingShot.damage         = shotMinDamage;
            UpdateChargingShot();
        }
        //When the holder holds down this Item's key, update the LazerShot
        else if (use)
        {
            UpdateChargingShot();
        }

        //When the holder release's this Item's key, shoot the LazerShot
        if (endUse && chargingShot != null)
        {
            chargingShot.velocity = holder.velocity;
            chargingShot.MoveForward(shotSpeed);
            chargingShot = null;
        }
    }
Beispiel #2
0
    protected override void HoldingItem(bool use, bool startUse, bool endUse, bool doubleUse)
    {
        //update the time before the next shot
        if (shotCooldown > 0)
        {
            shotCooldown--;
        }
        //if the holder is holding down this Item's key and it is time to shoot another shot
        //then create a LazerShot infront of the holder
        else if (use)
        {
            LazerShot shot = (LazerShot)level.CreateObject("LazerShotPF", holder.position + offset.Rotate(holder.angle), holder.angle);
            shot.maxSpeed = shotSpeed + holder.velocity.magnitude;
            shot.velocity = holder.velocity;
            shot.MoveForward(shotSpeed);
            shot.damage         = shotDamage;
            shot.timeToLiveSecs = shotLifeSecs;
            shot.color          = color;
            shot.team           = holder.team;

            //reset the time until the next shot
            shotCooldown = (int)(shotCooldownSecs * level.updatesPerSec);

            level.score += USE_POINTS;
        }
    }
Beispiel #3
0
 //when dropped, destroy any shot that is being charged.
 protected override void DropItem()
 {
     if (chargingShot != null)
     {
         chargingShot.DestroyThis();
         chargingShot = null;
     }
 }
Beispiel #4
0
    protected override void UpdateDestructableObject()
    {
        //try to find a target if it doesn't have one
        if (target == null || !target.active)
        {
            target = ClosestObject(level.GetTypes(true, true, false, false), false);
        }
        else
        {
            shootTimer--;

            //find where this needs to shoot to hit the target given their current positions, the LazerShot's speed and the Target's position
            Vector3 intersect = IntersectPosTime(target, shotSpeed, new Vector2(0, 3).Rotate(angle) + position);

            //if the target can be hit, turn towards where this would need to shoot
            if (intersect.z >= 0)
            {
                TurnTowards(intersect);
            }

            //shoot if it is time to
            if (shootTimer <= 0)
            {
                //reset the shootTimer
                shootTimer = shootTimeSecs * level.updatesPerSec / difficultyModifier;

                //if the target cannot be hit by the LazerShot, stop targeting the target
                if (intersect.z < 0 || intersect.z > maxShotLiveSecs)
                {
                    target = null;
                }
                //create a LazerShot aimed to hit the target
                else
                {
                    LazerShot shot = (LazerShot)level.CreateObject("LazerShotPF",
                                                                   new Vector2(0, 3 + shotSpeed * level.secsPerUpdate).Rotate(angle) + position, angle);

                    shot.maxSpeed       = shotSpeed;
                    shot.speed          = shotSpeed;
                    shot.color          = Color.red;
                    shot.timeToLiveSecs = (int)(maxShotLiveSecs * level.updatesPerSec + 1);
                    shot.damage         = damage;
                }
            }
            else
            {
                //try to keep a certain distance from the target
                if (DistanceFrom(target) > targetDistanceFrom)
                {
                    MoveTowards(target, acceleration);
                }
                else
                {
                    MoveTowards(target, -acceleration);
                }
            }
        }
    }
Beispiel #5
0
    protected override void UpdateDestructableObject()
    {
        emitTimer--;

        //emit Lazers if it is time to
        if (emitTimer <= 0)
        {
            emitTimer = (int)(lazerEmitSecs * level.updatesPerSec);

            //create LazerShots around the this LazerEmitter equally spaced angles
            for (int i = 0; i < numLazers * difficultyModifier; i++)
            {
                float     currentAngle = angle + i * 360f / numLazers;
                LazerShot current      = (LazerShot)level.CreateObject("LazerShotPF", position + lazerOffset.Rotate(currentAngle), currentAngle, new Vector2(lazerSpeed, 0).ToAngle(currentAngle) + velocity);
                current.damage         = damage;
                current.timeToLiveSecs = lazerLifeSecs;
                current.color          = lazerColor;
                current.team           = team;
            }
        }
    }
Beispiel #6
0
    /// <summary>
    ///shoot LazerShots infront of the holder in an arch
    /// </summary>
    private void Shoot()
    {
        //make sure the arch is within the correct bounds
        if (spread < spreadStart)
        {
            spread = spreadStart;
        }
        else if (spread > spreadMax)
        {
            spread = spreadMax;
        }

        //create each LazerShot at a different angle in the arch
        for (int i = 0; i < numberOfShots; i++)
        {
            //find the angle for the current LazerShot
            float currentAngle = holder.angle - spread / 2.0f + i * spread / (numberOfShots - 1);

            //create the LazerShot infront of the holder its angle
            LazerShot current = (LazerShot)level.CreateObject("LazerShotPF", holder.position + offset.Rotate(currentAngle),
                                                              currentAngle, new Vector2(shotSpeed, 0).ToAngle(currentAngle) + holder.velocity);

            //set the LazerShot's initial settings
            current.damage         = damageEach;
            current.timeToLiveSecs = shotLifeSecs;
            current.color          = color;
            current.team           = holder.team;
        }

        //reset shoot settings
        shotCooldown = (int)(shotTimeSecs * level.updatesPerSec);
        shotTimer    = 0;
        spread       = 0;

        level.score += USE_POINTS;
    }