对于我的游戏中的另一个错误,日光周期不起作用我尝试翻转: 时间 = 0是的,但运气不好,我研究了这个问题,只找到了为其他语言设置白天/夜晚的方法,而当我尝试通过其他方式自动将其更改为白天时,Python 不喜欢它。
正如我所描述的,我尝试翻转位置:
Time = 0
进入:
elif Time >= 4800:
Time = 0
Raycast('Textures/Screens/Skybox/Earth',0,0,800,600)
ReDisplayItem()
但运气不好,我什至尝试使用 while 语句,但 python 不喜欢这样。
import pygame
#2000,1001
pygame.init()
Screen = "None"
Sobj = "None"
Width = 800
Height = 600
Time = 0
Frame = pygame.display.set_mode((Width,Height))
pygame.display.set_caption("HypoPixel")
FPS = pygame.time.Clock()
def ReDisplayItem():
if Sobj == "None":
Raycast('Textures/Extra/ItemBox.png',0,0,160,160)
elif Sobj == "Loom":
Raycast('Textures/Extra/IBO.png',0,0,160,160)
Raycast('Textures/Blocks/loom_side.png',10,10,140,140)
def Raycast(TTR, RayXPos, RayYPos, RaySizeX, RaySizeY):
RaycastThis = pygame.image.load(TTR)
RaycastThis = pygame.transform.scale(RaycastThis,(RaySizeX,RaySizeY))
Frame.blit(RaycastThis, (RayXPos, RayYPos))
Loop = True
Raycast('Textures/Screens/Skybox/Earth.png',0,0,800,600)
Raycast('Textures/Extra/ItemBox.png',0,0,160,160)
while Loop == True:
Time = Time + 1
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if event.type == pygame.KEYDOWN:
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
exit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_0:
Raycast('Textures/Extra/ItemBox.png',0,0,160,160)
Sobj = "None"
elif event.type == pygame.KEYDOWN and event.key == pygame.K_1:
Raycast('Textures/Blocks/loom_side.png',10,10,140,140)
Sobj = "Loom"
if Time >= 2400:
Raycast('Textures/Screens/Skybox/EarthNight.png',0,0,800,600)
ReDisplayItem()
elif Time >= 4800:
Time = 0
Raycast('Textures/Screens/Skybox/Earth',0,0,800,600)
ReDisplayItem()
pygame.display.update()
FPS.tick(60)
我以为黑夜会变成白天,但晚上只是一片漆黑。
当条件Time >= 4800
时满足,则Time >= 2400
也满足了。
elif
中的语句列表语句永远不会执行,因为 if
条件之前已评估并“获胜”。
所以if
条件必须是Time >= 2400 and Time < 4800
:
if Time >= 2400 and Time < 4800:
Raycast('Textures/Screens/Skybox/EarthNight.png',0,0,800,600)
ReDisplayItem()
elif Time >= 4800:
Time = 0
Raycast('Textures/Screens/Skybox/Earth',0,0,800,600)
ReDisplayItem()
或者情况的顺序必须颠倒:
if Time >= 4800:
Time = 0
Raycast('Textures/Screens/Skybox/Earth',0,0,800,600)
ReDisplayItem()
elif Time >= 2400:
Raycast('Textures/Screens/Skybox/EarthNight.png',0,0,800,600)
ReDisplayItem()
我是一名优秀的程序员,十分优秀!