SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position
Возникло исключение:
File "C:\Users\zanae\geme\game.py", line 4, in <module>
from anggrnpslogics import anggrnps
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 5-6: malformed \N character escape (anggrnpslogics.py, line 4)
main.py
import pygame
import sys
from playerlogics import Player
from Anggrnpslogics import Anggrnps #проблемная строка
clock = pygame.time.Clock()
pygame.init()
#размер экрана
lengthx = 1600
widthy = 800
screen = pygame.display.set_mode((lengthx, widthy))
#название
pygame.display.set_caption("Game")
#проверка работы fps
clock = pygame.time.Clock()
FPS = 8
local = pygame.image.load('imege\local.png')
px = 600
py = 400
pspeed = 4
rightborder = lengthx - 50
leftborder = 50
downborder = widthy - 50
upborder = 50
border = [
rightborder,
leftborder,
downborder,
upborder
]
npsspeed = 1
#основной цикл
running = True
while running:
#цвет экрана
screen.blit(local, (0, 0))
pygame.display.flip()
#логика player
pm = Player
Player.movement(pm, px, py, lengthx, widthy, pspeed, border, screen)
px = Player.x
py = Player.y
#логика 1 anggr nps
anps = Anggrnps
Anggrnps.movement(anps, px, py, npsspeed, border, screen)
pygame.display.update()
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
screen.blit(settings, (270, 480))
Anggrnpslogics
import pygame
import random
class Anggrnps ():
demondown = pygame.image.load('imege\NPS_Animation\Npsdbd.png')
anim = 0
direc = 0
randomdirec = random.randint(0, 8)
randomspeed = random.choice([0, 4])
randomlen = random.randint(0, 5)
direc = 0
i = 0
npsx = 1200
npsy = 400
def movement(self, px, py, speed, border, screen):
run = 1
zoneanggr = 50
#D
if self.npsx < border[0]:
direc = 'reght'
if px - zoneanggr < self.npsx:
self.npsx += speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 0:
if self.randomlen == 0:
pass
else:
for self.i in range (self.randomlen):
self.npsx += self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
#A
elif self.npsx > border[1]:
direc = 'left'
if px + zoneanggr > self.npsy:
self.npsx -= speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 1:
for self.i in range (self.randomlen):
self.npsy += self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
#S
elif self.npsy < border[2]:
direc = 'down'
if py - zoneanggr > self.npsy:
self.npsy += speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 2:
for self.i in range (self.randomlen):
self.npsy += self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
#W
elif self.npsy > border[3]:
direc = 'up'
if py - zoneanggr > self.npsy:
self.npsy -= speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 3:
for self.i in range (self.randomlen):
self.npsy -= self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
#DW
elif self.npsx > border[0] and self.npsy > border[3]:
direc = 'right'
if py - zoneanggr > self.npsy and px - zoneanggr < self.npsx:
self.npsy -= speed * run
self.npsy += speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 4:
for self.i in range (self.randomlen):
self.npsy -= self.randomspeed
self.npsx += self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
#WA
elif self.npsx > border[1] and self.npsy > border[3]:
direc = 'left'
if py - zoneanggr > self.npsy:
self.npsx -= speed * run
self.npsy -= speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 5:
for self.i in range (self.randomlen):
self.npsy -= self.randomspeed
self.npsx -= self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
#AS
elif self.npsx > border[1] and self.npsy < border[2]:
direc = 'left'
if px + zoneanggr > self.npsy and py + zoneanggr < self.npsy:
self.npsx -= speed * run
self.npsy += speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 6:
for self.i in range (self.randomlen):
self.npsy += self.randomspeed
self.npsy += self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
#SD
elif self.npsx < border[0] and self.npsy < border[2]:
direc = 'right'
if px - zoneanggr < self.npsx and py - zoneanggr > self.npsy:
self.npsx += speed * run
self.npsy += speed * run
screen.blit(self.demondown, (self.npsx, self.npsy))
elif self.randomdirec == 7:
for self.i in range (self.randomlen):
self.npsx += self.randomspeed
self.npsy += self.randomspeed
screen.blit(self.demondown, (self.npsx, self.npsy))
self.i = 0
else:
if self.anim == False:
pass
else:
screen.blit(self.demondown, (self.npsx, self.npsy))
Ответы (1 шт):
Автор решения: wchistow
→ Ссылка
Дело в том, что символы \<буква>
Python распознаёт как специальный символ. Что бы сказать ему, что это просто символы, нужно поставить перед строкой букву r
:
demondown = pygame.image.load(r'imege\NPS_Animation\Npsdbd.png')
# ^