Collision Detection in Java for the game

I am making a Java game with several other people, but we are stuck on one part of it, making collision detection. The game is an RPG, and I know how to do collision detection with characters using Rectangles, but what I don't know how to do is conflict detection for maps. What I mean is that the character cannot walk on trees or water, and this substance, but using rectangles, does not seem to be the best option here.

Well, to explain how game cards look, here is an example http://i980.photobucket.com/albums/ae287/gordsmash/7-8.jpg

Now I could use the rectangles to get the borders and stop the player from walking through the trees and water, but it will take a lot of them.

But is there another easy way to prevent a player from walking through trees and obstacles besides using Rectangles?

+3
source share
3 answers

Here's a simple way, but it uses more memory, and you do the work ahead ... just create a focal collision mask that denotes valid areas for characters that will walk in binary form. You can save this as a compressed raster shape. Then the search is very simple and very fast.

+1
source

, , ; , , , . , , , . , , .

! , , , . : (http://www.staff.ncl.ac.uk/qiuhua.liang/Research/Pic_research/mine_grid.jpg), , , .

- , , , .

Quadtree, , .

, , .

0

, , , , . ( RPG SNES), / .

, 2D-, ( ) , , , (, , , , ). ( O (n ^ 2)). , . , , , , , , 32x32 .

Although I personally have no experience with Java models, it looks like Mappy supports Java, and I heard good things about PulpCore . Of course, you can more than create your own engine, but you need to decide whether it is better to spend your time inventing the wheel (but, of course, it will be your wheel, which is quite satisfactory) or spending your time makes the best game.

0
source

Source: https://habr.com/ru/post/1796504/


All Articles