Advertisement
Guest User

Enemy.py

a guest
Jul 7th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. import pygame
  2.  
  3. win = pygame.display.set_mode((500, 480))
  4.  
  5. class enemy(object):
  6.     walkRight = [pygame.image.load('Game/R1E.png'), pygame.image.load('Game/R2E.png'), pygame.image.load('Game/R3E.png'),
  7.                  pygame.image.load('Game/R4E.png'), pygame.image.load('Game/R5E.png'), pygame.image.load('Game/R6E.png'),
  8.                  pygame.image.load('Game/R7E.png'), pygame.image.load('Game/R8E.png'), pygame.image.load('Game/R9E.png'),
  9.                  pygame.image.load('Game/R10E.png'), pygame.image.load('Game/R11E.png')]
  10.     walkLeft = [pygame.image.load('Game/L1E.png'), pygame.image.load('Game/L2E.png'), pygame.image.load('Game/L3E.png'),
  11.                 pygame.image.load('Game/L4E.png'), pygame.image.load('Game/L5E.png'), pygame.image.load('Game/L6E.png'),
  12.                 pygame.image.load('Game/L7E.png'), pygame.image.load('Game/L8E.png'), pygame.image.load('Game/L9E.png'),
  13.                 pygame.image.load('Game/L10E.png'), pygame.image.load('Game/L11E.png')]
  14.  
  15.     def __init__(self, x, y, width, height, end):
  16.         self.x = x
  17.         self.y = y
  18.         self.width = width
  19.         self.height = height
  20.         self.path = [x, end]
  21.         self.walkCount = 0
  22.         self.vel = 3
  23.         self.health = 10
  24.         self.hitbox = (self.x + 17, self.y+2, 31, 57)
  25.         self.health = 10
  26.         self.visible = True
  27.     def draw(self, win):
  28.         self.move()
  29.         if self.visible:
  30.             if self.walkCount + 1 >= 33:
  31.                 self.walkCount = 0
  32.  
  33.             if self.vel > 0:
  34.                 win.blit(self.walkRight[self.walkCount // 3], (self.x, self.y))
  35.                 self.walkCount += 1
  36.             else:
  37.                 win.blit(self.walkLeft[self.walkCount // 3], (self.x, self.y))
  38.                 self.walkCount += 1
  39.  
  40.     def move(self):
  41.         if self.vel > 0:
  42.             if self.x + self.vel < self.path[1]:
  43.                 self.x += self.vel
  44.             else:
  45.                 self.vel = self.vel * -1
  46.                 self.x += self.vel
  47.                 self.walkCount = 0
  48.         else:
  49.             if self.x - self.vel > self.path[0]:
  50.                 self.x += self.vel
  51.             else:
  52.                 self.vel = self.vel * -1
  53.                 self.x += self.vel
  54.                 self.walkCount = 0
  55.         if self.visible:
  56.             pygame.draw.rect(win, (255, 0, 0), (self.hitbox[0], self.hitbox[1] - 20, 50, 10))
  57.             pygame.draw.rect(win, (0, 128, 0), (self.hitbox[0], self.hitbox[1] - 20, 50 - (5 * (10 - self.health)), 10))
  58.             self.hitbox = (self.x + 17, self.y + 2, 31, 57)
  59.         #pygame.draw.rect(win, (255, 0, 0), self.hitbox, 2)
  60.     def hit(self):
  61.         if self.health > 0:
  62.             self.health -= 1
  63.         else:
  64.             self.visible = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement