我试图在我的游戏中制作一个日光循环,但是一旦变成晚上就不会回到白天
I tried to make a daylight cycle in my game, but once it turns to night it will not go back to day
对于我的游戏中的另一个错误,日光循环将不起作用我尝试翻转位置:
时间 = 0
去,但运气不好,我调查了这个问题,我只找到了为其他语言制作 day/night 的方法,而当我尝试通过其他方式自动将其更改为 day 时,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
条件在"wins"之前计算。
所以 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()
对于我的游戏中的另一个错误,日光循环将不起作用我尝试翻转位置: 时间 = 0 去,但运气不好,我调查了这个问题,我只找到了为其他语言制作 day/night 的方法,而当我尝试通过其他方式自动将其更改为 day 时,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
条件在"wins"之前计算。
所以 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()