mpizenberg / elm-videoball

Minimalist elm implementation of the game videoball (not affiliated to official game)
https://mpizenberg.github.io/elm-videoball/
Mozilla Public License 2.0
4 stars 1 forks source link

Collisions #4

Closed mpizenberg closed 6 years ago

mpizenberg commented 6 years ago

A bit intertwined with game logic but hey, deserves its own issue ;)

The idea is probably to have it's own module, and describe the effects of collisions with a data type. This type could be used as a return value of functions of this module to describe the result of checking for collision so that the caller code can decide on what to do. You probably have alternative ideas on how to do that, experiment freely ^^.

For the physical models of things, I guess a simple implementation would be to consider only:

mpizenberg commented 6 years ago

Handling of collisions is done in two steps:

  1. Detect all collisions that will happen between this frame and the next one. Store their collision time and ids of the colliding entities. This is done in the function Data.Game.allCollisions.
  2. Process sorted collisions and apply transformations to the game one after the other. This happen by folding on the collisions list with the function Data.Game.processCollision.

It is an approximation because collisions are not recomputed for elements altered by previous collisions in the list.

It mostly works well. There are some issues left for player/ball collisions where players can get "trapped" in a ball.