|Top Previous Next|
This month's "Plug and play" section includes two different snippets that allow us to add a trial mode to our game demos.
The first method uses Acknex's built-in sys_trial instruction, which allows us to run the game for a specified number of days. Sys_trial creates an entry in the registry that can look like this:
sys_trial("Software\\Aum74\\SysTrialDemo", "install", 1)
Run systrial.exe from inside the systrial.cd folder; you will be greeted by a window that looks like this:
I have set the trial expiration date to a single day in order to be able to test how sys_trial works; you should set it to 30 days (or so) for the final version of your game. The "game" that comes with the sys_trial demo is a tiny drawing application; I had to draw a picture of me:
Draw as many pictures as you want today, because the program won't run tomorrow:
The second method is a 60 minute trial, which allows the potential customer to run the game for only 60 minutes. This method is used more often when it comes to game development because if you set even a modest 7 day trial period for your game, some people could finish the entire game sooner than that.
My trial method uses an API function - GetWindowsDirectory - to get Windows' installation directory and hides a file which stores the number of minutes that have been spent playing the game inside Windows' folder. Start the demo by running apitrial.c - you will see something like this:
You can hide the 3 lines at the bottom of the screen; they belong to a debugging panel that's intended for our use only. The "game" consists of a simple loop that changes the background color every 5 seconds. Whenever you shut down the game, the number of minutes that were spent playing (in fact, watching) the demo is added to the initial number of minutes.
Here's a picture of the screen after 19 minutes of play.
A separate loop checks if the trial has expired while the player is running the game and (if this is the case) it displays a proper message.
All the attempts to run the expired demo will make this window pop out:
You can simply delete the aum74trial.dat file from inside your Windows installation folder if you want to get another 60 minutes of furious gameplay. I would choose a weird file name (such as ym33.tdp, etc) for the hidden trial file and I would encrypt the number of played minutes (right now we've got the plain numerical value inside the file); this would complicate the things for those villains that are trying to crack and spread your masterpiece.
The code is fully commented, so all you need to do now is to create that killer game - the trial code is anxiously waiting for it...