Doom (RPG Paper Maker version)
About
This was created as a proof of concept for a more accurate FPS type game in RPG Paper Maker. Doom was used because everything should have a little Doom in it.
This a project you can open in RPG Paper Maker ver 2.0.7 and above. You can play the first few rooms of a level, view the code to learn, or even build your own game using this as a starting point. You don't need to credit me, but it would be nice to get a mention somewhere. Link to here.
It's not overly polished so what is there needs a bit more work. There are bugs and comments to explain everything in the code.
-------------------------------------------------
The main idea is to change the camera turn amount to 1, and change a variable at the same time by the same amount. This creates 360 turning that is tracked by a variable. Currently an image of an arrow is drawn on the screen using this variable as it's rotation factor, showing you in real time your current angle. It's drawn in the center and also acts temporary crosshairs.
Divide that 360 by 4, and each 90 degree section corresponds to N E S W.
N= 0
E=90
S=180
W=270
4 Directions aren't very accurate. You could have the player hit anything in a 45 degree cone for each direction. But instead I divide that even further to get 15 sections for each direction. Each a little bit to the side of the last one. A variable tracks which section the camera is current looking at.
North
357-3 degrees = 0
4-9 degrees = +1
10-15 degrees = +2
and so on
Collisions in the database that consist of small boxes in a long line form the line of fire. 15 lines are created, each a little bit to the side all ranging from -7 to +7, to match the above variable. This is what lets you hit the object in the center of the camera, even though the main hero OBJ can only look in 1 of 4 cardinal directions.