-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
35 lines (27 loc) · 982 Bytes
/
bot.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
import noise
import numpy
import random
import config
inaccuracy = 0.4
_step = 0.0
def play(player, balls):
global _step
_step += 0.001
_step %= 1
left = False
right = False
ball_to_follow = balls.sprites()[0]
trigger_range_offset = numpy.interp(ball_to_follow.rect.y, [0, config.PLAYER_Y - 10], [400, 0])
trigger_range = (player.rect.centerx - trigger_range_offset/2, player.rect.centerx + trigger_range_offset/2)
for ball in balls:
if ball.sticky and random.randint(0, 50) == 11:
ball.sticky = False
if not trigger_range[0] < ball_to_follow.rect.centerx < trigger_range[1]:
offset = numpy.interp(noise.pnoise1(_step), [0, 1],
[-player.rect.width * inaccuracy, player.rect.width * inaccuracy])
# print(offset)
if player.rect.centerx > ball_to_follow.rect.centerx + offset:
left = True
else:
right = True
return left, right