Editorial - October 2007

Issue 57 cover

Summer holidaysAs Autumn draws in, and the days grow shorter, I'm fortunate enough to have some fantastic and vivid memories of my Summer holiday. I recall the beautiful beaches and blue skies of the Canary islands, hot temperatures and cool breezes. I also remember the odd video footage I took on the coach journey from the airport.

While the kids chanted "Are we there yet?" mile after mile, I switched on my video camera to record the scenery. In itself, that's not strange. But I was pointing the camera perpendicular to the road, effectively recording some very fast moving scenery that wouldn't make for a very interesting holiday video.

When I play it back, the family confirm their suspicions; Dad has gone mad! But I see something different; I have my own test footage of scrolling scenery. You don't notice the effect with the naked eye, because we compensate for everything we see that is out of scope for our brain. But recording this live 2D side-scroller has given me an insight into what side-scrolling should really look like. The sand-dunes, rocky outcrops, cactii and distant rolling hills are the perfect combination of what one might see in a game, and so it is archived as another resource in my toolbox.

Autumn is looking very hectic, with plenty to report on. November will bring some exciting news on many fronts, but before that we have the final countdown to the Convention, FPSC X10 refinements, DVD Authoring tools, and a huge section dedicated to DarkBASIC Classic. Of course, you'll find many of the regular features and much more besides.

Until next time,

Steve Vink

contents

(1) FPSC X10 (2) Convention (3) HD Game Studio (4) FPSC News (5) BOTB (6) DBPro (7) DB Classic update (8) SFX Engine (9) Lee's Tip of the Month (10) Q&A Session (11) Tutorial - Full Game (12) From the Forums (13) Winner (14) Outro

FPS Creator X10 Update

FPSC X10

By Lee Bamber

This month we have been working steadily to close off the development phase and begin the hard work of bringing this version to a conclusion. This has involved a lot of decisions about how far to take certain features and which ones to delay until a future version. Our goal has been to create a piece of software that is easy to use, cutting edge and fun. Our priorities have thus been geared to items that contribute to that goal.

There have been hundreds of small visual and functional tweaks, and the known issues have been whittled down significantly in the last month. We are at the stage of dealing with very minor issues now, so much so that screenshots and video capture is taking place on the interface and ingame footage.

FPSC X10 RefractionAffordable, Refractive Refraction

In terms of larger more functional advances, we have succeeded in creating what we call the refractive refraction, which basically means the image of the water as it refracts what lies beneath can be further refracted in a window through which the player views that water. Such a technique would not be attempted before now in a game engine as the visual gain could not be justified by the cost in game speed. With the new GPU power, the technique was not only viable but we have room for more if we need it. This new system means you can create even more complex refraction scenes in your levels.

Another optimisation to the pipeline is the ability to switch off parts of the visual effects system that you do not want to use in the level. If you set reflection strength to zero, the pipeline skips the work to calculate that reflection. The same goes for water and window refraction, and bloom. As the effect values are configured per level, you can switch effects on for a visually stunning level and then off in level two for a fast, hundred soldier battle at 120fps.

FPSC X10 MenuNew challenges, new possibilities

You can also change the effects from within the level as well as using FPI scripting. This is especially cool for raising and lowering the level of the water, reducing ambient light, increasing the strength of shadows and any other property in the X10 effects menu and volume menu. You can now create a puzzle in your level where the player, for example, must pass through a small conduit in the ceiling, using a switch to let water rush into the room and fill it. The player can then swim up and into the conduit to the next part of the level. The underwater realm becomes an active ingredient to your future games!

Improving the user experience 

We also learned from showing the original FPS Creator product to reviewers and interested parties that although the editor is easy compared to traditional modding tools, it was still a little hard to figure out what do to first and in which order. We wanted to improve on this so we have created a new dialog that pops up when the software starts called the Getting Started dialog. Not only does the dialog give you a feature length introduction video to the software, it also gives you video tutorials and the sample levels that come with them. We felt that you should not have to read any manuals in order to get stuck into some game making fun. If a picture is worth a thousand words, then a video is worth the book they are written in. We also designed the dialog to accept new video and samples automatically in future updates to bring you easy lessons on the various parts of the software, and to introduce new features as we release them.

From our experience with the FPSC community, we also felt an automatic update feature would be helpful. When the software starts, it has the option to check the main FPS Creator X10 server to see if there are any new versions available. If one is found, you have the option to have the system download and install it. No need to go hunting on the website, or learning about an update by accident on the forums any more. The feature also has the ability to update itself so we can improve the system to deliver more content to you as the product evolves from version to version.

Refining the visuals, and adding more design options

As for new content, we are already working on features that will become available after release as well. One such feature is the ability for characters to hold a melee type weapon in their hands for close range combat, and have that weapon disappear if they are given another. This extends the range of characters that can be created and imported into X10, which in turn means more diverse and new level concepts.

On the shader side of things, we have further improved several effects.  We updated the weapon shader, which now uses parallax relief mapping to create a very realistic effect of depth in the surface (see my Tip of the Month). We also improved the bloom effect, taken directly from the DarkSHADER suite of shaders to boost the overall quality of the scene.

FPSC X10 Bloom effect

Right now we only have a handful of issues remaining, with our primary focus on pulling together the new X10 manual, screenshots, videos, sample levels, translation kit material and scripts that will be used to provide the professional voiceover to add that extra polish to the production. We are very close to completing X10 now - the waiting is almost over! We wanted to make sure that we got the product just right, and we feel the extra six months has really transformed the software.

FPS Creator X10 will be showcasing at the Convention at the end of October. Participants will be able to get involved with a hands-on session and try it out for themselves. Next month, we'll have some long-awaited announcements for you!

'07 - The Official Game Creators Convention

TGC Convention 2007

Following up on the details of the presentation a couple of months ago, some of the team members have recently expanded on the content of their intended talks.

Rick Vanner is naturally focusing on the plans of the company in the near future. "I will be outlining how indie developers can team up with the TGC team to sell their creations", says Rick. "If you're developing a tool, a cool game or some custom media then TGC can help you bring it to a wider market. TGC will be expanding their reach to more game developers in the months to come, and I'll be presenting the details of this plan."

Lee Bamber will be taking the technical perspective during the convention, looking at the future of DirectX. "I have been working with DirectX 10 and Windows Vista for a year now, so you can imagine I have a lot of technical knowledge to impart to those curious enough to ask. Aside from getting a peek at the new DBPro X10 and FPSC X10 before anyone else, you will also get a chance to poke my brain with a stick to see if anything falls out".

Lee also likes to take advantage of the social side of these events. "If you want to meet the guy who went to war over R&D tax credits, and won, come along and we'll swap our stories, both real and imagined. I will be the first one to arrive and the last one to get up, and just so you know which one is me, I will be the one with a Guinness in each hand. My favourite part of the event has to be the impromptu strolls down memory lane, and a gathering of game coders is a great place for nostalgic musings and harking back to the glory days of coding by abacus and frying toast on your power block."

Mike Johnson will be getting the opportunity to reveal a few of the neat tricks you can perform with a little ingenuity and imagination. "When using the Dark GDK it is possible to hook directly into the core engine. As an example of this I will be demonstrating how to load and animate character models from World of Warcraft in Dark GDK. Right now, I'm working on importing a full world from World of Warcraft, and I'll be presenting the results of these efforts at the convention. Of course, WOW is just one example. Technically, it's possible to do this with any media."

You'll also get to hear Paul Johnston speak about his experiences in bringing the TGC game engines into the world of multiple core CPUs. "With many things going on at once your code can become more complicated and harder to debug. I will demonstrate the types of task that are suited to threading, the different ways you can use threads to improve performance, and some key issues to look out for when using threads. Threads need special consideration when they interact with a variable shared by multiple threads, so I will also cover techniques used to handle this and avoid variable corruption."

 

The Time: October 27 & 28, 2007
The Place: Hinsley Hall conference centre, Leeds, UK

With less than one month to go, you need to get in touch as soon as possible to secure a place at the convention. There is so much happening behind the scenes at TGC right now, that the convention will be the place to be if you want to know what the future holds. You'll also get the chance to talk directly to Rick, Lee and the other developers and creative contributors.

Convention Day Rate - £29.50 per day (£59.00)

Convention Attendance
Tea/Coffee/Biscuits throughout the day
2-course Buffet Lunch

Full Weekend Rate - £170

Convention Attendance
Tea/Coffee/Biscuits throughout the day
2-course Buffet Lunch
Accommodation (Friday/Saturday evenings).
3-course, self-service Evening Meal (Friday/Saturday)
Breakfast (Saturday/Sunday Morning)

Rooms at the centre can no longer be guaranteed. Enquiries will be made at the time of your booking on the availability of a room. However, you are still able to arrange your accommodation elsewhere and attend the convention as a day delegate, paying the reduced rate.

You can download the booking form here, and return it with your payment to reserve your place. You can pay online, simply email Michelle Vink for the details. We are very excited about this event, and hope that you will take advantage of this unique opportunity. Find more details and join in the discussions on the forums.

The Game Creators add a New EDGe to HD DVD authoring

sonicBuilding on their proven development environments for interactive games, The Game Creators are introducing applications that verify and export format-compliant advanced content for the new high-definition packaged media formats. As a New EDGe application, HD DVD Game Studio is designed to work seamlessly with Sonic's industry-proven Scenarist® authoring systems. The solution from The Game Creators will greatly streamline the production of game-oriented bonus content and make it significantly easier for Hollywood studios and professional content holders to add compelling extras to their HD DVD titles.

"By embracing the high-definition medium early on, our intention is to be the leading tool provider in the interactive games creation market," says Rick Vanner. "Participating in the Sonic EDGe program Dave Milton, Francois Lionet, Rick Vanneroffers us a clear path toward that goal. Thanks to Sonic, we are able to help pioneer easy gaming creativity for HD DVD, while at the same time expanding our market for our own innovative, powerful, and affordable game-making solutions."

Members of the team visited IBC in the Netherlands in September to showcase the technology with Sonic. For Rick, it was a memorable trip as he met up with François Lionet of Clickteam (pictured centre left). Rick and François worked together for many years on the Atari ST, Amiga and PC platforms, before going their separate ways. Clickteam are a second participant in the EDGe programme focusing on the Blu-Ray format.

News from the World of FPS Creator

FPS Creator News

FPS Creator Version 1.07 

The latest upgrade for FPS Creator is now available. Changes include:

To ensure a smooth upgrade process, follow these guidelines:

Note: If you have model packs 3 or 5, we advise you uninstall these and download the latest  versions from your Order History. The original packs included FPS system files and these are now redundant. Model packs will be updated later in October and will be identifiable by their _07 suffix. For example, FPSCreatorModelPack2.zip becomes FPSCreatorModelPack2_07.zip

One of the most important changes is the replacement of the lightmapping system with Dark Lights technology. This gives much faster mapping speeds, and much improved end results. The version of Dark Lights built into FPS Creator fully supports both dual and quad core processors. Consequently - if your CPU allows - you can lightmap your scenes significantly faster. Our test results show dual core systems mapping scenes at up to 70% quicker than single core. The bigger the game scene, the larger the speed increase.

Update 1.07 is available from the FPSC downloads page.

 

Phoenix Contest

David Goodman, creator of Phoenix Sentry Game Protection, has announced a competition based around FPS Creator. The prizes include hardware, software and a potential publishing contract for the winners. This is also your first opportunity to win the upcoming FPS Creator X10, donated to this contest by The Game Creators. The full list of prizes and competition rules follow.

Concept

The concept is for FPSC game developers to produce a unique mini-game consisting of 2 or 3 levels within the boundaries of a 15x15x5 map. There is no genre requirement, so you can make your mini-game SciFi, Horror, War, Surreal, etc. It's up to you.

The Prizes

Grand Prize:

2nd & 3rd Place:

Rules

The competition is open now, and the deadline is 30 November, 2007. The winners will be announced by 15 December 2007.

You can join the contest forum discussion to catch up on the latest details.

 

Best Of The Best

Best Of The Best

Here are two FPSC games that have achieved the accolade of Best Of The Best this month...

Darkest Island

by Luke314Pi

