0

I have some code which should make my sprite move with arrow keys, but it doesn't move and I don't know why. It is a problem of xv and yv variable because they stay at 0 which I don't know why. Code:

from pygame import *
from sys import exit
init()
xv, yv, x, y = 0, 0, 0, 0
size = w, h = 300,300
screen = display.set_mode(size)
box = image.load("push.png")
while True:
  for event.type in event.get():
    if event.type == QUIT:
      exit()
    if event.type == KEYDOWN:
      # a: ^, d: <, c: v, b: >
      print(event.type)
      if "C" in event.type.key:
        xv += 1
        yv = 0
      elif "D" in event.type.key:
        xv += -1
        yv = 0
      elif "A" in event.type.key:
        yv += 1
        xv = 0
      elif "B" in event.type.key:
        yv += -1
        xv = 0
  x += xv
  y += yv
  screen.fill(17, 237, 178)
  screen.blit(box,(x,y))
  display.flip()
  display.update()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

0 Answers0