mirror of
https://github.com/OpenBMB/ChatDev.git
synced 2024-09-19 14:17:32 +03:00
23 lines
665 B
Python
23 lines
665 B
Python
'''
|
|
This file contains the Player class.
|
|
'''
|
|
import pygame
|
|
class Player:
|
|
def __init__(self, x, y):
|
|
self.x = x
|
|
self.y = y
|
|
self.width = 50
|
|
self.height = 50
|
|
self.velocity = 2
|
|
def update(self):
|
|
keys = pygame.key.get_pressed()
|
|
if keys[pygame.K_LEFT]:
|
|
self.x -= self.velocity
|
|
if keys[pygame.K_RIGHT]:
|
|
self.x += self.velocity
|
|
if keys[pygame.K_UP]:
|
|
self.y -= self.velocity
|
|
if keys[pygame.K_DOWN]:
|
|
self.y += self.velocity
|
|
def draw(self, window):
|
|
pygame.draw.rect(window, (255, 0, 0), (self.x, self.y, self.width, self.height)) |