Exemplo n.º 1
0
    protected void InitNodes(GameState.Level level, string checkPoint)
    {
        this.Character              = this.GetNode <Character>("Character");
        this.Background             = this.GetNode <Background>("Background");
        this.HUD                    = this.GetNode <HUD>("HUD");
        this.ImpactLocator          = this.GetNode <ImpactLocator>("ImpactLocator");
        this.BoulderGeneratorFollow = this.GetNode <RemoteTransform2D>("Character/BoulderGeneratorFollow");
        this.CameraFollow           = this.GetNode <RemoteTransform2D>("Character/CameraFollow");
        this.Music                  = this.GetNode <AudioStreamPlayer>("Audio/Music");
        this.LostSound              = this.GetNode <AudioStreamPlayer>("Audio/LostSound");

        this.Terrain = this.AddTerrain(level);

        this.BoulderGeneratorFollow.RemotePath = new NodePath("../../Terrain/BoulderGenerator");

        this.Character.GlobalPosition = this.Terrain.UseCheckPoint(checkPoint);

        this.Background.AdjustMotion(this.Terrain.LevelLength);

        this.LevelAudio.Reset();
        this.LevelAudio.AddPlayerToMuteControl(this.Music);
    }
Exemplo n.º 2
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        gameStates = (GameStates)GetNode("/root/GAMESTATES");
        network    = (Network)GetNode("/root/NETWORK");

        _remoteTransform2D = (RemoteTransform2D)GetNode("CameraRemoteTransform");

        Particles2D smoke = (Particles2D)GetNode("Smoke");

        smoke.Emitting = false;

        CurrentInventory  = (Inventory)GetNode("Inventory");
        DamageEffectTimer = (Timer)GetNode("DamageEffectTimer");
        Body = (Sprite)GetNode("Body");

        _health = MaxHealth;
        _energy = MaxEnergy;

        CurrentWeaponIndex.Add(Weapon.WeaponOrder.Left, 0);
        CurrentWeaponIndex.Add(Weapon.WeaponOrder.Right, 0);

        EmitSignal(nameof(HealthChangedSignal), _health * 100 / MaxHealth);
        EmitSignal(nameof(EnergyChangedSignal), _health * 100 / MaxHealth);
    }
Exemplo n.º 3
0
    private async void UpdateRect()
    {
        edgeBodies = new Array <JellyAtom>();
        if (jellyAtomPacked == null)
        {
            return;
        }
        Vector2 atomSeparation = new Vector2(atomW > 1 ? rect.Size.x / (atomW - 1) : 0, atomH > 1 ? rect.Size.y / (atomH - 1) : 0);
        Vector2 origin         = rect.Position;

        foreach (Node n in GetChildren())
        {
            n.QueueFree();
        }
        mapAtoms = new Dictionary <Vector2, JellyAtom>();
        for (int j = atomH - 1; j >= 0; j--)
        {
            for (int i = atomW - 1; i >= 0; i--)
            {
                JellyAtom jellyAtom = (JellyAtom)jellyAtomPacked.Instance();

                Vector2 gridPos = new Vector2(i, j);
                jellyAtom.Position     = origin + atomSeparation * gridPos;
                jellyAtom.jelly        = this;
                jellyAtom.GravityScale = gravityScale;
                AddChild(jellyAtom);
                mapAtoms.Add(gridPos, jellyAtom);
                Vector2[] neighbours = new Vector2[] {
                    new Vector2(i + 1, j),
                    new Vector2(i, j + 1),
                    new Vector2(i + 1, j + 1),
                    new Vector2(i - 1, j + 1)
                };
                if (i == 3 && j == 3)
                {
                    foreach (Node n in GetTree().GetNodesInGroup("CameraOffset"))
                    {
                        Node2D            cameraOffset = (Node2D)n;
                        RemoteTransform2D rt           = new RemoteTransform2D();
                        rt.UpdateRotation = false;
                        rt.UpdateRotation = false;
                        rt.RemotePath     = cameraOffset.GetPath();
                        jellyAtom.AddChild(rt);
                    }
                }
                foreach (Vector2 neighbour in neighbours)
                {
                    JellyAtom neighbourBody;

                    if (!mapAtoms.TryGetValue(neighbour, out neighbourBody))
                    {
                        continue;
                    }

                    float dist = (neighbourBody.Position - jellyAtom.Position).Length();
                    neighbourBody.AddNeighbour(new Neighbour(jellyAtom, dist));
                    jellyAtom.AddNeighbour(new Neighbour(neighbourBody, dist));
                }
                //await ToSignal(GetTree(), "idle_frame");
            }
        }

        for (int i = 0; i < atomW; i++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, 0)]);
        }

        for (int j = 1; j < atomH; j++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(atomW - 1, j)]);
        }

        for (int i = atomW - 2; i >= 0; i--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, atomH - 1)]);
        }

        for (int j = atomH - 2; j >= 1; j--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(0, j)]);
        }
    }
