I am rewriting the Bad Roads game with pygame, for AI research, having extracted the assets from the APK file. I have the truck images and the background:
How do I set the truck to run on the road, recognizing the black edge as the road?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
Note: I'd suggest to create your own, instead of ripping these off the original game. That will give you more control, and will avoid any copyright issues.
how to recognize the black edge as the road?
You don't, well, sort of.
You need an array with the heights of the terrain, such that you can use it to query for the ground at any given X coordinate.
You may want to process the image to get the heights, which would be done by going column by column, from left to right, checking the color of the pixels and exporting them to a file that you would then use in your code.
From watching the promotional video for the game you claim to attempt to clone, the terrain is not meant to be smooth. That means that working with a lower resolution and doing interpolation won't replicate the effect correctly.
Another thing to notice is that the trees are not obstacles. The approach above will have a problem with the trees because in the image the trees share color with the floor.
You can identify the trees rather easily (either by hand or by looking for picks in the data), what to replace them with? You can approximate the height of the ground where there is a tree by interpolating the surroundings.
In practice the heigh map is not the image, the image is just a visual representation for the user, but it is not mechanically relevant.
Note: the promotional video also shows the truck hitting a water tower, I'd suggest to place the coordinates for such obstacles by hand. Dealing with collisions is beyond the scope of this answer.