-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI.py
More file actions
140 lines (133 loc) · 5.09 KB
/
AI.py
File metadata and controls
140 lines (133 loc) · 5.09 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import pygame, math, Constants, Player
from pygame.locals import *
def AI_Run_Jump(self):
'''base AI'''
o=x=sq=tr=lsx=lsy=rsx=rsy=l1=l2=r1=r2=0
#print self.direction
lsx = cmp(self.ddx,0)
#lsx = 1-self.direction*2
changeddir = 0
if self.collisionrect.centerx <= self.prevpos[0]+1 and self.direction ==0:
#this means we stopped going right
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
if self.grounded and self.state/2 in [9]:
self.direction = 1
self.ddx = -1
lsx = -1
elif self.grounded:
changeddir = 1
elif self.collisionrect.centerx >= self.prevpos[0]-1 and self.direction ==1:
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
if self.grounded and self.state/2 in [9]:
#if we're grounded, but not in land animation
self.direction = 0
self.ddx = 1
lsx = 1
elif self.grounded:
changeddir = 1
if self.grounded:
o = changeddir
if self.state/2 in [6,7]:
o = 1
if self.ddy > Constants.GRAV and not self.jump:
o = 1
self.PumpInput({"L1":l1,"L2":l2,"R1":r1,"R2":r2,"X":x,"O":o,"Tri":tr,"Sqr":sq,"LSX":lsx,"LSY":lsy,"RSX":rsx,"RSY":rsy})
def AI_Run_Fall(self):
'''base AI'''
o=x=sq=tr=lsx=lsy=rsx=rsy=l1=l2=r1=r2=0
#print self.direction
lsx = cmp(self.ddx,0)
#lsx = 1-self.direction*2
changeddir = 0
if self.collisionrect.centerx <= self.prevpos[0]+1 and self.direction ==0:
#this means we stopped going right
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
elif self.grounded:
self.direction = 1
self.ddx = -1
lsx = -1
elif self.collisionrect.centerx >= self.prevpos[0]-1 and self.direction ==1:
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
elif self.grounded:
#if we're grounded, but not in land animation
self.direction = 0
self.ddx = 1
lsx = 1
self.PumpInput({"L1":l1,"L2":l2,"R1":r1,"R2":r2,"X":x,"O":o,"Tri":tr,"Sqr":sq,"LSX":lsx,"LSY":lsy,"RSX":rsx,"RSY":rsy})
def AI_Run(self):
'''Runs, when it starts falling it turns around'''
o=x=sq=tr=lsx=lsy=rsx=rsy=l1=l2=r1=r2=0
#print self.direction
lsx = cmp(self.ddx,0)
#lsx = 1-self.direction*2
changeddir = 0
if self.collisionrect.centerx <= self.prevpos[0] and self.direction ==0:
#this means we stopped going right
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
elif self.grounded:
self.direction = 1
self.ddx = -.2
lsx = -1
elif self.collisionrect.centerx >= self.prevpos[0] and self.direction ==1:
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
elif self.grounded:
#if we're grounded, but not in land animation
self.direction = 0
self.ddx = .2
lsx = 1
if not self.grounded:
check = Rect(self.collisionrect.centerx,self.collisionrect.bottom,cmp(self.ddx,0),Constants.TLHGHT/3)
ndir = 1
for obj in self.collideswith:
if check.colliderect(obj.collisionrect):
#grounded,
ndir = 0
break
if ndir:
self.direction = 1-self.direction
lsx = self.ddx = 1-self.direction*2
self.collisionrect.centerx = self.prevpos[0]
self.PumpInput({"L1":l1,"L2":l2,"R1":r1,"R2":r2,"X":x,"O":o,"Tri":tr,"Sqr":sq,"LSX":lsx,"LSY":lsy,"RSX":rsx,"RSY":rsy})
def AI_Run_Tortadillo(self):
'''Runs, when it starts falling it turns around
attacks players.'''
o=x=sq=tr=lsx=lsy=rsx=rsy=l1=l2=r1=r2=0
#print self.direction
lsx = cmp(self.ddx,0)
#lsx = 1-self.direction*2
changeddir = 0
if self.collisionrect.centerx <= self.prevpos[0] and self.direction ==0:
#this means we stopped going right
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
elif self.grounded:
self.direction = 1
self.ddx = -.9
lsx = -1
elif self.collisionrect.centerx >= self.prevpos[0] and self.direction ==1:
if self.state/2 in [6,7,8]:
lsx = 1-self.direction*2
elif self.grounded:
#if we're grounded, but not in land animation
self.direction = 0
self.ddx = .9
lsx = 1
if not self.grounded:
check = Rect(self.collisionrect.centerx,self.collisionrect.bottom,cmp(self.ddx,0),Constants.TLHGHT/3)
ndir = 1
for obj in self.parent.world:
if check.colliderect(obj.collisionrect):
#grounded,
ndir = 0
break
if ndir:
self.direction = 1-self.direction
lsx = self.ddx = 1-self.direction*2
self.collisionrect.centerx = self.prevpos[0]
self.PumpInput({"L1":l1,"L2":l2,"R1":r1,"R2":r2,"X":x,"O":o,"Tri":tr,"Sqr":sq,"LSX":lsx,"LSY":lsy,"RSX":rsx,"RSY":rsy})