@@ -12,6 +12,7 @@ class Car(pg.sprite.Sprite):
1212 BACK_BOUNCE = 8
1313 FRONT_BASE_ACC = 0.1
1414 BACK_BASE_ACC = 0.03
15+ MAX_SPEED = 100
1516
1617 def __init__ (self , id , position , speed , direction , rotation , engine , name , curr_map : Map ):
1718 pg .sprite .Sprite .__init__ (self )
@@ -36,18 +37,18 @@ def __init__(self, id, position, speed, direction, rotation, engine, name, curr_
3637 self .collision_facilitator = [False , 0 ]
3738
3839 self .mask = pg .mask .from_surface (self .image )
39-
40+
4041 #
41- self .nitro_pow = 2 # power
42- self .nitro_cap = 60 # capacity
43- self .nitro_dur = 40 # duration
44- self .nitro_restore = 0.2 # restoration speed
42+ self .nitro_pow = 2 # power
43+ self .nitro_cap = 60 # capacity
44+ self .nitro_dur = 40 # duration
45+ self .nitro_restore = 0.2 # restoration speed
4546
4647 def update (self , dt ):
4748 self .map .handle_boosters (self )
4849 self .handle_collision_facilitator ()
4950
50- #print("speed b4 everything: ", self.speed)
51+ # print("speed b4 everything: ", self.speed)
5152
5253 if self .boosters ["freeze" ][0 ]:
5354 self .speed = 0
@@ -59,11 +60,15 @@ def update(self, dt):
5960 else :
6061 if collision_test_result [0 ] == "other" :
6162 if self .speed * (1 + self .boosters ["speed" ][0 ]) > 0 :
62- self .position .subtract ((self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .FRONT_BOUNCE ) * cos (radians (self .direction )),
63- (self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .FRONT_BOUNCE ) * sin (radians (self .direction )))
63+ self .position .subtract ((self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .FRONT_BOUNCE ) * cos (
64+ radians (self .direction )),
65+ (self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .FRONT_BOUNCE ) * sin (
66+ radians (self .direction )))
6467 else :
65- self .position .add ((self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .BACK_BOUNCE ) * cos (radians (self .direction )),
66- (self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .BACK_BOUNCE ) * sin (radians (self .direction )))
68+ self .position .add ((self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .BACK_BOUNCE ) * cos (
69+ radians (self .direction )),
70+ (self .speed * (1 + self .boosters ["speed" ][0 ]) + Car .BACK_BOUNCE ) * sin (
71+ radians (self .direction )))
6772
6873 self .speed = - (self .speed * (1 + self .boosters ["speed" ][0 ])) * Car .AIR_RESISTANCE
6974
@@ -72,9 +77,8 @@ def update(self, dt):
7277 else :
7378 self .boosters ["transparent" ] = [True , pg .time .get_ticks () * 40 ]
7479
75- #print("Speed after collision: ", self.speed)
76- #print("_-----------------------_")
77-
80+ # print("Speed after collision: ", self.speed)
81+ # print("_-----------------------_")
7882
7983 new_traction = self .map .handle_collision_with_surfaces (self )
8084 self .map .handle_collision_with_boosters (self )
@@ -106,15 +110,20 @@ def move(self, dt):
106110
107111 if self .speed > 0 :
108112 # print(self.speed, self.speed * (0.1 + self.speed * 0.01))
109- self .speed -= (self .speed * (1 + self .boosters ["speed" ][0 ])) * (Car .FRONT_BASE_ACC + (self .speed * (1 + self .boosters ["speed" ][0 ])) * 0.15 * Car .AIR_RESISTANCE ) # v drogi i v*v powietrza //static variables -NEEDED!
113+ self .speed -= (self .speed * (1 + self .boosters ["speed" ][0 ])) * (Car .FRONT_BASE_ACC + (self .speed * (
114+ 1 + self .boosters ["speed" ][0 ])) * 0.15 * Car .AIR_RESISTANCE ) # v drogi i v*v powietrza //static variables -NEEDED!
110115 elif self .speed < 0 :
111116 self .speed += (self .speed * (1 + self .boosters ["speed" ][0 ])) * (
112- Car .BACK_BASE_ACC + (self .speed * (1 + self .boosters ["speed" ][0 ])) * Car .AIR_RESISTANCE ) # v drogi i v*v powietrza
117+ Car .BACK_BASE_ACC + (
118+ self .speed * (1 + self .boosters ["speed" ][0 ])) * Car .AIR_RESISTANCE ) # v drogi i v*v powietrza
119+
120+ self .speed = min (self .speed , Car .MAX_SPEED ) # so the car doesn't enter "hyperspeed"
113121
114122 def rotate_left (self , dt ):
115123 if self .speed != 0 :
116- self .direction = (self .direction - (Car .TURNING_CAPABILITY + self .boosters ["turning" ][0 ]) * (self .speed * (1 + self .boosters ["speed" ][0 ])) * self .rotation / (
117- dt ** 2 )) % 360
124+ self .direction = (self .direction - (Car .TURNING_CAPABILITY + self .boosters ["turning" ][0 ]) * (
125+ self .speed * (1 + self .boosters ["speed" ][0 ])) * self .rotation / (
126+ dt ** 2 )) % 360
118127
119128 if self .direction < 0 :
120129 self .direction += 360
@@ -126,8 +135,9 @@ def rotate_left(self, dt):
126135
127136 def rotate_right (self , dt ):
128137 if self .speed != 0 :
129- self .direction = (self .direction + (Car .TURNING_CAPABILITY + self .boosters ["turning" ][0 ]) * (self .speed * (1 + self .boosters ["speed" ][0 ])) * self .rotation / (
130- dt ** 2 )) % 360
138+ self .direction = (self .direction + (Car .TURNING_CAPABILITY + self .boosters ["turning" ][0 ]) * (
139+ self .speed * (1 + self .boosters ["speed" ][0 ])) * self .rotation / (
140+ dt ** 2 )) % 360
131141 if self .direction > 360 :
132142 self .direction -= 360
133143
@@ -143,12 +153,12 @@ def accelerate(self, dt):
143153
144154 def decelerate (self , dt ):
145155 self .speed -= self .engine / (2 * dt )
146-
156+
147157 def nitro_acc (self ):
148158 self .speed += self .nitro_pow * (lambda x : 1 if x >= 0 else - 1 )(self .speed )
149159
150160 def handle_collision_facilitator (self ):
151161 self .collision_facilitator [1 ] -= pg .time .get_ticks ()
152162 if self .collision_facilitator [1 ] <= 0 :
153163 self .collision_facilitator [0 ] = False
154- self .collision_facilitator [1 ] = 0
164+ self .collision_facilitator [1 ] = 0
0 commit comments