Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powerups #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions game/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions game/global_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions game/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -181,7 +182,7 @@ def check_collisions():

def render_field():

global flip_image,screen
global flip_image,screen, striker

screen.fill(black)

Expand All @@ -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

Expand Down
Binary file modified game/main.pyc
Binary file not shown.