package com.roblox.ggj;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;

/**
 * Created by KaseiFox on 1/20/17.
 */

public class TrumpActor extends Actor {
    private Sprite sprite;
    private Vector2 velocity;
    private final float speed = 20.f * App.getPPU();

    TrumpActor() {
        sprite = App.createScaledSprite(new Texture("trump.png"));
        sprite.setX((Gdx.graphics.getWidth() - sprite.getWidth()) / 2.f);
        sprite.setY(5.f * App.getPPU());

        velocity = new Vector2();
    }

    @Override
    public void act(float delta) {
        if(Gdx.input.isTouched()) {
            float x = Gdx.input.getX();
            float y = Gdx.input.getY();

            if(!sprite.getBoundingRectangle().contains(x, y)) {
                float dx = x - (sprite.getX() + sprite.getWidth() / 2.f);
                float dy = y - (sprite.getY() + sprite.getHeight() / 2.f);

                velocity.set(dx, dy);
                velocity.setLength(speed);
            }
        } else velocity.setLength2(0);

        sprite.translate(velocity.x, velocity.y);
    }

    @Override
    public void draw(Batch batch, float parentAlpha) {
        sprite.draw(batch);
    }
}

@@ -47,16 +47,48 @@
 dx.Gdx;%0A
+import com.badlogic.gdx.Screen;%0A
 import c
@@ -468,17 +468,17 @@
 speed = 
-2
+4
 0.f * Ap
@@ -879,16 +879,43 @@
 loat y =
+ Gdx.graphics.getHeight() -
  Gdx.inp
@@ -921,25 +921,24 @@
 put.getY();%0A
-%0A
             
@@ -941,56 +941,121 @@
     
-if(!sprite.getBoundingRectangle().contains(x, y)
+float length = Math.abs(sprite.getX() + sprite.getWidth() / 2.f - x) / App.getPPU();%0A%0A            if(length %3E 5.f
 ) %7B%0A
@@ -1237,18 +1237,17 @@
 set(dx, 
-dy
+0
 );%0A     
@@ -1281,16 +1281,102 @@
 th(speed
+ * delta);%0A            %7D else if(length %3C 1.f) %7B%0A                velocity.setLength2(0
 );%0A     

update trump actor