Exemplo n.º 4
0
    private void UpdateRect()
    {
        edgeBodies = new Array <RigidBody2D>();
        if (jellyAtomPacked == null)
        {
            return;
        }
        Vector2 atomSeparation = new Vector2(atomW > 1 ? rect.Size.x / (atomW - 1) : 0, atomH > 1 ? rect.Size.y / (atomH - 1) : 0);
        Vector2 origin         = rect.Position;

        foreach (Node n in mapAtoms.Values)
        {
            n.QueueFree();
        }
        mapAtoms = new Dictionary <Vector2, RigidBody2D>();
        for (int j = atomH - 1; j >= 0; j--)
        {
            for (int i = atomW - 1; i >= 0; i--)
            {
                JellyAtomJoints jellyAtom = (JellyAtomJoints)jellyAtomPacked.Instance();
                Vector2         gridPos   = new Vector2(i, j);
                jellyAtom.Position     = origin + atomSeparation * gridPos;
                jellyAtom.GravityScale = gravityScale;
                jellyAtom.Radius       = atomRadius;
                jellyAtom.SetDraggable(draggable);
                AddChild(jellyAtom);
                mapAtoms.Add(gridPos, jellyAtom);
                int mX = (int)(atomW / 2);
                int mY = (int)(atomH / 2);
                if (i == mX && j == mY)
                {
                    center   = jellyAtom;
                    rayCasts = (Node2D)GD.Load <PackedScene>("res://tests/thibault/RayCasts.tscn").Instance();
                    AddChild(rayCasts);
                    RemoteTransform2D rt = new RemoteTransform2D();
                    rt.UpdateRotation = false;
                    rt.UpdateScale    = false;
                    rt.RemotePath     = rayCasts.GetPath();
                    jellyAtom.AddChild(rt);
                    foreach (Node n in GetTree().GetNodesInGroup("CameraOffset"))
                    {
                        Node2D cameraOffset = (Node2D)n;
                        rt = new RemoteTransform2D();
                        rt.UpdateRotation = false;
                        rt.UpdateScale    = false;
                        rt.RemotePath     = cameraOffset.GetPath();
                        jellyAtom.AddChild(rt);
                    }
                }
                else if (j == mY && i == atomW - 1)
                {
                    east = jellyAtom;
                }
                Vector2[] neighbours = new Vector2[] {
                    new Vector2(i + 1, j),
                    new Vector2(i, j + 1),
                    new Vector2(i + 1, j + 1),
                    new Vector2(i - 1, j + 1)
                };
                foreach (Vector2 neighbour in neighbours)
                {
                    RigidBody2D neighbourBody;

                    if (!mapAtoms.TryGetValue(neighbour, out neighbourBody))
                    {
                        continue;
                    }

                    JellyJoint joint      = new JellyJoint();
                    Vector2    separation = new Vector2(neighbourBody.Position - jellyAtom.Position);
                    joint.Position         = jellyAtom.Position;
                    joint.RestLength       = separation.Length();
                    joint.Rotation         = separation.Angle() - Mathf.Pi / 2;
                    joint.Length           = separation.Length();
                    joint.NodeA            = jellyAtom.GetPath();
                    joint.NodeB            = neighbourBody.GetPath();
                    joint.DisableCollision = false;
                    joint.Stiffness        = stiffness;
                    joint.Damping          = damping;
                    joints.Add(joint);
                    // RemoteTransform2D rt = new RemoteTransform2D();
                    // rt.UpdateRotation = false;
                    // rt.UpdateScale = false;
                    // joint.Scale = new Vector2(0.1f, 0.1f);
                    AddChild(joint);
                    // rt.RemotePath = joint.GetPath();
                    // jellyAtom.AddChild(rt);
                }
            }
        }

        for (int i = 0; i < atomW; i++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, 0)]);
        }

        for (int j = 1; j < atomH; j++)
        {
            edgeBodies.Add(mapAtoms[new Vector2(atomW - 1, j)]);
        }

        for (int i = atomW - 2; i >= 0; i--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(i, atomH - 1)]);
        }

        for (int j = atomH - 2; j >= 1; j--)
        {
            edgeBodies.Add(mapAtoms[new Vector2(0, j)]);
        }
    }
Exemplo n.º 5
0
 public override void _Ready()
 {
     _remoteTransform2D = (RemoteTransform2D)GetNode("CameraRemoteTransform");
 }