Exemplo n.º 1
0
    void loadBody(StadiumObject stadiumObject)
    {
        StaticBody2D body = new StaticBody2D();

        ImageTexture texture = new ImageTexture();

        texture.Load(stadiumObject.TexturePath);
        Sprite sprite = new Sprite();

        sprite.Texture = texture;
        if (stadiumObject.Shape == StadiumObject.Type.RECT)
        {
            sprite.Centered = false;
        }
        body.AddChild(sprite);

        float positionX = (float)(stadiumObject.ShapeStruct.Position.X);
        float positionY = (float)(stadiumObject.ShapeStruct.Position.Y);

        body.Position = new Godot.Vector2(positionX, positionY);

        if (stadiumObject.Shape == StadiumObject.Type.RECT)
        {
            body = loadRectBody(stadiumObject, body);
        }
        else
        {
            body = loadCircBody(stadiumObject, body);
        }


        AddChild(body);
    }
Exemplo n.º 2
0
        private void CreateRocks()
        {
            rng.Randomize();
            int cachedCount = floorTiles.Count;

            foreach (Vector2 tileCoord in floorTiles)
            {
                // Spawn a rock
                if (rng.Randf() < 0.2)
                {
                    StaticBody2D r = new StaticBody2D();

                    // Spawn ore instead
                    if (rng.Randf() < 0.2)
                    {
                        r = (StaticBody2D)basicOre.Instance();
                    }
                    else
                    {
                        r = (StaticBody2D)rocks[rng.RandiRange(0, rocks.Length - 1)].Instance();
                    }

                    rockTiles.Add(tileCoord);
                    r.GlobalPosition = tileCoord;
                    rockLayer.AddChild(r);
                }
            }

            // Lets other scripts know that the level is done generating
            EmitSignal(nameof(LevelGenerated), spawnPosition);
        }
Exemplo n.º 3
0
    public void DrawGameBoard()
    {
        Random random = new Random();
        int    i      = 0;

        while (i < BRICK_COUNT)
        {
            // instance new brick
            StaticBody2D brickNode = brick.Instance() as StaticBody2D;
            brickArea.AddChild(brickNode);
            //position brick relative to previous
            brickNode.Modulate = new Color(
                (float)random.NextDouble(),
                (float)random.NextDouble(),
                (float)random.NextDouble(),
                1f
                );
            brickNode.Position = new Vector2(
                (i % COL_COUNT * brickSizeVector.x) + INITIAL_OFFSET,
                (i / COL_COUNT) * brickSizeVector.y
                );

            i++;
        }
    }
Exemplo n.º 4
0
 public override void _Ready()
 {
     _collisionShape  = GetNode <CollisionShape2D>("CollisionShape2D");
     _leftWall        = GetParent().GetNode <StaticBody2D>("LeftWall");
     _rightWall       = GetParent().GetNode <StaticBody2D>("RightWall");
     _animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
 }
Exemplo n.º 5
0
    public BarrierActionPerformer(Node2D item) : base(item)
    {
        barrier = (StaticBody2D)item;

        HUD.ConfirmPressed += onConfirmPressed;
        HUD.DownPressed    += onDownPressed;
        HUD.UpPressed      += onUpPressed;
    }
Exemplo n.º 6
0
    public void AddStaticBodyCollider(Area2D prop)
    {
        var shape = prop.GetNode <CollisionShape2D>("Shape");

        var body = new StaticBody2D();

        body.AddChild(shape.Duplicate());
        body.CollisionLayer = 1024;
        prop.AddChild(body);
    }
