Commodore 64 3D engine demo
I have made a small C64 program to see if I can make a 3D engine, just for fun. I never had an intention to build the full game engine or a game. But, since I already have something that is usable, I would like for somebody to use it.
The graphics display has 80x50 pixels resolution. Actually, the program uses PETSCII graphics, and all graphics in the 3D mode are made of 16 characters.
The program starts in the 2D view mode.
To switch to the 3D and back to the 2D view mode press the S
button.
Player can strife left and right by using Q
and W
buttons. Otherwise, use the joystick to control the player.
There are two "events" marked on the map - event A and event B. When the player steps on the cell marked with the letter A, the part of the wall will be painted, indicating a hidden passage. If you press the joystick button while on that cell, the wall will open. Event B is an example of an "open the door" event, or better to say "open the wall."
The project is written in the C64Studio software (https://www.c64-wiki.com/wiki/C64_Studio).
There is a precompiled version of the program "kick3d.prg" which you can run in your emulator or your C64 machine.
Start the C64Studio, select File > Open > Solution or project...
Browse until you find the "kick3d.s64" file and open it.
Select the "kick3d.asm" tab in the C64Studio and then select Build > Build and Run
from the menu.
If you have the VICE emulator set up to run by the C64Studio, the program will compile and run in the emulator.
The code could be faster than it is. I have opted to have a clean code rather than the fastest one. There are no self-modifying code sections. And I have commented on the code as best I could.
Software is broken into several modules.
This module is used as a manager module through which the program is assembled.
This module contains the main program loop, setup, and some global routines.
This module contains mathematical functions. And only three mathematical functions are used in this program: sine, cosine, and multiplication.
This module contains routines used to control the interaction with the user and control player actions. There are joystick control routines, keyboard control routines, and player map events control.
This module contains routines for graphics display.
Sprites control routines. For now, sprites are used in the 2D view and as background objects in the 3D view.
This is the ray casting routine. It casts a single ray and returns the cell the ray hits and distances.
This routine casts 40 rays and stores calculations in the buffer, which is later used by the display module. The engine was originally casting 80 rays, but that was too slow. So, I have created a system where every second ray is interpolated in between casted rays.
Just a basic interrupt scanline routine to create the effect of sky and grass by splitting the background color into two parts.
Sprites and maps information.
Various tables such as sine table, and calculation speed up tables.