Let’s Make: Traffic Department 2192 – Part 24

Prototyping - Gameplay Map Programming

We have to modify the map files and bring them in to GameMaker using text reads for HTML5 compatability. While reading the files, we'll create both the sprite map and a collision map based on the values. We'll test the map drawing both with and without VRAM.


We can implement the world and view using two objects:

Concept Object Notes
Map display obj_map Loads and holds data for the scene. Spawns child objects as necessary
Camera obj_camera Displays a text-only line in large font centered on the screen


C Code

We have to convert all of the map files from the original traffic department to a format that's safe for ASCII / UTF8 reads. Since all map files have a maximum byte value of 80, we have plenty of room to move byte values up in to a valid range.




GML Code

We do our GameMaker work in GML for each object and event

obj_map: Create 1

Set a reference to the gamedata object


obj_map: Create 2

Initialize variables for map size, draw trigger, and draw mode


obj_map: Create 3

Create the data structures


obj_map: Create 4

Load the map data from our ASCII-safe files. We'll also create the collision map for certain sprites


obj_map: Destroy 1

Release all data structures


obj_map: Draw 1

The RAM only drawing of the map (slow)


obj_map: Draw 2

Storing the map in VRAM method (fast)


obj_camera: Create 1

Register the keyboard so we can control the camera


obj_camera: Create 2

Variables and other properties. The most important is the camera target, which we can lock to anything. For now, we'll lock it to itself


obj_camera: Destroy 1

Remove keyboard


obj_camera: Step 1

Process input commands. Camera only responds to controls when it's not locked to another object


obj_camera: End Step 1

Lock camera to target


obj_camera: Room Start 1

Find the player's ship