Exemplo n.º 7
0
    /**
     * Handles inputs for the simulation
     */
    public override void _Input(InputEvent inputEvent)
    {
        //Adds a liquid particle to the mouse's position if the left mouse button is pressed
        if (Input.IsActionPressed("add_liquid_particle") && this._framesUntilNextLiquidParticleCreation == 0)
        {
            var liquidParticleInstance = (Node2D)this._liquidParticleScene.Instance();
            liquidParticleInstance.Position = this.GetViewport().GetMousePosition();
            this.AddChild(liquidParticleInstance);
            this._liquidParticles.Add((LiquidParticle)liquidParticleInstance);
            this._framesUntilNextLiquidParticleCreation = 5;
        }

        //If the right mouse button is being pressed, creates a blocker from the start of the press to the end of the press
        if (Input.IsActionPressed("add_blocker"))
        {
            if (this._blockerSegmentBeingPlaced == null)
            {
                this._blockerSegmentBeingPlaced = new SegmentShape2D {
                    A = this.GetViewport().GetMousePosition(),
                    B = this.GetViewport().GetMousePosition()
                };
                var body = new StaticBody2D();
                body.AddChild(new CollisionShape2D {
                    Shape = this._blockerSegmentBeingPlaced
                });
                this.AddChild(body);
                this._blockers.Add(this._blockerSegmentBeingPlaced);
                this.Update();
            }
            else
            {
                this._blockerSegmentBeingPlaced.B = this.GetViewport().GetMousePosition();
                this.Update();
            }
        }
        else
        {
            this._blockerSegmentBeingPlaced = null;
            this.Update();
        }

        //Removes all children if the escape key is pressed
        if (Input.IsActionPressed("clear_everything"))
        {
            foreach (var child in this.GetChildren())
            {
                this.RemoveChild((Node)child);
            }

            this._liquidParticles.Clear();
            this._springs.Clear();
            this._blockers.Clear();
            this.Update();
        }
    }
Exemplo n.º 8
0
    StaticBody2D loadRectBody(StadiumObject stadiumObject, StaticBody2D body)
    {
        CollisionShape2D collider = new CollisionShape2D();

        RectangleShape2D shape      = new RectangleShape2D();
        RectStruct       rectStruct = (RectStruct)stadiumObject.ShapeStruct;

        shape.Extents  = new Godot.Vector2((float)rectStruct.Position.X / 2, (float)rectStruct.Position.Y / 2);
        collider.Shape = shape;
        body.AddChild(collider);

        return(body);
    }
Exemplo n.º 9
0
    private void OnPlayPressed()                //resetting variables upon pressing, as well as generating the traps
    {
        winingLabel.Visible      = false;
        GameData.paused          = false;
        titleCam.Current         = false;
        titleCam.Visible         = false;
        Player.playerCam.Current = true;
        GameData.minutesLeft     = 1;
        GameData.secondsLeft     = 30;
        GameData.won             = false;
        GameData.dead            = false;
        GameData.gameOver        = false;
        Player.player.Position   = spawnPoint.GlobalPosition;
        for (int i = 0; i < GetChildCount(); i++)
        {
            Node potentialWeaponPoint = GetChild(i);
            if (potentialWeaponPoint.GetType().ToString() == "Godot.Position2D")
            {
                Position2D weaponPoint = potentialWeaponPoint as Position2D;
                if (weaponPoint.Name.Contains("Weapon"))                                //separating player spawn and weapon spawns
                {
                    switch (rand.Next(0, 4))
                    {
                    case 0:
                        Node2D weapon = (Node2D)weaponSet1.Instance();
                        weapon.GlobalPosition = weaponPoint.GlobalPosition;
                        weaponsContainer.AddChild(weapon);
                        break;

                    case 1:
                        Node2D weapon2 = weaponSet2.Instance() as Node2D;
                        weapon2.GlobalPosition = weaponPoint.GlobalPosition;
                        weaponsContainer.AddChild(weapon2);
                        break;

                    case 2:
                        StaticBody2D weapon3 = weaponSet3.Instance() as StaticBody2D;
                        weapon3.GlobalPosition = weaponPoint.GlobalPosition - new Vector2(24f, 0f);
                        weaponsContainer.AddChild(weapon3);
                        break;

                    case 3:
                        StaticBody2D weapon4 = weaponSet4.Instance() as StaticBody2D;
                        weapon4.GlobalPosition = weaponPoint.GlobalPosition - new Vector2(24f, 0f);
                        weaponsContainer.AddChild(weapon4);
                        break;
                    }
                }
            }
        }
    }
