#Imported Pygame
import pygame
#The Colors
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
ORANGE = (255, 115, 0)
YELLOW = (242, 255, 0)
BROWN = (115, 87, 39)
PURPLE = (298, 0, 247)
GRAY = (168, 168, 168)
PINK = (255, 0, 234)
pygame.init()
#The Screen
screen = pygame.display.set_mode([1000,500])
#Name of the window
pygame.display.set_caption("My first game")
clock = pygame.time.Clock()
#The sounds
# Positions of graphics
background_position = [0,0]
singleplayer_position = [350, 200]
tutorial_position = [350,300]
sorry_position = [0,0]
developer_position = [0,450]
rules_position = [0,0]
#The graphics
background_image = pygame.image.load("Castle.png").convert()
singleplayer_image = pygame.image.load("SinglePlayer.png").convert()
singleplayer_image.set_colorkey(WHITE)
tutorial_button = pygame.image.load("Tutorial_button.png").convert()
sorry_message = pygame.image.load("Sorry.png").convert()
sorry_message.set_colorkey(WHITE)
developer_message = pygame.image.load("Developer.png").convert()
developer_message.set_colorkey(WHITE)
Rules_image = pygame.image.load("Rules.png").convert()
#Main Loop __________________________
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# Copy of background or main menu
screen.blit(background_image, background_position)
#Copy of other images
mouse_pos = pygame.mouse.get_pos()
my_rect = pygame.Rect(350,200,393,75)
tutorial_rect = pygame.Rect(350,300,393,75)
screen.blit(singleplayer_image, singleplayer_position)
screen.blit(tutorial_button, tutorial_position)
screen.blit(developer_message, developer_position)
if pygame.mouse.get_pressed()[0] and my_rect.collidepoint(mouse_pos):
screen.blit(sorry_message, sorry_position)
correct = False
if pygame.mouse.get_pressed()[0] and my_rect.collidepoint(mouse_pos):
#Here I make the screen fill white
if python.mouse.get_pressed()[0]tutorial_rect.collidepoint(mouse.pos):
correct = True
if correct == True:
screen.blit(Rules_image, rules_position)
pygame.display.flip()
clock.tick(60)
#To quit game
pygame.quit()
これは基本的に私のコードです...私がシングルプレーヤーのボタンを押したとき、私はそれを白くしていますが、そこにはいません。私が一度ヒットしてシングルプレイヤーのボタンを押したときのように、それは白のままですが、私が画面を元に戻したときと同じです。とにかく、以前にやったことのあるものをすべて消去して、シングルプレイヤーボタンを押すと新しい画面を開くことはできますか?ボタンで画面を消去する
あなたが私に与えた答えに戻る。 私はあなたのように私のコードを構造化しました。
if pygame.mouse.get_pressed()[0] and my_rect.collidepoint(mouse_pos):
color_white = True
if color_white = True
screen.fill(WHITE)
これはまだ画面が白くならないため動作しません。 私はこれを試しました。
if pygame.mouse.get_pressed()[0] and my_rect.collidepoint(mouse_pos):
color_white = True
if color_white = True
screen.fill(WHITE)
これは、color_whiteが未定義であると言うことを継続するため、これも動作していないようです。
あなたのコードでは、 'tutorial_rect.collidepoint(mouse_pos)で壊れなります' –
ああtutorial_rectがここにコードを印刷する際に、単にエラーです。実際の画面ではインデントされています。 – HALLOPEOPLE
あなたの質問を編集してみませんか?結腸は何ですか? –