Python Basics Pygame Keyboard Input

preview_player
Показать описание
Learn how to use keyword input with pygame for python programming. Using pygame.KEYDOWN event to change location of an image in pygame

Patreon:
Github:
Discord:
Twitter:
twitter: @python_basics

#pythonprogramming #pythonbasics #pythonforever
Рекомендации по теме
Комментарии
Автор

This was helpful! Straight forward with no lame inapplicable crap!

brokentek
Автор

My fellow friend and mentor, this is beyond explanatory and well made! Looking forward to more tutorials in the future! :P

wavy
Автор

Hello, why when i put all the mouvement code into a function i have this message: "local variable 'x' referenced before assignment' i don't understand because the function is at the same place. ty for your videos

bosetti
Автор

What difference between key down and keyup? Please explain me

type
Автор

Why won't my script work (yes, i have created an instance later in the script)?


class Player:
def __init__(self, coords, colour, AI):
self.x, self.y = coords
self.colour = colour
self.AI = AI
self.movement_speed = 0

def draw(self):
pygame.draw.rect(window, self.colour, (self.x, self.y, 20, 40))

def move(self, target):
self.movement_speed *= 0.75
self.y += self.movement_speed
if self.x < 250:
for event in
if event.key == pygame.K_w:
self.movement_speed -= 3
if event.key == pygame.K_s:
self.movement_speed += 3
elif self.AI:
if (target.y + 10) - (self.y + 20) > 10:
self.movement_speed -= 3
if (target.y + 10) - (self.y + 20) < -10:
self.movement_speed += 3
else:
for event in
if event.key == pygame.K_UP:
self.movement_speed -= 2
if event.key == pygame.K_DOWN:
self.movement_speed += 2

davthemillionth
Автор

This looks like it was filmed in a potato

AdrianTheHacker