diff --git a/game/constants.py b/game/constants.py index 310ef6c..2babad9 100644 --- a/game/constants.py +++ b/game/constants.py @@ -52,6 +52,11 @@ busts=0 escapes=0 +#powerup constants +spawn=0 +power_picked=0 +power_radius=15 + # text formats game_title_text_large = pygame.font.Font( os.path.join(assets_directory, 'Weston Free.otf'), 120) diff --git a/game/global_objects.py b/game/global_objects.py index 1f9fc8e..f658730 100644 --- a/game/global_objects.py +++ b/game/global_objects.py @@ -281,6 +281,44 @@ def draw(self, screen, color): pygame.draw.circle(screen, wall_silver, (int( self.x), int(self.y)), self.radius - 30, 1) +class Powerup(object): + def __init__(self): + distance=1000 + while distance>strike_bound_radius: + #randomly spawning powerups in rectangle until in circle + self.x=random.randrange(265,635) + self.y=random.randrange(185,555) + dx=self.x-main_game_middle_x + dy=self.y - main_game_middle_y + distance=math.hypot(dx, dy) + def update(self, screen): + global spawn, power_picked, pwoer_radius + if spawn!=0: + #powerup appears for 3 seconds + if spawn<300 and power_picked==0: + pygame.draw.circle(screen,red,(self.x,self.y),power_radius) + spawn-=1 + else: + power_picked=0 + #random cooldown period b/w 6-9 seconds + distance=1000 + while distance>strike_bound_radius: + #randomly spawning powerups in rectangle until in circle + self.x=random.randrange(265,635) + self.y=random.randrange(185,555) + dx=self.x-main_game_middle_x + dy=self.y - main_game_middle_y + distance=math.hypot(dx, dy) + spawn=random.randrange(900,1200) + def touch(self,striker): + global spawn, power_picked + dx=abs(self.x-striker.x) + dy=abs(self.y-striker.y) + distance=math.hypot(dx, dy) + if(distance<=(striker_radius+power_radius) and spawn<300): + #power has been picked + power_picked=1 + class Bricks(pygame.sprite.Sprite): def __init__(self, x, y, VH): diff --git a/game/main.py b/game/main.py index 3572cfe..ba6d55d 100644 --- a/game/main.py +++ b/game/main.py @@ -21,7 +21,7 @@ def init(): global screen, clock, flip_image, score, seconds_first, seconds_second, minutes_first, minutes_second, \ - count_to_seconds, ball, striker, time_count, score_time, hit_count, brick_point, choice, bricks + count_to_seconds, ball, striker, time_count, score_time, hit_count, brick_point, choice, bricks, powerup mute=1 hit_count = 0 # stores number of bricks hit brick_point = 0 # stores the score accumulated by hitting brick @@ -30,6 +30,7 @@ def init(): ball = Ball(main_game_middle_x + 50, main_game_middle_y + strike_bound_radius - 75) striker = Striker(main_game_middle_x, main_game_middle_y) + powerup = Powerup() seconds_first, seconds_second = 0, 0 minutes_first, minutes_second = 0, 0 count_to_seconds = 0 @@ -181,7 +182,7 @@ def check_collisions(): def render_field(): - global flip_image,screen + global flip_image,screen, striker screen.fill(black) @@ -206,6 +207,8 @@ def render_field(): # drawing striker boundary pygame.draw.circle(screen, light_black, (main_game_middle_x, main_game_middle_y), strike_bound_radius) + powerup.update(screen) + powerup.touch(striker) # main game loop diff --git a/game/main.pyc b/game/main.pyc index 5c73012..3faf28c 100644 Binary files a/game/main.pyc and b/game/main.pyc differ