ChatDev/WareHouse/RPG_V1_ModelBest1024_20231026174838/player.py

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))