I have been experimenting with trying to create my own sort of game using pygame, and I am having trouble figuring out how to make it sense which button is clicked, it senses that a button is clicked, just not which one.
this is my code:
import pygame
from pygame.locals import *
pygame.init()
playerX = 400
playerY = 400
width = 800
height = 600
window = pygame.display.set_mode((width, height), pygame.RESIZABLE)
backgroundcolor = (225, 225, 255)
pygame.display.set_caption('My Game')
window.fill(backgroundcolor)
pygame.display.update()
image = pygame.image.load('images/Character.png')#the link for this character is here: https://i.stack.imgur.com/jMdVe.png
running = True
while running:
window.blit(image, (playerX, playerY))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
print("A key was pressed")
if event.key == pygame.K_w:
playerY -= 5
print('w')
if event.key == pygame.K_s:
playerY += 5
print('s')
if event.key == pygame.K_a:
playerX -= 5
print('a')
if event.key == pygame.K_d:
playerX += 5
print('d')
#updates the display
pygame.display.update()
pygame.quit()