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