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

Refactored code and created separate classes for Ball, Brick and Bat #20

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ def read_file(self, file_path):
pass

def run(self):
def vw(x):
return (x / 100) * pygame.display.get_surface().get_width()

def vh(y):
return (y / 100) * pygame.display.get_surface().get_height()

def restart_game():
pygame.mixer.music.load("assets/jazz.ogg")
pygame.mixer.music.play(-1)
screen = pygame.display.get_surface()
scroller_w = round((screen.get_width()) / 10.7)
scroller_h = round((screen.get_height()) / 40)
y_scrol = (screen.get_height() - 10) - scroller_h - 70

self.bat = Bat((vw(50), vh(88)), (vw(11.7), vw(2)))

self.balls = []
new_ball()
self.bat = Bat((screen.get_width() / 2, y_scrol), (scroller_w, scroller_h))

self.lives = 3
self.score = 0
Expand All @@ -120,11 +123,8 @@ def restart_game():
brick_make()

def new_ball():
scroller_w = round((screen.get_width()) / 10.7)
scroller_h = round((screen.get_height()) / 40)
b_diameter = round((scroller_w) / 3.75)
y_scrol = (screen.get_height() - 10) - scroller_h - 70
self.balls.append(Ball(((screen.get_width() - b_diameter) / 2, y_scrol - b_diameter), b_diameter / 2))
r = vw(1.4)
jriyyya marked this conversation as resolved.
Show resolved Hide resolved
self.balls.append(Ball((vw(50), vh(88) - r - 3), r))

def sx(x):
screen = pygame.display.get_surface()
Expand Down