teleport
This commit is contained in:
@@ -17,18 +17,29 @@ green = (0,255,0)
|
|||||||
black = (0, 0, 0)
|
black = (0, 0, 0)
|
||||||
grey = (180, 180, 180)
|
grey = (180, 180, 180)
|
||||||
|
|
||||||
|
border = Rect(0, 0 , width, height)
|
||||||
speed = 10
|
|
||||||
|
|
||||||
p1_x = 100
|
|
||||||
p1_y = 200
|
|
||||||
|
|
||||||
p_size = 100
|
p_size = 100
|
||||||
|
|
||||||
p2_x = 600
|
speed = 10
|
||||||
p2_y = 250
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
running = True
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
@@ -45,27 +56,34 @@ while running:
|
|||||||
|
|
||||||
keys = key.get_pressed()
|
keys = key.get_pressed()
|
||||||
if keys[K_LEFT]:
|
if keys[K_LEFT]:
|
||||||
p1_x -= speed
|
p1.x -= speed
|
||||||
if keys[K_RIGHT]:
|
if keys[K_RIGHT]:
|
||||||
p1_x += speed
|
p1.x += speed
|
||||||
if keys[K_DOWN]:
|
if keys[K_DOWN]:
|
||||||
p1_y += speed
|
p1.y += speed
|
||||||
if keys[K_UP]:
|
if keys[K_UP]:
|
||||||
p1_y -= speed
|
p1.y -= speed
|
||||||
|
|
||||||
if keys[K_a]:
|
if keys[K_a]:
|
||||||
p2_x -= speed
|
p2.x -= speed
|
||||||
if keys[K_d]:
|
if keys[K_d]:
|
||||||
p2_x += speed
|
p2.x += speed
|
||||||
if keys[K_s]:
|
if keys[K_s]:
|
||||||
p2_y += speed
|
p2.y += speed
|
||||||
if keys[K_w]:
|
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)
|
screen.fill(white)
|
||||||
draw.rect(screen, blue, (p1_x, p1_y, p_size, p_size))
|
draw.rect(screen, blue, p1)
|
||||||
draw.rect(screen, green, (p2_x, p2_y, p_size, p_size))
|
draw.rect(screen, green, p2)
|
||||||
display.flip()
|
display.flip()
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user