I tried to show a character in my window at a certain point. What am I doing wrong?
This is for my first game and I am new to pygame. I tried the code, that google gave me.
screenwidth = 800
screenheight = 600
win = pygame.display.set_mode((screenwidth, screenheight))
bg = pygame.image.load("bg.png")
char = pygame.image.load("char.png")
x = 400
y = 300
vel = 5
isJumping = False
running = True
clock = pygame.time.Clock()
def redrawBackground():
win.blit(bg, (0, 0))
pygame.display.update()
def player(x, y):
win.blit(char, (x, y))
while running:
clock.tick(60)
pygame.time.delay(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
player_one_x -= vel
if keys[pygame.K_RIGHT]:
player_one_x += vel
if not(isJumping):
if keys[pygame.K_SPACE]:
for i in range(10):
player_one_y -= vel
isJumping = True
player(x, y)
redrawBackground()
I expect the result of this code to show the file named "char.png", but it didn't show up.