Ejemplo n.º 1
0
    public void _on_Area2D_body_entered(Node body)
    {
        if (bouncer_data.deadly && body is Juni)
        {
            Juni.die();
            return;
        }

        if (!in_air)
        {
            return;
        }
        if (!GDArea.isIn(GlobalPosition))
        {
            return;
        }                                             // ignore all collisions if out of the area
        if (vel < 0f)
        {
            vel = -vel; return;
        }

        in_air = false;

        var p = Position;

        p.y      = start_y;
        Position = p;

        GetNode <AnimatedSprite>("AnimatedSprite").Play(Anim, true);
    }
Ejemplo n.º 2
0
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);

        // Check for collisions with ObjectsCollide and area bounds
        var diff     = speed * direction * SPEED_SCALE * delta;
        var diff_vec = vertical ? new Vector2(0, diff) : new Vector2(diff, 0);

        // Sometimes collision can be detected with zero movement! Muff got stuck after this.
        if (diff != 0 && (!GDArea.isIn(Center + diff_vec, x_border: xBorder) || moveAndCollide(diff_vec) != null))
        {
            collide();
        }

        var new_speed = speed - _deceleration * delta;

        if (speed > 0 && new_speed <= 0)
        {
            changeSpeed(0);
        }
        else
        {
            speed = new_speed;
        }
    }
Ejemplo n.º 3
0
    public void _on_Area2D_body_entered(Node body)
    {
        if (body is Juni juni)
        {
            juniDie(juni);
            return;
        }

        if (!in_air)
        {
            return;
        }
        if (!GDArea.isIn(GlobalPosition))
        {
            return;
        }                                             // ignore all collisions if out of the area
        if (vel < 0f)
        {
            vel = -vel; return;
        }

        in_air = false;

        Position = new Vector2(Position.x, start_y);

        GetNodeOrNull <RawAudioPlayer2D>("BouncePlayer")?.Play();
        sprite.Play("stop", true);
    }
Ejemplo n.º 4
0
 public override void _PhysicsProcess(float delta)
 {
     base._PhysicsProcess(delta);
     if (!Juni.dead && Juni.manhattanDistance(Center) < 67 && GDArea.isIn(Juni.GlobalPosition, 18 + 14, 18 + 14))
     {
         sprite.Play("launch");
         GetNode <AudioStreamPlayer2D>("ExplodePlayer").Play();
         juniDie(Juni);
     }
 }
Ejemplo n.º 5
0
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);
        var sprite = GetNode <AnimatedSprite>("AnimatedSprite");
        var jgp    = Juni.ApparentPosition;

        float juni_radar_value = horizontal ? jgp.y : jgp.x;
        float obj_radar_value  = horizontal ? Center.y : Center.x;
        bool  out_of_radar     = (radarTop != 0 && juni_radar_value < obj_radar_value - radarTop) ||
                                 (radarBottom != 0 && juni_radar_value > obj_radar_value + radarBottom);

        float juni_coord_value = horizontal ? jgp.x : jgp.y;
        float obj_coord_value  = horizontal ? Center.x : Center.y;
        bool  too_close        = Mathf.Abs(juni_coord_value - obj_coord_value) < keepDistance;
        bool  stop             = out_of_radar || too_close;

        if (!stop)
        {
            int   direction = juni_coord_value < obj_coord_value ? -1 : 1;
            float diff      = speed * direction * delta;
            var   diff_vec  = horizontal ? new Vector2(diff, 0) : new Vector2(0, diff);
            if (!GDArea.isIn(Center + diff_vec, x_border: 10) || moveAndCollide(diff_vec) != null)
            {
                stop = true;
            }
            else
            {
                if (sprite.Animation != "walk")
                {
                    sprite.Play("walk");
                    if (horizontal)
                    {
                        sprite.FlipH = direction < 0;
                    }
                    else
                    {
                        sprite.FlipV = direction > 0;
                    }
                }
            }
        }

        if (stop)
        {
            if (sprite.Animation == "walk")
            {
                sprite.Play("default");
            }
        }
    }
Ejemplo n.º 6
0
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);

        var movement  = (CurrentDirection * _params.speed * delta) + Buzz * delta;
        var col       = Call("move_and_collide", movement, true, true, true) as KinematicCollision2D;
        var offscreen = !GDArea.isIn(Center + (movement * 6f));

        if (col == null && !offscreen)
        {
            Translate(movement);
        }
        else
        {
            startMove();
        }
    }
Ejemplo n.º 7
0
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);
        var buzz = new Vector2(random.NextFloat(-buzzStrength, buzzStrength),
                               random.NextFloat(-buzzStrength, buzzStrength));
        var movement  = currentDirection * speed * delta + buzz * delta;
        var collision = moveAndCollide(movement, testOnly: true);
        var offscreen = !GDArea.isIn(Center + movement, x_border: border, y_border: border);

        if (collision == null && !offscreen)
        {
            Translate(movement);
        }
        else
        {
            changeDirection(); GetNode <Timer>("FlyTimer").Start();
        }
    }
Ejemplo n.º 8
0
    protected override void _InvProcess(float delta)
    {
        time += delta;

        var gp = GlobalPosition;

        gp.x          += Speed * delta;
        gp.y           = height + (Mathf.Sin(time * HOVER_SPEED) * HOVER_HEIGHT);
        GlobalPosition = gp;

        // Collide with area edge
        var dp = GlobalPosition + new Vector2(12f + (12f * Mathf.Sign(Speed)), 0f);

        if (!GDArea.isIn(dp))
        {
            Speed *= -1f;
        }
    }
Ejemplo n.º 9
0
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);
        if (!isRunning)
        {
            return;
        }
        float diff     = speed * direction * delta;
        var   diff_vec = new Vector2(diff, 0);
        var   center   = GlobalPosition + new Vector2(centerOffset, 0);

        if (!GDArea.isIn(center + diff_vec, x_border: border) || moveAndCollide(diff_vec) != null)
        {
            isRunning    = false;
            direction    = -direction;
            sprite.FlipH = !sprite.FlipH;
            sprite.Play("default");
        }
    }
Ejemplo n.º 10
0
    public override void _PhysicsProcess(float delta)
    {
        // TODO: not very accurate (no reappear, different speed, etc). Rewrite if required.
        speed += random.NextFloat(-speedBuzz + speedOffset, speedBuzz + speedOffset) * delta;
        if (speed > limitSpeed)
        {
            speed = resetSpeed;
        }

        direction += random.NextFloat(-directionBuzz, directionBuzz) * delta;

        opacity += random.NextFloat(-opacityBuzz, opacityBuzz) * delta;
        opacity  = Mathf.Max(0, Mathf.Min(1, opacity));

        var diff      = new Vector2(speed, 0).Rotated(direction);
        var collision = moveAndCollide(diff * delta * SPEED_SCALE);

        if (collision != null)
        {
            direction = diff.Bounce(collision.Normal).Angle();
        }
        if (!GDArea.isIn(Center))
        {
            direction = (GDArea.GlobalPosition + new Vector2(300, 120)).AngleToPoint(Center);
        }

        sprite.Rotation = direction;
        Modulate        = new Color(1, 1, 1, opacity);

        string anim = speed <= idleSpeed ? "idle" :
                      speed > runSpeed ? "run" : "fly";

        if (sprite.Animation != anim)
        {
            sprite.Play(anim);
        }
    }