Recientemente comencé con pygame y estoy tratando de hacer un pequeño proyecto. Voy a agregar inventario y otras cosas a continuación (principalmente porque no estoy seguro de qué agregar a continuación), pero estoy un poco atascado. Hasta ahora, el juego tiene movimiento de cuadrícula y, si haces clic, el personaje se vuelve verde como marcador de posición para usar un arma.
Aquí está mi código hasta ahora. (Si tienes alguna crítica me encantaría escucharla y aprender)
from pygame.locals import *
SCREEN_HEIGHT = 900
SCREEN_WIDTH = 1600
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
mainLoop = True
def drawBackground():
screen.fill((0, 0, 0))
for y in range(50, SCREEN_HEIGHT, 50):
pygame.draw.line(screen, (255, 255, 255), (0, y), (SCREEN_WIDTH, y))
for x in range(50, SCREEN_WIDTH, 50):
pygame.draw.line(screen, (255, 255, 255), (x, 0), (x, SCREEN_HEIGHT))
class Player(pygame.sprite.Sprite):
def __init__(self):
super(Player, self).__init__()
self.surf = pygame.Surface((49, 49))
self.surf.fill((255, 255, 255))
self.rect = self.surf.get_rect(center=(775, 475))
def update(self, event):
if(event.key == K_d):
self.rect.move_ip(50, 0)
if(event.key == K_a):
self.rect.move_ip(-50, 0)
if(event.key == K_s):
self.rect.move_ip(0, 50)
if(event.key == K_w):
self.rect.move_ip(0, -50)
def Inventory():
while True:
pass
drawBackground()
player = Player()
while mainLoop:
ev = pygame.event.get()
drawBackground()
for event in ev:
if(event.type == KEYDOWN):
if(event.key == K_ESCAPE):
mainLoop = False
player.update(event)
elif(event.type == QUIT):
mainLoop = False
if event.type == pygame.MOUSEBUTTONUP:
player.surf.fill((0, 128, 0))
screen.blit(player.surf, player.rect)
pygame.display.flip()