Most effective way of creating barriers in a top-down game
Hello, so I figured out how to embed Jars if anyone remembers that dilemma XD
Anyways I'm creating a top down RPG-ish sort of thing and have been wondering what the most efficient way of creating impassable blocks is. I have created my own code that works, sorta:
//Called to update the position of the player's position and rectangle
public void move(boolean left, boolean right, boolean up, boolean down)
rect = new Rectangle(x, y, w, h);
x -= speed;
x += speed;
y += speed;
y -= speed;
//Called to pass down "legacy" positions.
public void updateP()
px2 = px;
py2 = py;
px = x;
py = y;
The problem is that it vibrates a bit when you try to walk into a wall. It isn't really too big of a problem, but I was guessing there was a better way.
//Updating "legacy" positions of player.
//Updating current position and rectangle of player.
p.move(kb.left, kb.right, kb.up, kb.down);
//Detects collisions between Player and blocks
for(int i = 0; i < block1.length; i++)
for(int j = 0; j < block1.length; j++)
//Sets the player's position to what it was two cycles ago.
p.x = p.px2;
p.y = p.py2;