Score and working random teleport
This commit is contained in:
@@ -8,7 +8,7 @@ screen = display.set_mode((width, height))
|
||||
display.set_caption("Game")
|
||||
|
||||
clock = time.Clock()
|
||||
game_font = font.SysFont(None, 40)
|
||||
font = font.SysFont(None, 40)
|
||||
|
||||
white = (255,255,255)
|
||||
blue = (0,0,255)
|
||||
@@ -23,22 +23,29 @@ p_size = 100
|
||||
|
||||
speed = 10
|
||||
|
||||
points_p1 = 0
|
||||
points_p2 = 0
|
||||
|
||||
|
||||
c_r = 25
|
||||
c_d = c_r*2
|
||||
c_x = random.randint(c_r, width - c_r)
|
||||
c_y = random.randint(c_r, height - c_r)
|
||||
|
||||
c_visible = True
|
||||
|
||||
time = 0
|
||||
|
||||
c = Rect(c_x, c_y, c_d, c_d)
|
||||
p1 = Rect(100, 200, p_size, p_size)
|
||||
p2 = Rect(600, 250, p_size, p_size)
|
||||
|
||||
p1.x = 100
|
||||
p1.y = 200
|
||||
def show_score(score_p1, score_p2):
|
||||
score_text = font.render("Punkte P1: " + str(score_p1) + " Punkte P2:" + str(score_p2), True, (0, 0, 0))
|
||||
screen.blit(score_text, (10, 10))
|
||||
|
||||
|
||||
|
||||
p2.x = 600
|
||||
p2.y = 250
|
||||
|
||||
running = True
|
||||
|
||||
@@ -79,7 +86,12 @@ while running:
|
||||
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))
|
||||
|
||||
if p1.colliderect(c):
|
||||
c_x, c_y = (random.randint(0, width - c_d),random.randint(0, height - c_d))
|
||||
points_p1 = points_p1 + 1
|
||||
if p2.colliderect(c):
|
||||
c_x, c_y = (random.randint(0, width - c_d),random.randint(0, height - c_d))
|
||||
points_p2 = points_p2 + 1
|
||||
|
||||
screen.fill(white)
|
||||
draw.rect(screen, blue, p1)
|
||||
@@ -87,6 +99,8 @@ while running:
|
||||
|
||||
if c_visible:
|
||||
draw.circle(screen, red, (c_x, c_y), c_r)
|
||||
c = Rect(c_x, c_y, c_d, c_d)
|
||||
show_score(points_p1, points_p2)
|
||||
|
||||
|
||||
display.flip()
|
||||
|
||||
Reference in New Issue
Block a user