-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolice_car.py
71 lines (68 loc) · 2 KB
/
police_car.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
import pygame
from pygame.locals import *
import random
'''
Purpose:
- To create the sprite of the police car
Parameter:
N/A
Return:
- The police car sprite is made to drive on the road outside th bank
'''
class police(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite. __init__(self)
self.image = pygame.image.load("police_cruiser.gif").convert_alpha()
self.rect = self.image.get_rect()
self.rect.center = (-4500,-200)
'''
Purpose: To move the police car during the player's movements
Parameter:
x: The horizontal movement of the police car
y: The vertical movement of the police car
Return:
- The police car moves smoothly during the player's movements
'''
def update(self,x,y):
self.rect.top += y
self.rect.left += x
'''
Purpose:
- To create the driving movement of the police car and
Parameter:
police1: The sprite and attributes of the police car
police_group: The group containing the police car
send_police: Whether the police car will be sent or not
distance_police: The distance that the police car has traveled
Return:
send_police: Whether the police car will be sent or not (reset)
police_group: The group containing the police car
distance_police: The reset distance of the police car
'''
def drive_by(police1,police_group,send_police,distance_police):
if send_police == 1:
send_police = 2
if send_police > 1:
police1.update(5,0)
distance_police += 5
if distance_police > 6000:
police1.update(-6000,0)
send_police = 0
distance_police = 0
return(send_police,police_group,distance_police)
'''
Purpose:
- To randomly determine whether a police car will appear or not
Parameter:
N/A
Return:
1: The police car will appear
0: The police car will not appear
'''
def random_drive():
drive_num = 1
drive = random.randint(0,2)
if drive == drive_num:
return 1
else:
return 0