Trying to make a TweenMovement component

I’m getting an unwanted teleporting effect and the fact that It will not walk unless i press the button again isnt anything I have wrapped my head around though.

Help would be appriciated.

I’m using Slick2d library and this entity component system http://slick.cokeandcode.com/wiki/doku.php?id=entity_tutorial

Here’s the code:

package rpggame.component.movement;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

import rpggame.component.Component;


public class TopDownMovement extends Component {

	float speed;
	float direction;
	Vector2f targetPosition;

	
	boolean headingUp = false;
	boolean headingDown = false;
	boolean headingLeft = false;
	boolean headingRight = false;
	
	
	public TopDownMovement(String id)
	{
		
		this.id = id;
		
	}
	
	public float getSpeed()
	{
		
		return speed;
	
	}
	
	public float getDirection()
	{
		
		return direction;
	
	}
	
	public boolean checkMoving()
	{
		if(!headingUp || !headingDown || !headingLeft || !headingRight)
		{
			 System.out.println("Isnt moving");
			 return false;
		}
		
		return true;
	}
	
	public void movement(GameContainer gc, int delta)
	{
		Input input = gc.getInput();
		Vector2f currentPosition = owner.getPosition();
		if(!checkMoving())
		{
			if(input.isKeyPressed(Input.KEY_W))
			{
				headingUp = true;
				targetPosition = currentPosition;
				targetPosition.y -= 32;
				advance(delta);
			}
		}
		else{
			advance(delta);
		}
	}
	
	public void advance(int delta)
	{
		Vector2f currentPosition = owner.getPosition();
		if(headingUp)
		{
			if(currentPosition != targetPosition)
			{
				currentPosition.y -= 1 * delta;
			}
			else{
				headingUp = false;
			}
		}
	}
	

	
	public void update(GameContainer gc, StateBasedGame sb, int delta)
	{
		
		movement(gc, delta);
		
	}
	
	
	
}

When a button is pressed, assign new target point to an entity and update them to move slowly (by using tick/delta) until they reach that target and stop.

Your if statement in checkMoving() is wrong. You should be using && instead of ||.

However, that won’t result in any change until you implement the other 3 directions in movement(…). Your whole design is faulty. Listen to ReBirth :slight_smile:

lol hi! :smiley: You’re the nehifish I know, right!?

I can help you over skype or something, lol.