Делаю ритм-игру. Игра заключается в том, что надо оставаться на дорожке, по которой двигается игрок.
Вот наглядно:
https://drive.google.com/file/d/1KpBerWIb8xXl7wrMo...
Вот код:
import pygame
from pygame.locals import *
import sys
import json
pygame.init()
pygame.mixer.init()
with open('settings.json') as f:
settings = json.load(f)
resolution = (settings["width"], settings["height"])
screen = pygame.display.set_mode(resolution)
pygame.display.set_caption('Tap Tap Beat - Playing')
clock = pygame.time.Clock()
playerX = 256
playerY = 488
speed = 3
motions = ["up", "left", "right"]
motion = "up"
player = pygame.image.load("player.png")
playerRect = pygame.Rect(playerX, playerY, 48, 48)
point_Up = pygame.image.load("point_up.png")
point_Up = pygame.transform.scale(point_Up, (48, 48))
point_Left = pygame.image.load("point_left.png")
point_Left = pygame.transform.scale(point_Left, (48, 48))
point_Right = pygame.image.load("point_right.png")
point_Right = pygame.transform.scale(point_Right, (48, 48))
rotateMap = [1,0,2]
rotates = 0
gameMap = [
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,4,0,0,0,0,0],
[0,0,1,0,0,0,0,0],
[0,0,2,1,3,0,0,0],
[0,0,0,0,1,0,0,0],
[0,0,0,0,1,0,0,0],
[0,0,0,0,1,0,0,0]
]
collisionRects = []
fall = False
for a in range(8):
for b in range(8):
if gameMap[a][b] == 1:
collisionRects.append(pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64)))
if gameMap[a][b] == 2:
collisionRects.append(pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64)))
if gameMap[a][b] == 3:
collisionRects.append(pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64)))
if gameMap[a][b] == 4:
collisionRects.append(pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64)))
def game():
global playerX, playerY, rotates, motion, playerRect
while True:
clock.tick(60)
screen.fill((53, 195, 215))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_SPACE:
try:
motion = motions[rotateMap[rotates]]
rotates += 1
except IndexError:
motion = None
if motion == motions[0]:
playerY -= speed
elif motion == motions[1]:
playerX -= speed
elif motion == motions[2]:
playerX += speed
for a in range(8):
for b in range(8):
if gameMap[a][b] == 1:
pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64))
if gameMap[a][b] == 2:
pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64))
screen.blit(point_Up, (b*64, a*64))
if gameMap[a][b] == 3:
pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64))
screen.blit(point_Left, (b*64, a*64))
if gameMap[a][b] == 4:
pygame.draw.rect(screen, (255, 255, 255), (b*64-8, a*64-8, 64, 64))
screen.blit(point_Right, (b*64, a*64))
playerRect = pygame.Rect(playerX, playerY, 48, 48)
# playerRect = pygame.Rect(playerX, playerY, 48, 48)
# pygame.draw.circle(screen, (255, 0, 0), (playerX, playerY), 20, 2)
screen.blit(player, (playerX, playerY))
pygame.display.flip()
game()
Как сделать так, чтобы при
НЕ соприкосновении игрока с дорожкой, к примеру, закрывалась игра?