Advertisement

beginner with direct X 9: needed some programming advice

Started by July 07, 2019 04:06 PM
1 comment, last by Dawoodoz 5 years, 5 months ago

Hello.

I'll start explaining my core game concept and I would be appreciated if help me understand and how to implement such functionality. ill be using DirectX 9 by the way.

my game is top-down style game with 8 movement direction(like Hotline Miami), the player will be controlling a mining space ship or a robot with a drill attached to it.

the player will fly around and drill through the asteroids to gather resources. the stage cleared if the player meets the job quota.

I want the player to have free movement control while digging through the asteroid. I have been searching for polygon/texture dividing or splitting with little result.

I have also been trying to implementing Pixel perfect collision detection based on this article but I seem to hit a wall, it seems to be that SPRITE class isn't recognizable in DirectX 9.

the effect I'm trying to create is smaller to terrain destruction from the game worms or lemmings. here is a demonstration of the effect made with GameMaker.

 https://forum.yoyogames.com/index.php?threads/solved-lemmings-style-destructable-terrain.26288/ 

 

Shape representation
Generate a distance transform (https://en.wikipedia.org/wiki/Distance_transform) from each character frame and derive along X and Y separately to find the shape's skeleton (https://en.wikipedia.org/wiki/Morphological_skeleton) using local non-maxima supression. The skeleton combined with the distance transform can be reversed by drawing a circle using the distance transform's radius for each pixel in the skeleton. To make it faster, keep a sparse list of spheres after filtering away spheres that are overlapping too much. To make it more stable, you should also filter away the smallest spheres that have no stable direction. A final skeleton of 5 spheres should be enough to get close to the pixels and still be stable. Additional types of collision shapes can be added for smooth surfaces, but 2D spheres is simplest to begin with.

World collision
Let the obstacle layer generate another distance transform where each pixel's value tells the distance or 2D offset to the closest point. The closest point then creates a line of collision which gives the direction. The sphere's radius minus the collision length gives the pressure for the force and friction. When obstacles changes for a region, updated the distance transform for a larger region by padding with the combined kernel size of the filter. Spheres can then collide with the obstacles up to the largest allowed radius.

Physics
Use fixed time-steps of around 120 to 600 steps per frame to make sure that physics remain stable even if graphics is lagging or the computer is too fast for the used floating-point precision. Use the velocity to interpolate the visible location if it looks shaky from using fixed steps.

Line intersection
When moving bullets very quickly, you can iterate forward faster using larger spheres that shrink when getting close to an obstacle.

Sprites
Draw sprites by uploading a texture atlas ahead of time and render quads with texture coordinates (0.0 to 1.0 scale) selecting the correct image to be drawn.

Instancing
If you have lots of sprites to be drawn, you might have to use hardware instancing or upload a dynamic vertex buffer to reduce the call overhead. You can also draw things on the CPU and then upload images to the GPU, which makes it easier to make things pixel-exact. The GPU is then used for moving the camera, deferred light and bloom effects.

This topic is closed to new replies.

Advertisement