-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaitestrun.py
More file actions
168 lines (136 loc) · 4.62 KB
/
aitestrun.py
File metadata and controls
168 lines (136 loc) · 4.62 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#Game y Me <)
#ant w*h=150*250
#things w*h=180*100
import pygame
import time
import random
pygame.init()
crsound=pygame.mixer.Sound('sound/wallhit.wav')
lane=pygame.mixer.Sound('sound/lane.wav')
pygame.mixer.music.load('sound/main.wav')
white= (204, 230, 255)
kaala=(20, 20, 12)
red=(255,0,0)
w=800
h=600
cw=150
ch=250
tw=180
th=100
gameDis=pygame.display.set_mode((w,h))
pygame.display.set_caption('Idiot AnB')
#ITS like refreshing rate
clk=pygame.time.Clock()
pause=True
img= pygame.image.load('images/ant.png')
over= pygame.image.load('images/gover.png')
gwd=150
#characters image array
thing=[pygame.image.load('images/im (1).png'),pygame.image.load('images/im (2).png'),pygame.image.load('images/im (3).png'),pygame.image.load('images/im (4).png'),pygame.image.load('images/im (5).png'),pygame.image.load('images/im (6).png'),pygame.image.load('images/im (7).png')]
def gameHd(caption):
pygame.display.set_caption(caption)
def tdodge(count):
strin='SCORE : '+str(count)
msg(strin,0,0,30,red)
def msg(text,posx,posy,f_size,clr):
font =pygame.font.SysFont(None,f_size)
text1=font.render(text,True,clr)
gameDis.blit(text1,(posx,posy))
pygame.display.update()
#def pause():
# while pause:
# msg=('Game paused press space again to start!',50,h/2
def idiot(x,y):
gameDis.blit(img,(x,y))
def things(thingx,thingy,thingty): #tn=thing numer
gameDis.blit(thingty,(thingx,thingy))
def gameOver(typeof,dodge):
pygame.mixer.music.stop()
pygame.mixer.Sound.play(crsound)
time.sleep(1)
text="You Crashed into "+typeof+"! Your score : "+str(dodge)
msg(text,20,h/2,55,red)
gameHd("GAme Over !"+"\U0001F622")
time.sleep(1)
msg('Do you want to Play again?press Y or N',10,h/4,40,red)
time.sleep(3)
for event in pygame.event.get():
print(event)
if event.type==pygame.QUIT:
pygame.quit()
quit()
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_y:
game()
if event.key==pygame.K_n:
gameDis.blit(over,(0,0))
pygame.display.update()
time.sleep(1)
#game()
pygame.quit()
quit()
def game():
fll=w/16 #first left limit for rectangular strip
sll= (6*w)/16 #second left limit for same
tll=(11*w)/16
pygame.mixer.music.play(-1)
#x and y co ordinates of girl character
x= sll+50
y=h*0.8
dodge=0
thingstartx=random.choice([sll,fll,sll,tll])
thingstarty=-600
thingspeed=3
thingnum=random.choice(thing)
crashed= False
while not crashed:
#pygame.mixer.music.play(-1)
for event in pygame.event.get():
if event.type==pygame.QUIT:
crashed= True
#print(event)
if event.type==pygame.KEYDOWN:
#pygame.mixer.Sound.play(lane)
if event.key==pygame.K_LEFT:
pygame.mixer.Sound.play(lane)
x-=250
if event.key==pygame.K_RIGHT:
pygame.mixer.Sound.play(lane)
x+=250
if event.type==pygame.KEYUP:
if event.key==pygame.K_LEFT or event.key==pygame.K_RIGHT:
x=x
gameDis.fill(white) #use to display the white ackground
pygame.draw.rect(gameDis, kaala, [fll, 0, w/4,h], 0)
pygame.draw.rect(gameDis, kaala, [sll, 0, w/4,h], 0)
pygame.draw.rect(gameDis, kaala, [tll, 0, w/4,h], 0)
#things(thingx,thingy,tn)
things(thingstartx,thingstarty,thingnum)
thingstarty += thingspeed
idiot(x,y)
tdodge(dodge)
if x<-50 or x>w-(gwd/2):
#msg(text,posx,posy,f_size,clr):
gameOver(" Wall",dodge)
if thingstarty > h:
dodge+=1
thingspeed+=0.3
thingstarty = 0-th
thingstartx=random.choice([fll,sll,tll])
thingnum=random.choice(thing)
#print(thingspeed)
if thingstarty+th-20 > y and x==thingstartx+50 :
if thingstartx==fll :
x+=250
if thingstartx==sll:
x=random.choice([x+250,x-250])
if thingstartx==tll:
x-=250
gameOver(" enemy",dodge)
pygame.display.update()
clk.tick(120)
game()
event=pygame.event.get()
print (event)
pygame.quit()
quit()