Sign in to follow this  
  • entries
    455
  • comments
    639
  • views
    422452

Bonsai - input!

Sign in to follow this  
_the_phantom_

56 views

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 = false
text= ""
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]
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now