import pygame.locals
import gameCode.player_ant
import gameCode.soil
pygame.init()
display = pygame.display.set_mode((1280, 720))
displaySurface = pygame.Surface(display.get_size())
clock = pygame.time.Clock()
setPlayerX = 0
setPlayerY = 10
esc = True
playerFlipX = False
playerFlipY = False
mousePosX = 0
mousePosY = 0
soilPosGroupX = list()
soilPosGroupY = list()
soilTag = 0
soilGroup = list()
soilGroupLen = len(soilGroup)
print(soilGroupLen)
pointed = True
checkSoil = 0
soilMouse_betweenX = list()
soilMouse_betweenY = list()
soilMouse_betweenX_abs = list()
soilMouse_betweenY_abs = list()
soilMouse_betweenX_min = 0
soilMouse_betweenY_min = 0
soilMouse_betweenX_min_num = 0
soilMouse_betweenY_min_num = 0
soilMouse_betweenX_Last_min = 0
soilMouse_between_min_pos_soilX = 0
soilMouse_between_min_pos_soilY = 0
def sign(number):
if number > 0:
boolReturn = True
elif number < 0:
boolReturn = False
elif number == 0:
boolReturn = None
return boolReturn
while esc:
pygame.display.init()
display.fill((255, 255, 255))
mouseClick1, mouseClick2, mouseClick3 = pygame.mouse.get_pressed()
mousePosX, mousePosY = pygame.mouse.get_pos()
if soilGroupLen > 0:
for checkSoil in range(soilGroupLen):
soilPosGroupX_out = soilPosGroupX[checkSoil]
soilPosGroupY_out = soilPosGroupY[checkSoil]
soilMouse_betweenX[checkSoil] = mousePosX - soilPosGroupX_out
soilMouse_betweenY[checkSoil] = mousePosY - soilPosGroupY_out
soilMouse_betweenX_abs[checkSoil] = abs(soilMouse_betweenX[checkSoil])
soilMouse_betweenY_abs[checkSoil] = abs(soilMouse_betweenX[checkSoil])
if checkSoil == soilGroupLen:
soilMouse_betweenX_min = min(soilMouse_betweenX_abs)
soilMouse_betweenY_min = min(soilMouse_betweenY_abs)
soilMouse_betweenX_min_num = soilMouse_betweenX_abs.index(soilMouse_betweenX_min)
soilMouse_between_min_pos_soilX = soilMouse_betweenX_abs.index(soilMouse_betweenX_min)
soilMouse_between_min_pos_soilY = soilMouse_betweenY_abs.index(soilMouse_betweenY_min)
pointX_bool = sign(soilMouse_between_min_pos_soilX)
pointY_bool = sign(soilMouse_between_min_pos_soilY)
print(pointX_bool)
print(pointY_bool)
if mouseClick1 and soilGroupLen == 0:
soilTag += 1
soilPosXSet = mousePosX - 50
soilPosYSet = mousePosY - 50
soilPosGroupX.append(soilPosXSet)
soilPosGroupY.append(soilPosYSet)
exec("global soilObject%s" % (soilTag))
exec("soilObject%s = pygame.image.load('image/soil.bmp')" % (soilTag))
exec("soilGroup.append(soilObject%s)" % (soilTag))
elif mouseClick1 and soilGroupLen > 0:
soilTag += 1
soilPosXSet = mousePosX - 50
soilPosYSet = mousePosY - 50
soilPosGroupX.append(soilPosXSet)
soilPosGroupY.append(soilPosYSet)
exec("global soilObject%s" % (soilTag))
exec("soilObject%s = pygame.image.load('image/soil.bmp')" % (soilTag))
exec("soilGroup.append(soilObject%s)" % (soilTag))
for event in pygame.event.get():
if event.type == pygame.QUIT:
esc = False
playerObject = gameCode.player_ant.Player(0, playerFlipX, playerFlipY)
playerX, playerFlipX = playerObject.event()
setPlayerX += playerX
display.blit(playerObject.loadImage, (setPlayerX, setPlayerY))
playerRender = pygame.sprite.RenderPlain(playerObject)
playerObject.update()
loopSoilBlit = 0
soilGroupLen = len(soilGroup)
if soilGroupLen > 0:
for loopSoilBlit in range(soilGroupLen):
soilGroup_out = soilGroup[loopSoilBlit]
soilPosGroupX_out = soilPosGroupX[loopSoilBlit]
soilPosGroupY_out = soilPosGroupY[loopSoilBlit]
display.blit(soilGroup_out, (soilPosGroupX_out, soilPosGroupY_out))
else:
pass
pygame.display.flip()
pygame.display.update()
clock.tick(60)
pygame.quit()
Here
soilPosGroupX_out = soilPosGroupX[checkSoil]
soilMouse_betweenX[checkSoil] = mousePosX - soilPosGroupX_out
IndexError: list assignment index out of range
That's what the error. What went wrong?
This is an error message that the operation range of the list has been exceeded.
When judging from only two questions, I think you should look at the Python tutorial first to carry out the code on the question.
© 2024 OneMinuteCode. All rights reserved.