Methods for creating a 2D game world

I want to make a 2D game in C ++ using Irrlicht . In this game you will control a tiny ship in a cave. This cave will be created automatically (the game will have random levels) and will look like this:

Cave

Suppose I already have polygon points inside a cave (white part). How should I display this figure on the screen and use it to detect collisions? From what I read on different sites, I have to use the triangulation algorithm to make the grid walls of the cave (the black part) using the polygon inside the cave (white part). Then I can also use these grids to detect collisions. Is this really the best way to do this? Do you know if Irrlicht has built-in functions that can help me with this?

Any advice would be appreciated.

+3
source share
3 answers

, 3D-, . , 3D- , , , , . , , , , . . .

, Irrlicht - , , , . ( , , .) , , , .

+3

- ( ) .

,

if map_points[sprite.x sprite.y] is black then
   collision detected

, , .

, " " ,
.

+1

To check if a point is inside or outside your polygon, you can simply count the transitions. You know that (0,0) is outside your polygon. Now draw a line from there to the test point (X, Y). If this line intersects an odd number of edges of the polygon (for example, 1), it is inside the polygon. If the line crosses an even number of edges (for example, 0 or 2), the point (X, Y) goes beyond the polygon. It is useful to run this algorithm on paper once to convince yourself.

+1
source

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


All Articles