hi guys I'm trying to make a game just like the atari classic arcade but how can I make a wall at the edges of the screen smth. like
if(playerthoucheswall)
{
don'tpass
}
int x=getX(), y=getY(); //-- insert moving code here if (isTouching(Wall.class)) setLocation(x, y);
int halfWidth = getImage().getWidth()/2; if (getX() < halfWidth) setLocation(halfWidth, getY()); if (getX() > getWorld().getWidth()-halfWidth) setLocation(getWorld().getWidth()-halfWidth, getY());
//Reference
Actor ActorName = getOneIntersectingObject(ActorName.class);
if (ActorName != null) // Checks if the Player/Enemy is touching the wall
setLocation(getX(), getY()); //Change to the opposite of the regular speed (i.e. getX + 6 turns into getX - 6)
//Example IF Wall is above (this piece of code goes into the same method allowing the actor to move in the first place)
Actor Wall = getOneIntersectingObject(Wall.class);
if (Wall != null)
setLocation(getX(), getY() + Speed); //Speed can be a Variable or straight integer (number)
//Example IF It's an AI/Enemy (assumes movement is set in a method and assume bounce is only up and down)
private boolean Bounced = false;
...
if (Bounced == false) //Moving up
{
setLocation(getX(), getY() - Speed);
Actor Wall = getOneIntersectingObject(Wall.class);
if (Wall != null)
Bounced = true;
}
else //Moving Down
{
setLocation(getX(), getY() + Speed);
Actor Wall = getOneIntersectingObject(Wall.class); //can be replaced to check for Y = 0;
if (Wall != null)
Bounced = false;
}