Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- win = pygame.display.set_mode((500, 480))
- class enemy(object):
- walkRight = [pygame.image.load('Game/R1E.png'), pygame.image.load('Game/R2E.png'), pygame.image.load('Game/R3E.png'),
- pygame.image.load('Game/R4E.png'), pygame.image.load('Game/R5E.png'), pygame.image.load('Game/R6E.png'),
- pygame.image.load('Game/R7E.png'), pygame.image.load('Game/R8E.png'), pygame.image.load('Game/R9E.png'),
- pygame.image.load('Game/R10E.png'), pygame.image.load('Game/R11E.png')]
- walkLeft = [pygame.image.load('Game/L1E.png'), pygame.image.load('Game/L2E.png'), pygame.image.load('Game/L3E.png'),
- pygame.image.load('Game/L4E.png'), pygame.image.load('Game/L5E.png'), pygame.image.load('Game/L6E.png'),
- pygame.image.load('Game/L7E.png'), pygame.image.load('Game/L8E.png'), pygame.image.load('Game/L9E.png'),
- pygame.image.load('Game/L10E.png'), pygame.image.load('Game/L11E.png')]
- def __init__(self, x, y, width, height, end):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.path = [x, end]
- self.walkCount = 0
- self.vel = 3
- self.health = 10
- self.hitbox = (self.x + 17, self.y+2, 31, 57)
- self.health = 10
- self.visible = True
- def draw(self, win):
- self.move()
- if self.visible:
- if self.walkCount + 1 >= 33:
- self.walkCount = 0
- if self.vel > 0:
- win.blit(self.walkRight[self.walkCount // 3], (self.x, self.y))
- self.walkCount += 1
- else:
- win.blit(self.walkLeft[self.walkCount // 3], (self.x, self.y))
- self.walkCount += 1
- def move(self):
- if self.vel > 0:
- if self.x + self.vel < self.path[1]:
- self.x += self.vel
- else:
- self.vel = self.vel * -1
- self.x += self.vel
- self.walkCount = 0
- else:
- if self.x - self.vel > self.path[0]:
- self.x += self.vel
- else:
- self.vel = self.vel * -1
- self.x += self.vel
- self.walkCount = 0
- if self.visible:
- pygame.draw.rect(win, (255, 0, 0), (self.hitbox[0], self.hitbox[1] - 20, 50, 10))
- pygame.draw.rect(win, (0, 128, 0), (self.hitbox[0], self.hitbox[1] - 20, 50 - (5 * (10 - self.health)), 10))
- self.hitbox = (self.x + 17, self.y + 2, 31, 57)
- #pygame.draw.rect(win, (255, 0, 0), self.hitbox, 2)
- def hit(self):
- if self.health > 0:
- self.health -= 1
- else:
- self.visible = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement