Re: how would i create an actual key config class in python with lucia?

The simplest way is doing something like this is the following:

import lucia
keys = {
    "up" : lucia.K_UP,
    "left" : lucia.K_LEFT,
    "down" : lucia.K_DOWN
}

Then, to override the key, you may wish to present the player with an option menu to override each key individually, and then do something like this:

def configure_key(key):
    while 1:
        events = lucia.process_events()
        for event in events:
            if event.type == lucia.KEYDOWN:
                #Override the keys like so:
                keys[key] = event.key
                return

Finally, to use your keys, you can do something like so:

if lucia.key_pressed(keys["up"]):
    #Logic
elif lucia.key_pressed(keys["left"]):
    #Logic

There is a really good book called Game Design Patterns Revisited which describes something called the command pattern and demonstrates how it can be used to model keys, but I'm not sure if you can pull off what it is describing with Python (all the code for the book is in c++).
Hope that helps. I strongly suggest wrapping the code I showed earlier into a class, it was meant to give a rough demonstration of what your config could look like. For exporting the dictionary, Json or or pickle might be a good bet, or you can try and find a module which writes .ini files if you're into that.



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ambro86 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ambro86 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector

Reply via email to