Exemplo n.º 10
0
    public void shoot(float delta)
    {
        begin.Visible = true;
        beam.Visible  = true;
        if (raycast.IsColliding())
        {
            end.GlobalPosition = raycast.GetCollisionPoint();

            float collision = (raycast.GetCollisionPoint() - raycast.GlobalPosition).Length() * 500 / 120;

            beam.Rotation = raycast.CastTo.Angle();

            var beamRegionRect = beam.RegionRect;
            var vector2        = beamRegionRect.End;
            vector2.x          = collision;
            beamRegionRect.End = vector2;
            beam.RegionRect    = beamRegionRect;

            var hit_collider = raycast.GetCollider();
            // Collide with a block
            if (hit_collider is TileMap)
            {
                BlockCollision(delta);
            }
            else if (hit_collider is StaticBody2D)
            {
                // Collide with a tree
                StaticBody2D s = (StaticBody2D)hit_collider;
                if (s.GetGroups().Contains("tree"))
                {
                    TreeCollosion(delta);
                }
            }
            else if (hit_collider is Ennemy_Fly)
            {
                EnemyCollision(delta);
            }
        }
        else
        {
            end.GlobalPosition = raycast.CastTo;

            beam.Rotation = raycast.CastTo.Angle();
            var beamRegionRect = beam.RegionRect;
            var vector2        = beamRegionRect.End;
            vector2.x          = raycast.CastTo.Length();
            beamRegionRect.End = vector2;
            beam.RegionRect    = beamRegionRect;
        }
        particule.Emitting = true;
    }
Exemplo n.º 11
0
 protected override void OnCantMoveStaticBody2D(StaticBody2D pared) //si "NO" podemos movernos recibe el cuerpo estatico y es un una pared.Este es un metodo que se sobreescribe
 {
     if (pared.IsInGroup("Wall"))                                   //si esta en el grupo suelo
     {
         food--;                                                    //en cada paso dismunuje la comida
         _FoodText.Text = "food " + food;                           //comida del jugador es disminuida
         hitWall        = (Wall)pared.GetParent();                  //con esto tendria que poder acceder al script que maneja ese piso para cambiar la figura al ser golpeado
     }
     if (hitWall != null)                                           //si el personaje esta chocando con un muro
     {
         hitWall.DamageWall(wallDamage);                            //descuento el hp al suelo,se me esta complicando entender el concepto de unity y pasarlo a godot
         //activo animación romper bloque
         playback.Travel("PlayerChop");                             //activo animación romper pared
     }
 }
Exemplo n.º 12
0
    StaticBody2D loadCircBody(StadiumObject stadiumObject, StaticBody2D body)
    {
        CollisionShape2D collider = new CollisionShape2D();

        CircleShape2D shape      = new CircleShape2D();
        CircStruct    circStruct = (CircStruct)stadiumObject.ShapeStruct;

        shape.Radius   = (float)circStruct.Size.X / 2;
        collider.Shape = shape;
        body.AddChild(collider);

        ImageTexture texture = new ImageTexture();

        texture.Load(stadiumObject.TexturePath);
        Sprite sprite = new Sprite();

        sprite.Texture = texture;
        body.AddChild(sprite);

        return(body);
    }
Exemplo n.º 13
0
        public override void _Ready()
        {
            ZAsRelative        = false;
            IsToBeDeleted      = false;
            AttackArea         = GetNode <Area2D>("Area2D");
            TowerBody          = GetNode <Sprite>("Body");
            TowerGun           = GetNode <AnimatedSprite>("Gun");
            ProjectileResource = GD.Load <PackedScene>(TowerType.ProjectilePath);
            TowerStateMachine  =
                new NodeStateMachine <BaseTower, DefaultTowerState>(this, _initialState,
                                                                    DefaultTowerState.Global);

            FirePeriod           = 1f / TowerType.FireRate;
            AttackRadius         = TowerType.AttackRadius;
            AttackDamage         = TowerType.Damage;
            ProjectileCollateral = TowerType.Collateral;
            _hasShot             = false;
            Targets          = new List <BaseEnemy>();
            CollisionBody    = GetNode <StaticBody2D>("StaticBody2D");
            PlayerCollision  = CollisionBody.GetNode <CollisionShape2D>("CollisionShape2D");
            ShootTimeCounter = FirePeriod;
        }
