-
Notifications
You must be signed in to change notification settings - Fork 1
/
npc.py
53 lines (46 loc) · 1.72 KB
/
npc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pygame
from pygame.locals import *
class Npc(object):
"""docstring for Npc"""
def __init__(self, img_bas,positionX, positionY, fenetre, perso):
super(Npc, self).__init__()
self.screen = fenetre
self.hero = perso
self.posXInitiale = positionX
self.boolRetour = False
self.boolAlle = True
# On charge les images pour les differentes positions
self.img_bas = pygame.image.load(img_bas).convert_alpha()
#imageDirection par defaut
self.imageDirection = self.img_bas
#Position du personnage en cases et en pixels
self.rectNpc = self.imageDirection.get_rect()
self.rectNpc = self.rectNpc.move(positionX, positionY)
self.alive = True
def event(self, tileMap, camera):
if self.rectNpc.colliderect(self.hero.rectPerso):
print "Collision"
if len(self.hero.bullets_array) > 0:
if self.rectNpc.colliderect(self.hero.bullets_array[0].projectileRect):
self.alive = False
self.animationNpc(tileMap)
self.screen.blit(self.imageDirection, camera.apply(self.rectNpc))
def animationNpc(self, tileMap):
if self.boolAlle == True:
if tileMap.getTile(self.rectNpc.top, self.rectNpc.left+33).passable == True:
self.rectNpc = self.rectNpc.move(1,0)
if self.rectNpc.left >= self.posXInitiale +120:
self.boolRetour = True
self.boolAlle = False
else:
self.boolRetour = True
self.boolAlle = False
if self.boolRetour == True:
if tileMap.getTile(self.rectNpc.top, self.rectNpc.left-3).passable == True and tileMap.getTile(self.rectNpc.top-30, self.rectNpc.left-3).passable == True:
self.rectNpc = self.rectNpc.move(-1,0)
if self.rectNpc.left == self.posXInitiale-30:
self.boolRetour = False
self.boolAlle = True
else:
self.boolRetour = False
self.boolAlle = True