Thursday, 31 January 2008

Scala and the LWJGL

So! Wending slowly through Scala has been very fun. After a little tinkering (I never did much with Java before) I managed to import the lightweight Java game library and get some primitive graphics on screen!

Now, I may loathe OpenGL's extension mechanism, but I'm forced to admit that using the basics is, well, basic. Granted, it took a little headscratching and blowing the cobwebs off some darkened cubicles of my mind, but eventually all that gubbins about changing the matrix mode returned and viola, 'proper' 3d.

Yep, it's still pretty freakin' primitive. The green blob is a sphere at the player position. Those little squares are tiles, pulled from a list of strings, with the walls rendered in a ghastly lilac and the floor in brown and green.

I'm intending to allow import of data from simple text formats laid out like an ASCII RL. Levels (or areas, I haven't really decided the topology of the game yet) will have a theme, which will dictate how these text files are interpreted.

For example, I'd like to take something like this as input:


In a standard cavern, # would correspond to generic rough granite walls, % would be an interesting wall feature, maybe a mineral vein, fracture or something similar. Then ~ would be a puddle of scummy water, ' & " would become moss and mushroom growths, and + a pile of loose rubble that might be cleared.

In the Evil Overloard DoomFortress, # would be ominous black brickwork, % a ghastly carved face or flickering wall sconce, ~ a font of blood/lava/vegetable oil, ' & " decorative amphorae and candelabras and + a standard (evil) door.

I'm not sure how much merit this idea actually has. It may be that the theme dictates dungeon layout too strongly for these generic templates to be any use; that procedural generation is in all ways better; or that explicit control over the entire palette of potential features and tiles is necessary and a custom map format is the only way forward. Time will (hopefully) tell.

Current bit of Scala code that brings me joy:
def j = k ^ up ^ k ^
(vector triple product followed by normalisation, part of the orthonormal basis of a Camera class)

1 comment:

Matt Hicks said...

Impressive work with Scala and LWJGL. You might be interested in my open-source project I'm currently developing called "sgine" (