Darkest IslandDarkest Island is the story of a man named Daniel who wakes up in a bloody hospital bed on a remote island with no knowledge of how he got there. A girl's voice echoes in his mind, begging for him to come and rescue her, and promising to help him get off the island. Daniel finds that this hospital is actually a research facility, and the inhabitants are no longer human. These zombie-like creatures are not the only enemies that Daniel makes. Soon he has armed soldiers hunting him as well. The true story of the facility unfolds as Daniel makes his way into the dark center of the Island.

"My brother Andrew came up to me one day with a story he wrote about a man fighting zombies on a remote island. I really liked the story and I told him it would make a great video game. His eyes lit up and he asked me if we could make one together. How could I refuse?

Darkest Island"I spent the next few weeks hammering out the story details and script based on his short story. I wanted the game to have a cohesive theme that was carried out through each level, and I think I was very successful with that. I drew up level designs on paper before creating them in FPSC, and it worked out very well for me. I wanted the levels to feel like a real place, with layouts that would exist in real buildings, instead of something that would only exist in a video game world. I started in April 2006 and my goal was to finish by Christmas so we could give the game out as presents. I ended up finishing a few days after Christmas, but everyone was happy to get the game."

You can download and view the trailer of Darkest Island. Please be aware that this preview contains a large degree of gore!

The game is available for download at FileFront.

Fall of the Fireflies

by Butterfingers

Fall Of The FirefliesFOTF is set in a conflict hotspot in North Korea. The storyline is based around North Korea running it's own Nuclear weapons program. Although the world knows that they possess WMDs they have not declared it, and the political environment has led to the situation being ignored. This leaves the door open for mercenary factions to attempt to steal the weapons. You play a member of Iron Hammer, a Russian paramilitary group, involved in numerous global conflicts. Your objective is to steal as much information and hardware from under the noses of the enemy, and sell it to the highest bidder.

The demo level is set in a monastery where you are attempting to open the doors to a sub-terrainian tunnel. The tunnel connects the monastry to a sewer that will lead you to the first Nuke factory.

Fall Of The Fireflies"The FOTF demo was released late last year, and at the time broke some barriers in FPSC. This is the demo that led me to make and release LYTEFX (Decal Lighting Effects), simply from the crit the lighting received. My first full project, FOTF was a way to focus my FPSC level building towards something specific, rather than simply churning out media. Although the demo only features one level, the game actually got as far as one-and-a-half chapters before it was canned!

"Playing it now, I can see that the texture work and modelling haven't aged well, but I still think that it's an FPSC classic. Almost all of the media is custom, from the wall textures and lights to the characters and weapons. Sure, they're not fantastic, but there is a consistent style to the media. I realise there is probably better stuff out there, but this demo had an unprecedented number of downloads, and featured in FPSfree's game of the month!"

The Fall of the Fireflies demo is also available for download at FileFront.

Full details and previous winners of the BOTB award can be found in the dedicated forum thread.

DarkBASIC Professional Round-up

DarkBASIC Professional

The community around TGC never ceases to surprise and enlighten us with new, alternative or simply different functionality, made available for all to benefit. If, like Dorian featured here this month, you have something to share with us then let us know.

Advanced Sprites

AdvancedSPRITES is a free plugin created by forum member Dorian Morelle , aka MOD. With 88 commands at your disposal, it is a comprehensive package of alternative functionality. This is not an enhancement to the existing Sprite System in DarkBASIC Professional, but an entirely different way of acheiving similar results. In various scenarios, these perform extremely well due to the differing methods implemented.

AdvancedSPRITES contains the following features :

The AdvancedSPRITES downloadable archive contains :

Dorian thanks IanM, ApexNow and Freddix for their assistance and contributions. Feedback and suggestions are welcomed via the forum thread.

AdvancedSPRITES is available from Dorian's website.

Dev.Mag - for Game Creators

dev.MagAn online publication from South Africa, Dev.Mag has been around for over a year now and proving to be a popular resource. It's created by a number of enthusiasts, and is a reasonably sized PDF publication, released monthly.

Features include project developments from the authors, reader contributions, industry news, and advice on programming and other essential skills. The current publication (shown opposite) is downloadable now, alongside 15 back issues. Get them from the Dev.Mag website.

 

 

