Pygame? K_SPACE + K_UP + K_RIGHT don't work together

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Pygame? K_SPACE + K_UP + K_RIGHT don't work together

#1 Post by Milkymalk »

This is more of a Pygame issue I fear, since I couldn't find any problems in my code, but I thought I'd ask here first in case I didn't see something.

The cursor keys move the sprite (well left and right only really change the horizontal speed), space shoots. I can move in every direction and shoot at the same time except for up+right. When I move right, shoot and press up, the sprite keeps moving right instead of up-right. If I move right first, shoot and move up, it moves right while shooting. If I move up-right and then start to shoot, no shots happen. In each of the three cases a moment or so later I get a speaker beep until I release one of the keys.

I have no problems with up-left, down-left or down-right.

This is the only place where I ever use keypresses:

Code: Select all

        keys=pygame.key.get_pressed()  ### Get keyboard input ###
        
        ### check if player swings to left or right ###
        if keys[pygame.K_LEFT] and not keys[pygame.K_RIGHT]:
            if player.tilt > -(player.speed):
                player.tilt -= player.acc
                if player.tilt < -player.speed:
                    player.tilt = -player.speed
        elif keys[pygame.K_RIGHT] and not keys[pygame.K_LEFT]:        
            if player.tilt < player.speed:
                player.tilt += player.acc
                if player.tilt > player.speed:
                    player.tilt = player.speed
        else:        ### if not, gradually normalise the momentum ###
            if player.tilt != 0:
                player.tilt += int(float(abs(player.tilt)) / float(-player.tilt))
                
        ### calculate sprite rotation ### irrelevant for this problem
        sin = float(player.tilt) / float(player.speed)
        player.head = int(float(math.degrees(math.asin(sin))) / 2.0)
   #     player.sprite.set_child(Transform(child=player.basesprite, rotate=player.head))
        
        ### up&down movement, slower if also moving sideways ###
        # changing this reveals it's indeed the key combination and not the direction
        hspeed = player.tilt
        if keys[pygame.K_DOWN]:
            vspeed = int(player.speed - (0.5*abs(player.tilt)))
        elif keys[pygame.K_UP]:
            vspeed = -int(player.speed - (0.5*abs(player.tilt)))
        else:
            vspeed = 0
        
        ### make sure not to leave the screen! ###
        if player.x + hspeed > config.screen_width-40:
            hspeed = config.screen_width-40 - player.x
        if player.x + hspeed < 40:
            hspeed = 40 - player.x
        if player.y + vspeed > config.screen_height-40:
            vspeed = config.screen_height-40 - player.y
        if player.y + vspeed < 40:
            vspeed = 40 - player.y
        player.x += hspeed
        player.y += vspeed
        
        ### check if player can shoot and if he wants to shoot ###
        if player.cooldownleft > 0:
            player.cooldownleft -= 1
        if keys[pygame.K_SPACE] and player.cooldownleft == 0:
            player.shoot()
            player.cooldownleft = player.cooldown
Is the problem in the code, is anything conflicting? Or is it some weird Pygame behaviour?
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Pygame? K_SPACE + K_UP + K_RIGHT don't work together

#2 Post by xela »

Code looks fine and it's not likely a pygame issue either, it's most likely a keyboard issue so there isn't much you can do about that.

PS:

Try WASD (maybe something else to fire as well), it could/should/might work and will take 5 secs recoding time.
Like what we're doing? Support us at:
Image

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Pygame? K_SPACE + K_UP + K_RIGHT don't work together

#3 Post by Milkymalk »

WASD isn't good because it includes the hotkay for screenshots and one other. It works if I use left alt instead of space - ideally I would use left crtl, but that is used for skip mode and I don't want to change a key that is so commonly used.

So it's probably my keyboard in particular? Hm.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Pygame? K_SPACE + K_UP + K_RIGHT don't work together

#4 Post by xela »

Nope, it's a common thing with some of microsoft, dell and a lot of other manufacturers I expect. Never heard of this being reported for logitech keyboards but it may depends on a model.
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]