Ejemplo n.º 1
0
    // This is called after collision checks are passed. Now we deal damage and stun the target
    public void interactWith(GameObject target, double numSeconds)
    {
        Stun newStun = new Stun(this.templateStun);
        // calculate stun duration
        double stunDuration = Math.Min(this.duration, numSeconds) + this.templateStun.getDuration();

        newStun.setDuration(stunDuration);
        // calculate stun acceleration
        double dx       = target.getCenter()[0] - this.getCenter()[0];
        double dy       = target.getCenter()[1] - this.getCenter()[1];
        double distance = Math.Sqrt(dx * dx + dy * dy);

        // prevent division by zero
        if (distance <= 0)
        {
            distance = 1;
        }
        double[] accel      = new double[2];
        double   accelScale = this.getKnockbackAccel() / distance;

        accel[0] = dx * accelScale;
        accel[1] = dy * accelScale;
        // error checking
        newStun.setAccel(accel);
        // apply the stun
        target.applyStun(newStun);
        Character myOwner = this.getOwner();

        if (myOwner != null)
        {
            myOwner.reinforce(1);
        }
        if (target.isACharacter())
        {
            ((Character)target).reinforce(-1);
        }
    }