I am teaching this to 5th graders so it needs to be as simple as possible. However, as you see inline 39 I am using stored variables for the function parameters. However is there an easier way? Let's say I wanted to put in a 2nd character I would have to put that long list of variables again?
Should I create a character class? If so, how would I plug that into a parameter?
import pygame
pygame.init()
win = pygame.display.set_mode((1000, 1000))
#Character Details
x = 100
y = 5
width = 10
height = 10
vel = 20
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#Movement Details
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
x -= vel #
if keys[pygame.K_RIGHT]:
x += vel
if keys[pygame.K_UP]:
y -= vel
if keys[pygame.K_DOWN]:
y += vel
#Without this character movement is additive.
win.fill((0, 0, 0))
pygame.draw.rect(win, (245, 100, 50), (x, y, width, height))
pygame.display.update()
```