Boundaries in java games, how do “professionals” do this?

How do professionals make boundaries in 2D games? My way is to say that I don't want elves to enter an area:

//Example
if ((playerPosX >= 825) && (playerPosX  <= 910)&& (playerPosY >= 170) && (playerPosY <= 255)) {
    //do nothing
}else{
    //move
}

But some games there have many boundaries, so I want to know if there is a simpler way I don't think anyone will use the above methods in the whole game just to prevent movement

Editor: my question is mainly about games where you can walk around, similar to Pokemon or final fantasy

Solution

I thought of two possibilities,

>1st describe the blocked area with polygons and make a point in the polygon test to determine whether the sprite can move to this position. > Like creating a mask (layer) in an image processing program, where the zero position represents the position that can be moved and the position of the blocking area This can be extended to the specified depth. See also z-buffer to partially hide the sprite,

Edit:

if ( mask[ nextY ][ nextX ] == 0 ) {
   currX = nextX;
   currY = nextY;
}

Suppose all variables are int and mask is 2D int array

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>