Exemple #1
0
    private void UpdatePhysics()
    {
        WMath.Vector2 forceDirection = new WMath.Vector2(-Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        rigidbody.AddForce(forceDirection, Time.deltaTime);

        Position += rigidbody.Velocity;
    }
Exemple #2
0
    public Enemy(WMath.Vector2 position)
    {
        visual = Resources.Load <Texture2D>("pacman");

        Circle        = new WMath.Circle();
        Circle.Radius = visual.width * .5f;

        Position = position;
    }
    public Projectile(WMath.Vector2 position, WMath.Vector2 direction, float startVelocity, float acceleration)
    {
        visual = Resources.Load <Texture2D>("pacman");

        Circle = new WMath.Circle {
            Position = position,
            Radius   = visual.width * .5f * SCALE
        };

        velocity = startVelocity;
        accelerationPerSecond = acceleration;

        Direction = direction;
    }
Exemple #4
0
    public Player()
    {
        visual                   = Resources.Load <Texture2D>("pacman");
        Circle.Radius            = visual.width * .5f;
        AntiSpawnCircle.Position = Position;
        AntiSpawnCircle.Radius   = Screen.width / 2;

        pixel    = new Texture2D(1, 1, TextureFormat.RGBA32, false);
        Position = new WMath.Vector2(Screen.width * .5f - visual.width * .5f, Screen.height * .5f - visual.height * .5f);

        rigidbody = new WMath.Rigidbody()
        {
            mass            = 1.0f,
            force           = 150.0f,
            dragCoefficient = .47f
        };
    }
Exemple #5
0
    public void Update()
    {
        UpdatePhysics();

        var mousePos = new WMath.Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
        var mouseDir = (mousePos - Position).Normalized;

        Rotation = WMath.WMath.RadToDeg(WMath.Vector2.Angle(new WMath.Vector2(.0f, .0f), mouseDir));

        if (Input.GetKey(KeyCode.Mouse0))
        {
            chargeTime += Time.deltaTime;
        }
        else if (Input.GetKeyUp(KeyCode.Mouse0))
        {
            float p = WMath.WMath.Clamp(chargeTime, .0f, maxChargeTime) / maxChargeTime;
            Game.Instance.CreateProjectile(Position, Direction, WMath.WMath.Lerp(minProjectileStartVelocity, maxProjectileStartVelocity, p),
                                           WMath.WMath.Lerp(minProjectileStartAcceleration, maxProjectileStartAcceleration, p));

            chargeTime = .0f;
        }
    }
 public static Vector2 ToUnity(this WMath.Vector2 v)
 {
     return(new Vector2(v.x, v.y));
 }
Exemple #7
0
 public void CreateProjectile(WMath.Vector2 position, WMath.Vector2 direction, float startVelocity, float acceleration)
 {
     projectiles.Add(new Projectile(position, direction, startVelocity, acceleration));
 }