11from __future__ import annotations
2+
3+ import asyncio
4+ import random
5+
26import pygame as pg
7+
8+ import boosterType
39from vector2d import Vector2D
410from car import Car
511from map import Map
6- from wall import Wall
7- from surface import Surface
8- from surfaceType import SurfaceType
912from stopwatch import Stopwatch
1013from booster import Booster
1114from boosterType import BoosterType
@@ -21,12 +24,6 @@ def __init__(self, refresh_rate):
2124 pg .display .set_caption ("QUICK RACING" )
2225 self .clock = pg .time .Clock ()
2326
24- #move to map
25- # self.all_walls = pg.sprite.Group()
26- # self.all_surfaces = pg.sprite.Group()
27-
28- #it would be nice if booster stayed here
29- self .all_boosters = pg .sprite .Group ()
3027
3128 # btw that's how we can load the map -> read all walls size and location from CSV then create
3229 # them and add them all to sprite group,
@@ -35,6 +32,51 @@ def __init__(self, refresh_rate):
3532
3633 #thought exactly the same thing :) -> can be done today during labs
3734
35+ def spawn_booster (self , map : Map , dt ):
36+
37+ if random .randrange (0 , 256 ) != 8 :
38+ return
39+
40+ place = random .randrange (0 , len (map .places_for_boosters )- 1 )
41+ x_coordinate = random .randrange (map .places_for_boosters [place ][0 ], map .places_for_boosters [place ][2 ])
42+ y_coordinate = random .randrange (map .places_for_boosters [place ][1 ], map .places_for_boosters [place ][3 ])
43+
44+
45+ what_booster = random .randrange (0 ,5 )
46+ new_booster_type = None
47+ change = None
48+
49+ #temp
50+ what_booster = 3
51+
52+ if what_booster == 0 :
53+ new_booster_type = BoosterType .SPEED
54+ change = random .randrange (- 100 , 100 )
55+
56+ elif what_booster == 1 :
57+ new_booster_type = BoosterType .TURNING
58+ change = random .randrange (- 3 , 3 )
59+
60+ elif what_booster == 2 :
61+ new_booster_type = BoosterType .NO_COLLISIONS
62+ change = 1
63+
64+ elif what_booster == 3 :
65+ new_booster_type = BoosterType .DECREASE_TIMER
66+ change = 1
67+
68+ elif what_booster == 4 :
69+ new_booster_type = BoosterType .NO_TURNING
70+ change = 1
71+
72+ elif what_booster == 5 :
73+ new_booster_type = BoosterType .FREEZE
74+ change = 1
75+
76+ map .all_boosters .add (Booster (Vector2D (x_coordinate , y_coordinate ), change , new_booster_type , dt ))
77+ #print("Booster spawned!\n")
78+
79+
3880 def start_timer (self ):
3981 stopwatch = Stopwatch (self .screen , self .clock , Vector2D (1300 , 40 ))
4082 stopwatch .restart_timer (pg .time .get_ticks ())
@@ -51,15 +93,15 @@ def run(self):
5193
5294 x , y = self .screen .get_size ()
5395
54- curr_map = Map (0 , x , y )
96+ run = True
97+ stopwatch = self .start_timer ()
98+
99+ curr_map = Map (0 , x , y , stopwatch )
55100 map_img = pg .image .load ("./data/grass.png" )
56101 curr_map .place_objects ()
57102
58103 car = Car (0 , Vector2D (50 , 100 ), 0 , 0 , 10 , 50 , curr_map )
59104
60- run = True
61- stopwatch = self .start_timer ()
62-
63105 while run :
64106 dt = self .clock .tick (self .refresh )
65107 self .screen .blit (map_img , (0 , 0 ))
@@ -74,6 +116,11 @@ def run(self):
74116 curr_map .all_walls .draw (self .screen )
75117 curr_map .all_walls .update ()
76118
119+ self .spawn_booster (curr_map , dt )
120+
121+ curr_map .all_boosters .draw (self .screen )
122+ curr_map .all_boosters .update ()
123+
77124 car .move (dt ) # maybe car also should be coded as a sprite???
78125 car .update (dt )
79126
0 commit comments