0

Hey guys I am trying to make a top down game using pygame but , when I use the keys normally like pressing w , a , s, d , it does not work but when i hold control (ctrl) and press w , a , s , d , it works all fine , heres the code :

import pygame
from pygame.locals import *
import sys

pygame.init()

win = pygame.display.set_mode( (800 , 600) )
pygame.display.set_caption('Place Holder')

fps = 60
fpsClock = pygame.time.Clock()

# Player Variables
PlayerPos = [ 400 , 300 ]
Juke = [ False , False , False , False ]

# Colours
White = ( 255 , 255 , 255 )

# main loop
Running = True
while Running:

    win.fill((50 , 50 , 50))

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    # Keydown
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_w:
            Juke[0] = True

        if event.key == pygame.K_s:
            Juke[1] = True

        if event.key == pygame.K_d:
            Juke[2] = True

        if event.key == pygame.K_a:
            Juke[3] = True

    # Keyup
    if event.type == pygame.KEYUP:
        if event.key == pygame.K_w:
            Juke[0] = False

        if event.key == pygame.K_s:
            Juke[1] = False

        if event.key == pygame.K_d:
            Juke[2] = False

        if event.key == pygame.K_a:
            Juke[3] = False

    # Start

    # Draw Player

    pygame.draw.rect(win , White, pygame.Rect(PlayerPos[0], PlayerPos[1], 64, 64))

    # Juke Movement

    if Juke[0]:
        PlayerPos[1] -=2

    if Juke[1]:
        PlayerPos[1] +=2

    if Juke[2]:
        PlayerPos[0] +=2

    if Juke[3]:
        PlayerPos[0] -=2

    # End

    pygame.display.update()
    fpsClock.tick(fps) # (60)

i cannot see where is the problem where is am saying the code to press ctrl (control)

0 Answers0