Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Day 3: Let there be light!

I’m satisfied with how my lighting system came out! This is my first time seriously working with GameMaker’s surfaces and blend modes. I recall a time when the now seemingly simple math behind these systems mystified me. It’s heart-warming seeing how far I’ve come!

In creating this system, I hit a program design issue: how can “regular” game objects be differentiated by “light source” objects. I can’t use GameMaker’s inheritance system because there would be overlap between my object parent/child hierarchies and GameMaker doesn’t have multiple inheritance (to my knowledge anyway) like Java’s interfaces, which would be perfect for this situation.

I’m sure I could do something fancy like check if light source required functions are defined/undefined in a given instance, but I didn’t want to fall into a rabbit hole creating a large framework from scratch. My solution is to just put the object indexes of “Light Source” objects into a global (assumed constant) array:

Each of these objects are expected to have the following functions defined (but this is not enforced!) like here in the PlayerSeed object:

The actual drawing of light sources is currently inefficiently using double iteration each game frame. I iterate once through all active instances (in GameMaker, this includes my game engine objects, invisible “marker” objects, etc., things that most definitely not produce light), then iterate again against the aforementioned global list of “light sources” to ensure that the currently considered instance is indeed a “light source”. If so, a light is drawn.

I’ll likely optimize this functionality by maintaining a list of Light Sources as they are created and destroyed, requiring only a single iteration through entities. However, because there aren’t too many instances in this game at one time (~15 instances * 5 Light Sources * 60 FPS = 6000 iterations per second, drawing lighting once per game frame), this optimization isn’t super necessary.