From f13515c9f8b4cbc7e013baa52d669842a3e4681d Mon Sep 17 00:00:00 2001 From: Finn-Luca Ortelbach Date: Thu, 12 Mar 2026 14:45:40 +0100 Subject: [PATCH] teleport --- main.py | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index 2d9a489..ec6b666 100644 --- a/main.py +++ b/main.py @@ -17,18 +17,29 @@ green = (0,255,0) black = (0, 0, 0) grey = (180, 180, 180) - -speed = 10 - -p1_x = 100 -p1_y = 200 +border = Rect(0, 0 , width, height) p_size = 100 -p2_x = 600 -p2_y = 250 +speed = 10 + +c_r = 25 +c_x = random.randint(c_r, width - c_r) +c_x = random.randint(c_r, height - c_r) +c_visible = True +time = 0 + +p1 = Rect(100, 200, p_size, p_size) +p2 = Rect(600, 250, p_size, p_size) + +p1.x = 100 +p1.y = 200 + +p2.x = 600 +p2.y = 250 + running = True while running: @@ -45,27 +56,34 @@ while running: keys = key.get_pressed() if keys[K_LEFT]: - p1_x -= speed + p1.x -= speed if keys[K_RIGHT]: - p1_x += speed + p1.x += speed if keys[K_DOWN]: - p1_y += speed + p1.y += speed if keys[K_UP]: - p1_y -= speed + p1.y -= speed if keys[K_a]: - p2_x -= speed + p2.x -= speed if keys[K_d]: - p2_x += speed + p2.x += speed if keys[K_s]: - p2_y += speed + p2.y += speed if keys[K_w]: - p2_y -= speed + p2.y -= speed + + p1.clamp_ip(border) + p2.clamp_ip(border) + + if p1.colliderect(p2): + p1.topleft = (random.randint(0, width - p_size),random.randint(0, height - p_size)) + p2.topleft = (random.randint(0, width - p_size),random.randint(0, height - p_size)) 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)) + draw.rect(screen, blue, p1) + draw.rect(screen, green, p2) display.flip() clock.tick(60)