Hands-On Game Development with WebAssembly
上QQ阅读APP看书,第一时间看更新

Rectangle collision detection

Rectangle collision detection is another fast collision detection method. In many cases, it may be faster than circle collision detection. A rectangle collider is defined by an x and a y coordinate that is the position of the top left corner of our rectangle, as well as a width and a height. Detecting a rectangle collision is pretty straightforward. We look for an overlap on the x axis between the two rectangles. If there is an overlap on the axis, we then look for an overlap on the axis. If we have an overlap on both axes, there is a collision. This technique works pretty well for a lot of old-school video games. Several classic games released on the Nintendo Entertainment System used this method of collision detection. In the game we are writing, we are rotating our sprites, so using traditional non-oriented collision detection will not be useful for us.