Example #1
0
    public void Reset()
    {
        Position     = Vector3.up * 9999f;
        Velocity     = Vector3.zero;
        Acceleration = 0f;
        ElapsedTime  = 0f;
        LastWorldPos = CurWorldPos = Vector3.zero;
        foreach (Affector affector in AffectorList)
        {
            affector.Reset();
        }

        if (Type == 1)
        {
            Sprite.SetRotation(OriRotateAngle);
            Sprite.SetPosition(Position);
            Sprite.SetColor(Color.clear);
            Sprite.Update(true);
            Scale = Vector2.one;
        }
        else if (Type == 2)
        {
            Ribbon.SetHeadPosition(ClientTrans.position + OriDirection.normalized * Owner.TailDistance);
            Ribbon.Reset();
            Ribbon.SetColor(Color.clear);
            Ribbon.UpdateVertices(Vector3.zero);
        }
    }
 public Enemy(TextureManager textureManager)
 {
     _spaceship.Texture = textureManager.Get("enemy_ship");
     _spaceship.SetScale(_scale, _scale);
     _spaceship.SetRotation(Math.PI); // make it face the player
     _spaceship.SetPosition(200, 0);  // put it somewhere easy to see
 }
Example #3
0
    public override PlayerState FixedUpdate(float delta)
    {
        player.MoveAndSlide(player.Velocity);
        player.Velocity.x *= 0.9f;
        player.Velocity.y += 100 * delta;

        reticule.SetPosition(64 * (player.GetGlobalMousePosition() - player.GetGlobalPosition()).Normalized());
        reticuleSpr.SetRotation(Mathf.PI / 2 + reticule.GetPosition().Angle());

        if (!Input.IsActionPressed("CommandHook"))
        {
            return(new HookThrowState());
        }
        return(null);
    }
Example #4
0
    public override void Enter()
    {
        DestroyHook = false;

        player.Velocity *= 0.5f;
        player.MoveAndSlide(player.Velocity);

        reticule    = new Node2D();
        reticuleSpr = new Sprite();

        reticule.SetName("Reticule");
        reticule.SetPosition(64 * (player.GetGlobalMousePosition() - player.GetGlobalPosition()).Normalized());
        reticuleSpr.SetTexture((Texture)ResourceLoader.Load("res://Player/HookReticule.png"));
        reticuleSpr.SetRotation(Mathf.PI / 2 + reticule.GetPosition().Angle());

        player.AddChild(reticule);
        reticule.AddChild(reticuleSpr);
        base.Enter();
    }
Example #5
0
    // Add an explosion into the list (will remove self once complete)
    public void AddExplosion(Vector2 Position)
    {
        // Allocate and register the new sprite, starting with the explosion
        // Note: slight randomization to add effect
        Sprite Explosion = new Sprite("Textures/ExplosionSprite" + UnityEngine.Random.Range(0, 2)); // [0, 1]
        Explosion.SetPosition(Position);
        Explosion.SetAnimation(Vector2.zero, new Vector2(20, 20), 7, 0.06f + UnityEngine.Random.Range(-0.01f, 0.05f));
        Explosion.SetGeometrySize(Explosion.GetSpriteSize() * (0.6f + UnityEngine.Random.Range(-0.2f, 0.2f)));
        Explosion.SetRotationCenter(Explosion.GetGeometrySize() / UnityEngine.Random.Range (1.0f, 2.0f));
        Explosion.SetRotation(UnityEngine.Random.Range(0.0f, 2.0f * Mathf.PI));
        Explosion.SetDepth(Globals.ExplosionDepth);

        // Register to renderer and list
        Globals.WorldView.SManager.AddSprite(Explosion);
        Explosions.Add(Explosion);

        // Add explosion audio
        int Index = UnityEngine.Random.Range(1, 4); // [1, 4)
        Globals.WorldView.AManager.PlayAudio(Position, "Explosion" + Index);
    }
Example #6
0
    void RotatePlayer(Sprite sprite)
    {
        Vector2 rotate = new Vector2(
            Input.GetJoyAxis(_playerOptions.playerNumber - 1, 2),
            Input.GetJoyAxis(_playerOptions.playerNumber - 1, 3));

        if (rotate.Length() < _JOYPAD_DEADZONE)
        {
            rotate = new Vector2(0, 0);
        }
        else
        {
            rotate = rotate.Normalized() *
                     ((rotate.Length() - _JOYPAD_DEADZONE) / (1 - _JOYPAD_DEADZONE));
        }

        if (rotate.Length() > 0)
        {
            sprite.SetRotation(rotate.Angle() - _ROTATION_OFFSET);
        }
    }
Example #7
0
//  // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(float delta)
    {
        this.Position += GRAVITY;
        // Called every frame. Delta is time since last frame.
        // Update game logic here.
        velocity = new Vector2();
        if (Input.IsActionPressed("ui_right") || Input.IsKeyPressed((int)KeyList.D))
        {
            velocity.x += VELOCITY;
            (GetNode("chicken") as Sprite).SetFlipH(true);
        }

        if (Input.IsActionPressed("ui_left") || Input.IsKeyPressed((int)KeyList.A))
        {
            velocity.x -= VELOCITY;
            (GetNode("chicken") as Sprite).SetFlipH(false);
        }

        if (Input.IsActionPressed("ui_down") || Input.IsKeyPressed((int)KeyList.S))
        {
            targetRotation -= 0.05;
        }


        if (Input.IsActionPressed("ui_up") || Input.IsKeyPressed((int)KeyList.W))
        {
            targetRotation += 0.05;
        }

        this.Position += velocity;

        target.SetRotation((float)targetRotation);
        target.SetPosition(new Vector2(targetRadius * (float)Math.Cos(targetRotation), targetRadius * (float)Math.Sin(targetRotation)));


        //this.SetPosition(this.Position);
        MoveAndCollide(velocity);
    }
Example #8
0
    // Add glow ontop of what is being fired
    public void AddGlow(Vector2 Position)
    {
        // Sprite info
        Vector2 GlowPos = ProjectileInfo.GetKey_Vector2("Glow", "Pos");
        Vector2 GlowSize = ProjectileInfo.GetKey_Vector2("Glow", "Size");

        // Allocate and register the new sprite
        // Note: slight randomization to add effect
        Sprite Explosion = new Sprite("Textures/Projectiles");
        Explosion.SetAnimation(GlowPos, GlowSize, 1, 1.0f);

        // Set in-world properties
        Explosion.SetPosition(Position);
        Explosion.SetGeometrySize(Explosion.GetSpriteSize() * (0.6f + UnityEngine.Random.Range(-0.2f, 0.2f)));
        Explosion.SetRotationCenter(Explosion.GetGeometrySize() / 2.0f);
        Explosion.SetRotation(UnityEngine.Random.Range(0.0f, 2.0f * Mathf.PI));
        Explosion.SetDepth(Globals.ExplosionDepth);

        // Register to renderer and list
        Globals.WorldView.SManager.AddSprite(Explosion);
        Glow.Add(Explosion);
    }