gpt4 book ai didi

python - 我尝试在游戏中设置白天循环,但是一旦变成夜晚,就不会再回到白天

转载 作者:太空宇宙 更新时间:2023-11-03 21:19:33 25 4
gpt4 key购买 nike

对于我的游戏中的另一个错误,日光周期不起作用我尝试翻转: 时间 = 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()

关于python - 我尝试在游戏中设置白天循环,但是一旦变成夜晚,就不会再回到白天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54411056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com