Я сейчас делаю подводную игру в python. И я пытаюсь заставить врагов в моей игре стрелять. Однако мой код не работает. Я пытался найти проблему сам, но я был безуспешным. Проблема не в синтаксисе, а в семантике. Мой вопрос: как заставить этот код работать? Вот код для стрельбы:
def strelej(self):
#This part of code is supposed to shoot and it triggers, but doesn't want to work
print(self.x-igralec.x)
if self.levo:
#If levo is true projectile starts going to left(smer is negative)
screen.blit(torpL, (self.patronx, self.patrony))
self.patronx += self.v * self.smer
if self.desno:
#If desno is true, projectile starts going right(smer is positive)
screen.blit(torpD, (self.patronx, self.patrony))
self.patronx += self.v * self.smer
def premik(self):
if self.levo:
self.smer = -1
if self.x > self.konc:
screen.blit(nasprotnikL, (self.x, self.y))
self.x -= self.v
if self.x == self.konc:
self.levo = False
self.desno = True
if self.desno:
self.smer = 1
if self.x < self.zac:
screen.blit(nasprotnikD, (self.x, self.y))
self.x += self.v
if self.x == self.zac:
self.levo = True
self.desno = False
if self.x - igralec.x <= 300:
#When distance between player and enemy is less or equal to 300 it triggers shooting
self.strelej()