-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaimTrainer.py
127 lines (107 loc) · 3.39 KB
/
aimTrainer.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
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
#Aim trainer
import pygame, sys, random, time, math
check_errors = pygame.init()
if check_errors[1] > 0:
print("(!) Had {0} initialising errors".format(check_errors[1]))
print("Exiting...")
sys.exit(-1)
else:
print("(+) PyGame successfully initialised!")
#Play Surface
width = 1280
height = 720
playSurface = pygame.display.set_mode((width, height))
pygame.display.set_caption('Aim trainer')
#Colo(u)rs
black = pygame.Color(0, 0, 0)
white = pygame.Color(255, 255, 255)
#FPS controller
tick_rate = 30
fpsController = pygame.time.Clock()
#Game state
tickCounter = 0
spawnTargetTimer = 30
aimPoints = []
score = 0
lives = 3
widthMax = 40
#Game over function
def gameOver():
myFont = pygame.font.SysFont('monaco', 72)
gameOverSurface = myFont.render('Game Over!', True, white)
gameOverRectangle = gameOverSurface.get_rect()
gameOverRectangle.midtop = (width/2, height/20)
playSurface.blit(gameOverSurface, gameOverRectangle)
showScore(0)
pygame.display.flip()
time.sleep(3)
pygame.quit()
sys.exit()
def showScore(choice=1):
sFont = pygame.font.SysFont('monaco', 36)
scoreSurface = sFont.render('Score: {0}'.format(score), True, white)
scoreRectangle = scoreSurface.get_rect()
if choice == 1:
scoreRectangle.midtop=(width/20,height/20)
else:
scoreRectangle.midtop=(width/2,height/4)
playSurface.blit(scoreSurface,scoreRectangle)
def showMisses():
sFont = pygame.font.SysFont('monaco', 36)
scoreSurface = sFont.render('Lives: {0}'.format(lives), True, white)
scoreRectangle = scoreSurface.get_rect()
scoreRectangle.midtop=(width-(width/20),height/20)
playSurface.blit(scoreSurface,scoreRectangle)
def timer():
tFont = pygame.font.SysFont('monaco', 24)
def distance(A, B):
return math.sqrt((A[0] - B[0])**2 + (A[1] - B[1])**2)
#Main game logic
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.event.post(pygame.event.Event(pygame.quit))
if event.type == pygame.MOUSEBUTTONDOWN:
foundPoint = False
for point in aimPoints:
if not foundPoint and distance(event.pos, point) < point[2]:
if point[3]:
score+= (widthMax - point[2])
else:
score+= (50 + (widthMax - point[2]))
foundPoint = True
aimPoints.remove(point)
if not foundPoint:
lives-=1
if tickCounter == spawnTargetTimer:
tickCounter = 0
aimPoints.insert(0,
[random.randrange(1,width),
random.randrange(1,height), 0, False])
print(aimPoints)
else:
tickCounter+=1
playSurface.fill(black)
for point in aimPoints:
if point[3]:
if point[2] == 0:
aimPoints.remove(point)
lives-=1
else:
point[2]-=1
else:
if point[2] == widthMax:
point[3] = True
point[2]+=1
pygame.draw.circle(playSurface, white,
(point[0], point[1]), point[2])
if lives == 0:
gameOver()
showScore()
showMisses()
pygame.display.flip()
fpsController.tick(tick_rate)