Exemplo n.º 14
0
        public override void _Ready()
        {
            ground_ray = GetNodeOrNull <RayCast2D>("Forge/RayCast2D");
            timer      = new Timer()
            {
                WaitTime = 60f
            };
            AddChild(timer);
            timer.Connect("timeout", this, "ClearItem");
            timer.Start();


            FireTimer = new Timer()
            {
                WaitTime = 5f
            };
            AddChild(FireTimer);
            FireTimer.Connect("timeout", this, "_on_fire");
            FireTimer.Start();

            staticBody2D = GetNodeOrNull <StaticBody2D>("Forge");
        }
Exemplo n.º 15
0
 public override void _Ready()
 {
     animationPlayer = GetNode <AnimationPlayer>("AnimationPlayer");
     body            = GetNode <StaticBody2D>("StaticBody2D");
     Visible         = false;
 }
Exemplo n.º 16
0
 //Esto es relacionado al movimiento y al tipo de obstaculo
 protected abstract void OnCantMoveStaticBody2D(StaticBody2D go); //aqui viene el comportamiento luego de no poder moverse,es un meotdoABstracto ya que se va a comportar de diferente manera según sea el personaje o elenemigo
Exemplo n.º 17
0
    public override void _Process(float delta)
    {
        planet = FindClosestPlanet() as StaticBody2D;

        // Define up
        normalDetector.LookAt(planet.GetGlobalPosition());
        if (normalDetector.IsColliding() && (planet as Planet).nonCircular)
        {
            up = normalDetector.GetCollisionNormal();
        }
        else
        {
            up = -Position.DirectionTo(planet.GetGlobalPosition());
        }
        right = -up.Tangent();


        if (launched && normalDetector.IsColliding())
        {
            launched = false;
        }

        LookAtPlanet(delta * 4);

        float pDistance = planet.GetGlobalPosition().DistanceTo(Position);
        float zoom      = Mathf.Pow(pDistance * 0.0015f, 1.2f) + 1;

        zoom = Mathf.Clamp(zoom, 1, 3);
        GetNode <Camera2D>("Camera2D").SetZoom(new Vector2(zoom, zoom));

        // Gravity
        if (!OnFloor())
        {
            SetLocalVel(new Vector2(GetLocalVel().x, GetLocalVel().y + G * delta));
        }
        else
        {
            SetLocalVel(new Vector2(GetLocalVel().x, 10));
        }

        // Jump
        if (Input.IsActionJustPressed("jump") && OnFloor())
        {
            vel += up * 700;
        }

        float movVel    = Input.GetActionStrength("right") - Input.GetActionStrength("left");
        float runspeed  = Input.GetActionStrength("run") * 250;
        float targetVel = movVel * (300 + runspeed);

        if (!launched)
        {
            SetLocalVel(new Vector2(Mathf.Lerp(GetLocalVel().x, targetVel, delta * 10), GetLocalVel().y));
        }
        else if (OnFloor())
        {
            launched = false;
        }


        // Animation
        AnimatedSprite sprite = GetNode <AnimatedSprite>("Sprite");

        if (!OnFloor())
        {
            sprite.SetAnimation("jump");
        }
        else if (movVel != 0 && runspeed > 0)
        {
            sprite.SetAnimation("walk");
            sprite.SpeedScale = 2;
        }
        else if (movVel != 0)
        {
            sprite.SetAnimation("walk");
            sprite.SpeedScale = 2;
        }
        else
        {
            sprite.SetAnimation("default");
        }

        if (movVel < 0)
        {
            sprite.FlipH = true;
        }
        else if (movVel > 0)
        {
            sprite.FlipH = false;
        }

        MoveAndSlide(vel);
    }
Exemplo n.º 18
0
 public override void _Ready()
 {
     planet         = GetNode("../Planets/initialPlanet") as StaticBody2D;
     normalDetector = GetNode <RayCast2D>("NormalDetector");
     checkpoint     = Position;
 }
Exemplo n.º 19
0
 protected override void OnCantMoveStaticBody2D(StaticBody2D go)//sino puede moverse por un cuerpo statico osea esto seria los obstaculos que estan en medio del escenario
 {
 }