Skip to content
Advertisement

How to make fighting game command inputs in PyGame

I am currently making a fighting game and was wondering how command inputs could be added. I understand it is kind of irrelevant and many substitutes are possible, but it would be nice to use familiar fighting game inputs.

I currently have something like this:

JavaScript

The “commandcount” helps keep the window of action available until a certain amount of time.

The main problem with this is that you could still press the inputs in whatever order and the projectile would still come out.

Thanks

Advertisement

Answer

Try using the pygame.KEYDOWN events instead of pygame.key.get_pressed() so the order can be observed. Use a list to keep track of the order of these KEYDOWN events. When the order matches a specific combo then execute the move and reset the list. The list also gets reset after a certain amount of time with a combo. I made an example program with the combo down, right, z activating a fireball.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement