Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. class enemy():
  2.     def __init__(self, x, y, color, radius, end):
  3.         self.x = x
  4.         self.y = y
  5.         self.color = color
  6.         self.radius = radius
  7.         self.end = end
  8.         self.path = [self.x, self.end]
  9.         self.walkCount = 0
  10.         self.vel = 3
  11.  
  12. #Remember to change and fix the draw function once I've got the sprites
  13.     def draw(self, gameWindow):      
  14.         self.move()
  15.         if self.walkCount + 1 <= 33:
  16.             self.walkCount = 0
  17.         if self.vel > 0:
  18.             pygame.draw.circle(gameWindow, self.color, (self.x, self.y), self.radius, 0)
  19.             self.walkCount += 1
  20.         else:
  21.             pygame.draw.circle(gameWindow, self.color, (self.x, self.y), self.radius, 0)
  22.             self.walkCount += 1
  23.  
  24. #The function is supposed to move the enemy by comparing their coordinates with the limits passed to the variable "self.path"
  25.     def move(self):
  26.         if self.vel > 0:
  27.             if self.x + self.vel < self.path[1]:
  28.                 self.x += self.vel
  29.             else:
  30.                 self.vel = self.vel * -1
  31.                 self.walkCount = 0
  32.         else:
  33.             if self.x - self.vel > self.path[0]:
  34.                 self.x += self.vel
  35.             else:
  36.                 self.vel = self.vel * -1
  37.                 self.walkCount = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement