У меня относительно простая игра, созданная с помощью pygame. Идея состоит в том, чтобы уклониться от падающих на вас блоков (они называются «вещи» в моем коде). Я хотел бы увеличить скорость этих блоков после каждых 10 уклонений. У меня уже есть уклоненный счетчик, который подсчитывает, сколько уклонено. Я знаю, что могу увеличить скорость всего с thing_speed += 1
после каждого уклонения, но это делает практически невозможным после уклонения около 30. Уклоненное значение - это счетчик, который добавляется после того, как каждый блок исчезает с экрана.
Вот мой код:
import pygame
import time
import random
import base64
import io
import webbrowser
pygame.init()
display_width = 800
display_height = 600
black = (0, 0, 0)
white = (255, 255, 255)
grey = (200, 200, 200)
pepe_width = 70
pepe_height = 70
gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('The Best Game')
clock = pygame.time.Clock()
photo = 'R0lGODudrGfXe1i..........nzveVVABFSQBYIgIBAA7'
photo2 = 'R0lGADNVMzNVZ............jNVmTOAZmYAAOBAAA7'
output = io.BytesIO(base64.b64decode(photo))
output2 = io.BytesIO(base64.b64decode(photo2))
pepeImg = pygame.image.load(output)
bgImg = pygame.image.load(output2)
def things_dodged(count):
font = pygame.font.SysFont(None, 25)
text = font.render("Dodged: " + str(count), True, black)
gameDisplay.blit(text, (10, 10))
def things(thingx, thingy, thingw, thingh, color):
pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh])
def pepe(x, y):
gameDisplay.blit(pepeImg, (x, y))
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def message_display(text):
LargeText = pygame.font.Font('freesansbold.ttf', 70)
TextSurf, TextRect = text_objects(text, LargeText)
TextRect.center = ((display_width / 2), (display_height / 2))
gameDisplay.blit(TextSurf, TextRect)
pygame.display.update()
time.sleep(2)
game_loop()
def crash():
message_display('lel pal u ded')
def game_loop():
x = (display_width * 0.45)
y = (display_height * 0.8)
x_change = 0
y_change = 0
thing_startx = random.randrange(0, display_width)
thing_starty = -600
thing_speed = 3.5
thing_width = 100
thing_height = 100
dodged = 0
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -5
elif event.key == pygame.K_RIGHT:
x_change = 5
elif event.key == pygame.K_UP:
y_change = -5
elif event.key == pygame.K_DOWN:
y_change = 5
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT or event.key == pygame.K_UP or event.key == pygame.K_DOWN:
x_change = 0
y_change = 0
x += x_change
y += y_change
gameDisplay.blit(bgImg, [0,0])
things(thing_startx, thing_starty, thing_width, thing_height, black)
thing_starty += thing_speed
pepe(x, y)
things_dodged(dodged)
if x > display_width - pepe_width or x < 0:
crash()
if y > display_height - pepe_width or y < 0:
crash()
if thing_starty > display_height:
thing_starty = 0 - thing_height
thing_startx = random.randrange(0, display_width)
dodged += 1
thing_speed += 1
if (x < thing_startx + thing_width and x + pepe_width > thing_startx and
y < thing_starty + thing_height and y + pepe_height > thing_starty):
crash()
pygame.display.update()
clock.tick(120)
game_loop()
pygame.quit()
quit()