Advanced graphics for Inform 7

Archive for the ‘How-To’ Category

How-To: Make an Analog Clock with Sweep Second Hand using Glimmr

Image of clock face created by this how-toBuried in Glimmr Drawing Commands, the bedrock Glimmr extension responsible for drawing images directly to the screen, is a set of commands for drawing lines using an angle plus a distance. This allows us to, for example, specify a line by saying “draw a line 20 pixels long from (0,0) on a heading of 30°.” I personally haven’t made much of use of this feature; I just thought that it might be useful given the emphasis of IF on compass directions–north being 0°, east 90°, and so on–and decided to throw it in. Something else this kind of thing is good for, though, is clocks. Since I’ve been thinking a little bit about timed events in IF lately, I thought I’d throw together a quick demo of an an analog clock face with sweep second hand (that’s it above). Downloads:

Demo game file
Source code (extensively commented)

Glulx games don’t yet have access to the system clock (though this is in progress), but of course an analog clock in an IF game will most often need to show game time rather than real-world time. Inform 7 tracks game time very simply by default–1 turn equals 1 minute–but this can be customized, and there are extensions to help. This analog clock demo, though, doesn’t change anything in Inform’s default handling. Instead, it overlays real-time on top of game time; in other words, each turn takes one minute, unless you spend one minute thinking about, in which case 2 minutes will pass. This probably isn’t a solution that would be appropriate for most games, but it’s convenient for demonstration purposes! (more…)