Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Bonsai - input!

Bonsai - input!

_the_phantom_
Not dead... · · 2 min read
462 0
So, after some ha><0ring and general stuff I've got keyboard input working [smile]

The 3 basic windows keyboard messages as passed on;
- key down
- key up
- char

To go with this there are 3 translation tables;
- bonsai.Event.translate does int => string translation
- bonsai.Event.keycodes does string => int translation
- bonsai.Event.charTranslate also does int => string but the output is printable

The first two are mostly useful for game input, for example you could define the following somewhere

up = w
down = s
left = a
right = d
fire = space

Then, by performing a lookup against the current keycodes you can get the required values to check on event handling.

Then when you save out the config you can just push the keycodes into the translate table and get back the string which will translate back to it.

Simple and pretty easy [smile]

The 'bonsai.Event.charTranslate' does printable translations, namely for when shift matters [grin]
So, typing 'a' and typing 'A' will give you the correct results.
However, if you try to type '!' it kinda blows up atm, that's mostly due to the lack of translation causing 'nil' to be appended to my string which I try to print with the following main loop;

quit = falsetext= ""while(quit == false)do	events = bonsai.getEvents()	for i = 1, #events 	do 		if events.message == bonsai.Event.types.quit 		then 			quit = true 		end 		if events.message == bonsai.Event.types.char		then			 text = text .. bonsai.Event.charTranslate[events.param1]		end 	end		eng:startFrame()	eng:renderQuads(imgs)	eng:renderText(0,100,text,font,{r=0,g=255,b=255})	img:update()	img2:update()	eng:endFrame()end


This is just a basic test of things, and I'm pretty happy with it. I should probably fix that exploding translation problem so it does the Right Thing(tm) and I'm also going to have to do something about the shift characters depending on the keyboard layout in use (damn you non-UK layout people! *shakes fists*).

However, that's another tick on my 'todo' list done, huzzah!

I think that pretty much leaves colour constants and sprites to deal with and then the game can be recreated.

Huzzah!
[grin]

Discussion

Loading comments...