DarkBASIC Classic is Revitalised

DarkBASIC CLassic 1.2.0

At the end of 2001, DarkBASIC version 1.13 was released. This provided enough power and functionality to make the application the desirable solution for programmers more than five years later. With the advent of Vista and the implications it introduces for programs running in this significantly different environment, DarkBASIC has been given an update to keep it running smoothly, and introdce some new features.

Ron Erickson (creator of the EZrotate, TextureMax and Enhanced Animations plugins for DarkBasic Professional) has finalised version 1.2.0 of DarkBASIC Classic. There are still many people using DarkBasic Classic for commercial projects, and this has been developed in conjunction with the makers of Starwraith, a hugely sucessful title developed using the language.

The main goal of the new release is to provide better support for the games produced in Windows Vista. The Vista compatability changes include the removal of DirectX retained mode dependency and the way that temporary files are generated.

Four new commands have also been added to provide better lighting and material effects to objects.

Finally, some existing problems with primitive objects have been corrected.

If you want to see the latest version of the language in action, and realise just what can be achieved, read on...

Evochron Renegades

From the Starwraith 3D Games stable comes their latest space sim, Evochron Renegades. The game is unique among freeform space-sims in that it offers a wide range of gameplay choices and activities including buying, trading, negotiating, bribing, spying, racing, transporting, mining, exploring, cleaning equipment, clearing paths through asteroid fields, recruiting, protecting, hiring crew members, fuel harvesting, and designing your ship. The upgrades, ships, equipment, money, and commodities you earn in the game can be used in both the single player and multiplayer modes. You don't have to give up your progress in the game when switching between single player and multiplayer, nor do you have to give up what you earn when you join different multiplayer sessions.

Everything you do in the game takes place in a seamless universe without system 'walls', there are no required warp gates or trade lanes to restrict your travel and hold you back. You can travel anywhere you want, with or without jump drives and gates, as long as you have the fuel and time to get there. You can descend into planet atmospheres (without loading screens or sudden environment flipping) to land at city trade stations or explore for hidden items. You can escape to nebula clouds for sensor cover or hide in a massive asteroid cave for protection. If you're low on fuel and don't have money, but you have a tractor beam and fuel converter, then retrieve photon particles from nearby stars and emissive nebulae which can be processed into fuel.

Design your ship for the role you want to play and customize the appearance by adjusting the position/scaling of the various parts of your ship. Whether it's combat, exploration, mining, trading, racing, or a variety of other activities, you'll find many ways to play and advance in the game.

Screenshots

The game is a fantastic showcase of DarkBASIC Classic 1.2.0 as you can see from the images below, taken directly from Evochron Renegades. Click on the images for a larger view.

Evochron Renegades Evochron Renegades 

Evochron Renegades Evochron Renegades 

Evochron Renegades Evochron Renegades 

The migration to DarkBASIC Classic 1.2.0

To introduce the enhanced and required functionality, certain changes are inevitable. Shawn of Starwraith 3D Games has shared his experiences of migrating to the new version of the language. His experience is invaluable to anyone making the same transition.

sdir$=left$(windir$(),3)+"dbTemp\"
if file exist(sdir$+"_virtual.bmp")=1 then delete file sdir$+"_virtual.bmp"
if file exist(sdir$+"_virtual.dat")=1 then delete file sdir$+"_virtual.dat"
if file exist(sdir$+"_virtual.jpg")=1 then delete file sdir$+"_virtual.jpg"
if path exist(sdir$)=1 then delete directory sdir$

Following these pointers should ensure a smooth transition and open up the new functionality to enhance your games.

Evochron Renegades is available from the StarWraith 3D Games website.

 

Coming Soon - DarkIDE for DarkBASIC Classic

DarkIDEDarkIDE is a third-party IDE for Dark Basic Classic. It is being developed by long-standing forum member TDK, and includes many of the advanced project features of the IDE shipped with Dark Basic Professional.

The current list of features, in the beta version of the product, includes:

DarkIDE Video Browser

There is also an integrated media browser for images, sounds, music, models and video. Code for media is automatically generated and inserted into the source editor. Although not yet complete,  it is now in public beta, and can be downloaded from the forums. Don't forget to leave your feedback and help this become the fully-featured and stable product that it aims to be.

 

SFX Engine Updated

SFX Engine

SFXEngine is a unique sound creation and processing tool. Sound is manipulated using a chain of custom audio plug-ins called Engines to make it easy to create and edit complex layered sound effects. Any parameter of any Engine can be modulated, and the modulator graphs are simply wav files making it easy to create or edit complex parameter changes.

SFXengine

The key features include:

Watch out this month for the update (1.09) to arrive on the SFXengine page on the site.

Lee's Tip of the Month - What A Relief

Lee Bamber Conehead!

I was talking with a nice NVIDIA dude the other day and amongst other things, I learned they really like parallax relief mapping. I mean they really like parallax relief mapping!

For all the great visual effects buried inside FPS Creator X10, the project I am tinkering with, I had not considered parallax relief mapping until it was suggested. I had not considered it before because the shader required to create the effect is quite a monster. It then took about two seconds to realise the 8800 graphics card could do relief shading in it's sleep.

The easiest way to get parallax relief mapping into your games is to use the DarkSHADER product, which contains a rather nifty relief mapper with textures to boot. Another way is to browse the community for a user who has released a demo to the public domain and swipe their relief shader...with their permission of course!

Rather that delve into the murky waters of shader coding, which I know you will just love, I will give you the friendly version of how it works and how you can get it into your game.

A parallax relief mapper uses at least two textures. A diffuse texture and a normal map texture. The diffuse texture is simply the color information your object uses. The normal map texture is filled with values that correspond to a 3D vector and a height value. The texture uses the R,G and B components to store the X,Y and Z values for the vector which describes the angle of the surface at each texel, like a standard normal map. Unlike a standard normal map, a relief shader requires a height value, which is stored in the alpha component of the texture, which describes how deep the surface is at each texel. The shader normally uses a specular texture too to describe how much specular light is reflected off the surface of the object.

Getting this great effect into your games is just about as easy as falling off a log, log permitting of course. Once you have your hands on a working relief shader (relief.fx) you simply add the following lines:

MAKE OBJECT CUBE 1,100
LOAD IMAGE "diffuse.png",2
LOAD IMAGE "normal.png",3
LOAD IMAGE "specular.png",4
LOAD EFFECT "relief.fx",5,0
TEXTURE OBJECT 1,0,2
TEXTURE OBJECT 1,1,3
TEXTURE OBJECT 1,2,4
SET OBJECT EFFECT 1,5 

Parallax Relief MappingThis will create a relief effect on the spinning cube, which you can then apply to any object in your game. Opposite is a video link (MSN login required) that shows this effect in action. You can also download the example code and run it for yourself, you will need a graphics card capable of running Pixel Shader 2.0a effects. If you want to make your graphics card happy, add a little parallax relief mapping to your life! 

The IRC Q&A Session with Rick Vanner and Lee Bamber

Whilst many people turned up to the Question and Answer session towards the end of September, we realise it's not possible for everyone to be there. This is a fantastic opportunity to grill the TGC team and get the answers to your queries and foibles. There is a link to the full, unabridged transcript in the From The Forums section, but in the meantime here are some of the more interesting responses.

Will we see a replacement IDE?

We are looking at two now which MIGHT be the next official IDE

Will DBPx10 have support for some kind of threading or asynchronous file i/o?

We already do AI and Lightmapping with threading in FPSCX10 and multicore is very much in our thinking.

Are there any plans to port the official plug-ins to DGDK?

Yes, very soon (later 2007 early 2008).

What do you think of the current dbp community / projects ?

The current state of the community is great, and as strong as ever - I can't wait to return with my bag of DirectX 10 goodies for them.

I'm always impressed by what the community do, be it low quality or high, it's so cool to see people make games.

Do you ever think about hiring people in the future?

We hire all the time, but very sneakily. We cherry pick the best people when they least expect it, so get working on your projects, you never know!

Are DBP arrays *actually* arrays, or just linked lists.. or something else?

They are a creature all of their own. They are real fast memory arrays, but have a built-in list manager to turn them into lists, stacks and queues at will, it is a nice system.

How many hours a day do you spend coding DBP X10 and FPSCx10?

Lee spends at least 10 hours a day, but more like 14 on a crazy day.

How many lines is FPSC X10 at just now?

Not many, around 37,000 lines in the DBP X10 language.

 

Tutorial - From Template to Game

DBPro Mastery 

Custom Keys

by Craig Chipperfield

I moved house recently and only received one key for each door. To make matters worse they looked identical! So, a trip to the cobbler (isn't it odd that all cobblers also cut keys?) was in order. I had the front door made from brass and the back door from stainless steel. Now I could tell the difference between them. That, however, wasn't enough for my wife, she got plastic covers for the end of her keys. So her front door is a cow and the back door a pig (or maybe it's the other way around). The fact is, we now both have totally different looking keys for the house but they do exactly the same job.

The same thing happens in games too. We all have our own preference for which keys to use but unless the coder has implemented an option to change them we are stuck with his choice. Back in the 8-bit days directional movement often used ZX'/ but on occasion the left and right were swapped and you had AZ<> instead. Now, it is usually WASD but depending on the game it may be easier to use the arrowkeys - but who decides? Well, it shouldn't be the coder, it should be the end user. So we need a custom key function and that is what we are going to look at this month.

To use custom keys there are three steps that we need to take.

  1. Each key needs a name because the user needs to know which keys are in use.

  2. The user must be able to choose which keys to use.

  3. The code must react correctly no matter which key is pressed.

Let's start at the beginning and look at step 1. Most keys already have names. Q is Q, W is W etc. but what about Return, Left Shift, Right Control? They certainly have names but when you press them, what appears on screen? These keys (in fact all keys) need to be named. It can be a slow process but fortunately it only needs to be done once ... EVER! You can re-use the name list for every project you create.

There are two other things to consider with the naming list: Firstly, who will use your project? Is it just your friends and family or will it go world-wide? If it will go world-wide then maybe you should consider support for foreign language keyboards. The other thing to consider is the layout of the keyboard. You might have a keyboard with special keys on it. Perhaps for media playing or specialist game keys but not everybody that uses your project will have the same keys. So, it will be best if you keep your keys to the standard 108 key layout.

Actually, to create the key list and support other languages really doesn't take much code at all. As you can see from the code below:

disable escapekey
Input "Enter Language : ", Language$
GetKeyNames(Language$)
end
function GetKeyNames( Language$ )
if path exist( "Languages" ) = 0 then make directory "Languages"
if file exist( "Languages/" + Language$ ) then delete file "Languages/" + Language$
open to write 1, "Languages/" + language$
repeat
cls
print "Press any key and enter its name or click the mouse to exit "
`Wait until the return key has been released
`so that it isn't assumed to be the next key
repeat until keystate(28) = 0
`Select Key
repeat sc = scancode() : until sc
`Enter Key Nameinput "Enter name for scancode " + str$( sc ) + ": ", name$
`Save to file
write string 1, str$( sc )
write string 1, name$
until mouseclick()
close file 1
endfunction 

That code doesn't need to be in your end project. You can run it, create your keyname list and then forget about it. The second part of step 1 comes in the form of reading the name list back in and that is a simple file read, the difference being this now needs to be in you main project. This is the file read function:

function ReadKeyNames( Language$ )
if file exist( "Languages/" + Language$ )
open to read 1, "Languages/" + Language$
repeat
`read the string
read string 1, code$
code = val( code$ )
read string 1, KeyName( Code )
until file end( 1 )
close file 1
endif
endfunction 

The sharp eyed amongst you will have noticed that the keynames are being read into an array that has not yet been defined. That will become clear when you see all of the final code. I've only shown the function here to demonstrate how simple it is.

So, now we have established the names for all of the keys on a standard keyboard and we have read those names into our main project. So, let's skip ahead, ignore step 2 for a moment and look at how the code should react to our key presses.

Take a look at the code below. It is simply a cube on a matrix. The arrow keys move the cube left, right, back & forward. The shift keys moves it up, control key moves it down and the space key changes the colour of the cube.

type t_obj
X as float
Y as float
Z as float
endtype 
Global Obj as t_obj
Global Speed as float = 1.0
sync on
sync rate 60
`Create World
autocam off
set text opaque
ink rgb(255,255,255), rgb(0,0,128)
make matrix 1, 100, 100, 10, 10
make object cube 1, 10
Obj.X = 50 : Obj.Z = 50
position object 1, Obj.X, 0, Obj.Z
position camera 50, 50, -25
point camera 50, 0, 50
do
GetUserInput()
UpdateDisplay()
sync
loop
end 
`-------------------
` GET USER INPUT
`-------------------
function GetUserInput()
if UpKey() then inc Obj.Z, Speed
if DownKey() then dec Obj.Z, Speed
if LeftKey() then dec Obj.X, Speed
if RightKey() then inc Obj.X, Speed
if ControlKey() then dec Obj.Y, Speed
if ShiftKey() then inc Obj.Y, Speed
if SpaceKey() then color object 1, rnd(16777215)
endfunction 
`-------------------
` UPDATE DISPLAY
`-------------------
function UpdateDisplay()
position object 1, Obj.X, Obj.Y, Obj.Z
endfunction 

This is fine if we have no intention of changing the keys but that is not what we are trying to achieve. So, we need to change the way we input the keys and for that we need to use the KEYSTATE() command to check to see if any keys have been pressed. Every key has a value assigned to it called a scancode. You can read each keys scancode value using the SCANCODE() command or look at an image of the keys with the scancode values on them. This is a popular one:

Scancodes

So, in the previous example we can now change the user input function to this:

function GetUserInput()
if Keystate( 200 ) then inc Obj.Z, Speed
if Keystate( 208 ) then dec Obj.Z, Speed
if Keystate( 203 ) then dec Obj.X, Speed
if Keystate( 205 ) then inc Obj.X, Speed
if Keystate( 54 ) then dec Obj.Y, Speed
if Keystate( 157 ) then inc Obj.Y, Speed
if Keystate( 57 ) then color object 1, rnd(16777215)
endfunction

Now that is all well and good but it hasn't actually achieved much. All we have done is replace one keyword with another. If we want to allow the user to change the keys then we can't have hard-coded key numbers, we must replace them with variables. Once that is done it is fairly obvious to see that it is simply a case of changing the variable's value to that of a different key and the code will still react as it should. So, we have successfully achieved the aim of step 3.

That just leaves step 2 which was to allow the user to input new key choices. For this part you might want to make a GUI that is in a similar style to the rest of your game but for the purpose of this tutorial I will keep it as simple text input.

Downloading the tutorial file will get you the complete ‘cube on a matrix' code with custom keys, a .EXE to generate your own language key name file and I have included the English version of the keyname file to save you the trouble of making your own.

It should be fairly obvious how to fit these functions into your own code. I can't promise you pigs and cows to open your house but at least now you should be able to give your users the option to change the keys on your games.

Download the tutorial files.

From the Forums

Here are some of the highlights from this month.

Image Filter Library

Mr Kohlenstoff has been busy creating a whole library of image effects and routines, from simple shape-making to more complex height maps and random skies.

IRC Q and A Session

Rick and Lee dropped by in the last week of September to answer the questions we have all been wanting to ask. See the transcript of that session here.

.

The Code Counter

The idea here is to add your source code to the counter, to see just how much code is being written in DarkBASIC (Classic, Pro, GDK). Add the number of lines you've written in any day, week, or project.

Legend Of The Green Dragon

Every once in a while, LOGD resurfaces for your delectation. Need a break from coding? Vent your frustration on other forum members? This is your chance, as Jerico2day hosts the game once again.

.

This month's Winner

Each month we pluck one lucky subscriber from the newsletter mailing list and award them a free copy of DarkBASIC Professional. The email address of this month's winner is: your***tru**od@gmail.com  If this is you then send us an email to claim your prize.

Outro

Share your news with over 14,000 active games developers!

If you have something you'd like featured in a future issue then please get in touch and include as much information as possible (including where applicable: screen shots, URLs and zip files).
Issue 58 deadline - October 26th.

Voodoo Programming: Things programmers do that they know shouldn't work but they try anyway, and which sometimes actually work, such as recompiling everything. (Karl Lehenbauer)