-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecuritas.py
More file actions
83 lines (70 loc) · 2.71 KB
/
securitas.py
File metadata and controls
83 lines (70 loc) · 2.71 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
import arcade
from data import *
import random
class Securitas(arcade.Sprite):
def __init__(self,filename,center_x,center_y,isAngry=False):
super().__init__(filename,SPRITE_SCALING_SECURITAS)
# Initial position
self.center_x=center_x
self.center_y=center_y
# Securitas SETUP
self.can_move= True if isAngry else False
self.isAngry = isAngry
self.static_time = 0 if isAngry else TIME_STATIC
self.BAC = ANGRY_SECURITAS_BAC if isAngry else 0
self.prev_x = None
self.prev_y = None
self.player_around = False
# First movement SETUP
if self.can_move==True:
securitas_initial_direction=random.randrange(1,5,1)
if(securitas_initial_direction==RIGHT):
self.change_x=SECURITAS_SPEED
elif(securitas_initial_direction==LEFT):
self.change_x=(-SECURITAS_SPEED)
elif(securitas_initial_direction==UP):
self.change_y=SECURITAS_SPEED
else :
self.change_y=(-SECURITAS_SPEED)
def update(self,delta_time):
# update prev x y and y
self.prev_x = self.center_x
self.prev_y = self.center_y
# The securitas can move
if self.can_move==True:
securitas_change=random.randrange(1,30,1)
if(securitas_change==1):
securitas_new_direction=random.randrange(1,5,1)
if(securitas_new_direction==RIGHT):
self.change_x = (SECURITAS_SPEED if self.isAngry == False else ANGRY_SECURITAS_SPEED)
elif(securitas_new_direction==LEFT):
self.change_x = (-SECURITAS_SPEED if self.isAngry == False else -ANGRY_SECURITAS_SPEED)
elif(securitas_new_direction==UP):
self.change_y = (SECURITAS_SPEED if self.isAngry == False else ANGRY_SECURITAS_SPEED)
else :
self.change_y= (-SECURITAS_SPEED if self.isAngry == False else -ANGRY_SECURITAS_SPEED)
# The securitas walked into a vomit and he is blocked
if self.static_time<0:
self.can_move=True
self.static_time = 0
else:
self.static_time-=delta_time
def check_for_physic_engine_block(self):
if self.prev_x == self.center_x and self.prev_y == self.center_y :
self.change_x = -self.change_x
self.change_y = -self.change_y
def check_if_player_around(self, player):
dist = arcade.sprite.get_distance_between_sprites(self, player)
self.player_around = True if (dist <= SECURITAS_RADIUS) else False
def check_if_charge_player(self, player):
if self.isAngry and self.player_around:
dist_x = self.center_x - player.center_x
dist_y = self.center_y - player.center_y
if abs(dist_x) <= ANGRY_SECURITAS_SPEED:
self.center_x = player.center_x
else:
self.change_x = ANGRY_SECURITAS_SPEED if dist_x < 0 else -ANGRY_SECURITAS_SPEED
if abs(dist_y) <= ANGRY_SECURITAS_SPEED:
self.center_y = player.center_y
else:
self.change_y = ANGRY_SECURITAS_SPEED if dist_y < 0 else -ANGRY_SECURITAS_SPEED