-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcockroach.py~
92 lines (74 loc) · 4.11 KB
/
cockroach.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class Cockroach(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
try:
self.image = pygame.image.load('cockroach.png').convert()
except:
self.image = pygame.Surface((100, 63))
self.rect = self.image.get_rect().move(x, y)
self.moveVector = [0, 0]
self.inAir = True
self.grounded = False
#create huge rect to see if player is on same level
self.rectPlayerCheck = pygame.Rect(x - 100, y + self.image.get_size()[1], 200, 1)
#boolean to check it player is on same platform
self.playerPlatform = False
self.currentPlatform = None #does not start on a platform
def update(self, hero, platforms):
#need to find a way to know if hero is on platform
#this moves towards hero
self.collide(platforms, hero) #make sure hero is passed here
if (self.grounded == True and self.playerPlatform == True):
if (self.rect.x < hero.rect.x):
self.rect.x += 2
if (self.rect.x > hero.rect.x):
self.rect.x -= 2
elif (self.grounded == True):
#if (self.rect.x < platform.x):
self.rect.x += 2
#if (self.rect.x > platform.x + platform.length):
#self.rect.x -= 2
#create a point that is down below platform and if said point stops colliding with platform then turn the
#this moves cockroach downward
if (self.inAir == True):
self.rect.y += 4 #
def draw(self, screen, world):
screen.blit(self.image, self.rect.move(world))
def entityCollide(self, who):
pass
def collide(self, platforms, hero):
self.platformCollide(platforms)
self.HeroOnPlatform(hero)
#check for player collision
#do nothing with dynamics for now
def HeroOnPlatform(self, hero):
#if the player collides with this
if (self.rectPlayerCheck.colliderect(hero.rect)):
self.playerPlatform = True
else:
self.playerPlatform = False
def platformCollide(self, platforms):
#self.grounded = False
for platform in platforms:
rect = self.rect.move((0, self.moveVector[1]))
col = platform.collides(rect)
if col is not None:
if (self.rect.y > platform.rect.y):
self.inAir = True
self.rect.y = rect.y + col.height
self.moveVector[1] = 0
if (self.rect.y < platform.rect.y):
self.inAir = False
self.grounded = True
self.rect.y = rect.y - col.height
self.moveVector[1] = 0
rect = self.rect.move((self.moveVector[0], 0))
col = platform.collides(rect)
if col is not None:
if (self.rect.x < platform.rect.x):
self.rect.x = rect.x - col.width
if (self.rect.x > platform.rect.x):
self.rect.x = rect.x + col.width
self.moveVector[0] = 0
if not grounded:
self.inAir = True