开发者

Obstacle path detection for 2D game

开发者 https://www.devze.com 2023-01-16 13:12 出处:网络
I\'m pretty much working on a platformer and still starting out so I was curious about best practices/algorithms. I have in my background just a castle and about 200px high at the bottom some grass wh

I'm pretty much working on a platformer and still starting out so I was curious about best practices/algorithms. I have in my background just a castle and about 200px high at the bottom some grass which 开发者_Go百科slightly curves up and down. In the middle (which is part of the background png) I have a rounded rectangle rock. So nothing is its own seperate object, just the character and the background.

Currently, I set up the path my character goes as initializing an array of colors and loading up a path coordinate dictionary. The way I do it is I go through each pixel on the x-axis and go down (so like (0,1), (0,2)... then (1,0), (1,1)...). The first instance I find of a RGB value of near green, I store the preceeding y value into the path coordinate dictionary. So a value of pathDictionary[0]=>563 would be the grass while 562 would be the black above the grass or the path.

For the rock in the middle, I simply have a condition where I see if my x-coordinate is beyond a certain point and if the y-coordinate minus the origin of my character is greater than a value indicating that the character met the rock in the background. This is obviously not an approach I'd use everywhere but I'm wondering if there is a more efficient way? Perhaps looking at the png, getting the coordinates of the rock and creating a rectangle?

Based on what you guys recommend, what would be the best way for jumping onto this background rock?


I was recently introduced to the Sonic Physics Guide which is information reverse engineered out of the Sonic the Hedgehog series of games. It may have a lot of useful information for your quest.

0

精彩评论

暂无评论...
验证码 换一张
取 消