简体   繁体   中英

Checking for same condition with incremented value over and over again

I am currently creating a very basic RPG game in java. I am currently working on collision, and this brings me to collision checking and my question:

Is it possible to check for a condition on 'foo' and 'foo' incremented a lot of times without making a mess like this

if(!Level.getTile((x) / 16, (y-8) / 16).solid() && !Level.getTile((x+1) / 16, (y-8) / 16).solid() && !Level.getTile((x+2) / 16, (y-8) / 16).solid())

It depends entirely on the methods Level.getTile and solid . Depending on how it works, there may be possible to have an efficient implementation of

boolean Level.isAnyTileSolid(int y, int x, ....)

That is, a method that takes one y value and several x values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM