Files
pygame-vlz/main.py
T
2026-03-12 14:29:59 +01:00

73 lines
1.3 KiB
Python

from pygame import *
import random
init()
width, height = 1920, 1080
screen = display.set_mode((width, height))
display.set_caption("Game")
clock = time.Clock()
game_font = font.SysFont(None, 40)
white = (255,255,255)
blue = (0,0,255)
red = (255,0,0)
green = (0,255,0)
black = (0, 0, 0)
grey = (180, 180, 180)
speed = 10
p1_x = 100
p1_y = 200
p_size = 100
p2_x = 600
p2_y = 250
running = True
while running:
for e in event.get():
if e.type == QUIT:
running = False
print("Programm closed by user input")
# if e.type == MOUSEBUTTONDOWN:
# m_x, m_y = mouse.get_pos()
# dx = m_x - c_x
# dy = m_y - c_y
# if dx * dx + dy*dy <= c_r * c_r:
# c_color = green if c_color == red else red
keys = key.get_pressed()
if keys[K_LEFT]:
p1_x -= speed
if keys[K_RIGHT]:
p1_x += speed
if keys[K_DOWN]:
p1_y += speed
if keys[K_UP]:
p1_y -= speed
if keys[K_a]:
p2_x -= speed
if keys[K_d]:
p2_x += speed
if keys[K_s]:
p2_y += speed
if keys[K_w]:
p2_y -= speed
screen.fill(white)
draw.rect(screen, blue, (p1_x, p1_y, p_size, p_size))
draw.rect(screen, green, (p2_x, p2_y, p_size, p_size))
display.flip()
clock.tick(60)
quit()