0

I'm currently making submarine game in python. And I try to make enemies in my game shoot. However my code doesn't work. I tried to find the problem myself, but I was unsucesfull. The problem isn't syntax, but semantics. My question is: how to make this code work? Here 's the code for shooting:

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()
  • 1
    Please explain the problem you're experiencing and the result you're expecting. Since you've written your code in another language (try to always write your code in English) and not provided an [mcve], we can neither understand or test your code to find a solution to the problem. – Ted Klein Bergman Mar 21 '20 at 17:27
  • @TedKleinBergman I'm expecting that enemy to shoot in my game. I will now add some comments to my code, so you will understand what does what. – Jonatan Jurkovnik Mar 21 '20 at 17:40
  • And you're sure it's because of this segment of code? The problem is that we cannot understand this snippet without the full context. I don't know what your variables are, how they're assigned and how they're are changed. Therefore, it's not possible to understand where the problem lies. And the comments doesn't really help as I don't know what the variables and attributes are supposed to do and represent. So you need to translate your code to English and create a [mcve]. My guess would be that your branches (`levno` and `deno`) are never entered, but that's just a wild shoot in the dark – Ted Klein Bergman Mar 21 '20 at 17:53
  • I'm pretty sure. This is the only part of code, that hhandles enemy shooting. I will add some more explanation to code – Jonatan Jurkovnik Mar 21 '20 at 18:09
  • Nevermind I now found the problem. Thank you for your time and sorry for wasting your time – Jonatan Jurkovnik Apr 06 '20 at 13:13

0 Answers0