Using SolidObjects to detect collisions

In addition to the Building object, we will define an object for the player and also define two objects to mark the start and end points of the maze. Although the player's view is the first person viewpoint (that is, we don't actually see them since the view is effectively through their eyes), we need to define a SolidObject to represent them.

A SolidObject is a special type of invisible object that can be checked to determine if the space that would be occupied by one SolidObject has overlapped another. This will allow us to use person.CollisionList(NewPos) to get a list of any other SolidObjects that the person object will be in contact with at the NewPos position. Since the Building class defines SolidObjects for all of the parts of the Building object, we will be able to detect when the player tries to move through a wall (or, for some reason, the roof/ceiling) and stop them from moving through it.

We also use SolidObjects for the start and end locations in the maze. The place where the player starts is set as the top-left corner of the map (the white-space pixel from the top left of the map) and is marked by the startpos object (a small pi3d.Sphere with the rock1.jpg texture) placed above the person's head. The end of the maze is marked with another pi3d.Sphere object (with the water.jpg texture) located at the center of the map. We also define another SolidObject at the end so that we can detect when the player reaches it and collides with it (and load the next level).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.255.140