D-pad input cancels when fire (A) button is pressed

I have created a simple routine for moving a player (turret) back and forth and having it fire with the A button, it works pretty good for the most part, but if I’m moving by holding the d-pad either left or right and I press the fire button (A) it stops the movement of my player - see code below. I have tried several fixes in order to get this to not happen but can’t figure it out, any help would be appreciated.

Thanks,

Brian

# read a key event (input from d-pad and buttons)
    eventtype = upygame.event.poll()
    if eventtype != upygame.NOEVENT:
        if eventtype.type == upygame.KEYDOWN:
            # left/right
            if eventtype.key == upygame.K_RIGHT and not turret_been_hit: speed_x =  1
            if eventtype.key == upygame.K_LEFT  and not turret_been_hit: speed_x = -1
            # button A
            if eventtype.key == upygame.BUT_A and not shot_fired: 
                shot_fired = True
                #play sound here ***********************************************************
                sx = tx
                sy = ty
        if eventtype.type == upygame.KEYUP: speed_x = 0
    # move turret
    tx += speed_x
    # keep turret on screen
    if(tx < 4) : tx = 4
    if(tx > 96): tx = 96

You can upload the binary here, and i will test with another unit

You said you had problems with sound. Your Pokitto went across the atlantic 4 times courtesy of the US Customs. it is possible there are hairline cracks or something else playing havoc on your board

I’m just looking for help with my code, no sound issues - I think you are responding to the wrong post

1 Like

The problem could be that you set speed_x = 0 whenever any key is released.

Try replacing

        if eventtype.type == upygame.KEYUP: speed_x = 0

with this

        if eventtype.type == upygame.KEYUP:
            if eventtype.key == upygame.K_RIGHT or eventtype.key == upygame.K_LEFT: speed_x = 0
2 Likes

Thanks I’ll try this

Perfect, that did it, thanks again!

Brian

1 Like

Hey Jonne, just thought I’d let you know My Pokitto is working flawless, haven’t had any issues with it. It’s my programming skills that need work :wink: Great device and thanks for the help.

Brian

4 Likes