Skip to content

Commit

Permalink
build spec
Browse files Browse the repository at this point in the history
  • Loading branch information
AvaAvarai committed Jul 25, 2023
1 parent 75ae95c commit 0d04879
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 24 deletions.
50 changes: 50 additions & 0 deletions Breaker.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

added_files = [

("assets\\image", "assets\\image"),
("assets\\audio", "assets\\audio")

]

a = Analysis(
['main.py'],
pathex=[],
binaries=[],
datas=added_files,
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='Breaker',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['assets\\image\\ball.ico']
)
Binary file modified assets/image/ball.ico
Binary file not shown.
35 changes: 21 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
import pickle
import random

import sys, os

FPS_TARGET = 60
WIN_WIDTH = 480
WIN_HEIGHT = 640
UI_HEIGHT = 45

def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)

def default_player_pos() -> pygame.rect.Rect:
return pygame.rect.Rect(WIN_WIDTH * 0.5 - 30, WIN_HEIGHT - 55, 60, 15)

Expand Down Expand Up @@ -55,7 +62,7 @@ def create_bricks(level_number: int) -> list[list]:
return level

def play_level_music(level_number: int) -> None:
pygame.mixer.music.load('assets/audio/level' + str(((level_number-1) % 5) + 1) + '.ogg')
pygame.mixer.music.load(resource_path(r'assets\audio\level' + str(((level_number-1) % 5) + 1) + '.ogg'))
pygame.mixer.music.play(-1)

class game:
Expand All @@ -65,13 +72,13 @@ def __init__(self, screen) -> None:
self.screen = screen
play_level_music(1)

self.background_image: pygame.surface.Surface = pygame.image.load('assets/image/background.jpg')
self.frame_image: pygame.surface.Surface = pygame.image.load('assets/image/frame.png')
self.ball_image: pygame.surface.Surface = pygame.image.load('assets/image/ball.png')
self.paddle_image: pygame.surface.Surface = pygame.image.load('assets/image/paddle.png')
self.paddle_icon_image: pygame.surface.Surface = pygame.image.load('assets/image/paddle_icon.png')
self.powerup1_image: pygame.surface.Surface = pygame.image.load('assets/image/powerup1.png') # B
self.powerup2_image: pygame.surface.Surface = pygame.image.load('assets/image/powerup2.png') # L
self.background_image: pygame.surface.Surface = pygame.image.load(resource_path(r'assets\image\background.jpg'))
self.frame_image: pygame.surface.Surface = pygame.image.load(resource_path(r'assets\image\frame.png'))
self.ball_image: pygame.surface.Surface = pygame.image.load(resource_path(r'assets\image\ball.png'))
self.paddle_image: pygame.surface.Surface = pygame.image.load(resource_path(r'assets\image\paddle.png'))
self.paddle_icon_image: pygame.surface.Surface = pygame.image.load(resource_path(r'assets\image\paddle_icon.png'))
self.powerup1_image: pygame.surface.Surface = pygame.image.load(resource_path(r'assets\image\powerup1.png')) # B
self.powerup2_image: pygame.surface.Surface = pygame.image.load(resource_path(r'assets\image\powerup2.png')) # L

self.fg_font: pygame.font.Font = pygame.font.SysFont(pygame.font.match_font("cascadiamonoregular"), 32)
self.fg_font_color1: tuple[int, int, int] = (255, 0, 0)
Expand Down Expand Up @@ -132,7 +139,7 @@ def start(self):
# --- BRICK COLLIDE ---
for block in self.bricks:
if self.ball_pos.colliderect(block[0], block[1], 36, 15):
pygame.mixer.Sound.play(pygame.mixer.Sound("assets/audio/ping.wav"))
pygame.mixer.Sound.play(pygame.mixer.Sound(resource_path(r'assets\audio\ping.wav')))
if random.randint(1, 10) == 10: # 10%
self.powerups.append([block[0], block[1]+10, 1])
if random.randint(1, 20) == 20: # 5%
Expand Down Expand Up @@ -191,7 +198,7 @@ def start(self):
self.powerups.remove(powerup)
powerup[1] += 100 * self.dt

# --- PLAYER/BALL DRAW ---
# --- PLAYER\BALL DRAW ---
self.screen.blit(self.ball_image, self.ball_pos)
self.screen.blit(self.paddle_image, self.player_pos)

Expand All @@ -201,7 +208,7 @@ def start(self):
# --- BALL PHYSICS ---
if self.ball_pos.centery > WIN_HEIGHT: # dead
if self.lives > 0:
pygame.mixer.Sound.play(pygame.mixer.Sound("assets/audio/drop.wav"))
pygame.mixer.Sound.play(pygame.mixer.Sound(resource_path(r'assets\audio\drop.wav')))
self.lives -= 1
self.player_pos = default_player_pos()
self.ball_pos = default_ball_pos()
Expand All @@ -211,7 +218,7 @@ def start(self):
self.ball_dir_y = 1
self.ball_ang = 0
else:
pygame.mixer.Sound.play(pygame.mixer.Sound("assets/audio/crash.wav"))
pygame.mixer.Sound.play(pygame.mixer.Sound(resource_path(r'assets\audio\crash.wav')))
self.__init__(self.screen)

if self.ball_pos.centerx < 15:
Expand All @@ -222,7 +229,7 @@ def start(self):
if self.ball_pos.centery < UI_HEIGHT + 10:
self.ball_dir_y *= -1

# --- BALL/PLAYER COLLIDE ---
# --- BALL\PLAYER COLLIDE ---
if self.ball_pos.colliderect(self.player_pos):
self.ball_dir_y = -1
self.ball_dir_x = 1
Expand Down Expand Up @@ -258,7 +265,7 @@ def start(self):
if __name__ == "__main__":
pygame.init()
pygame.display.set_caption('Breaker')
pygame.display.set_icon(pygame.image.load('assets/image/ball.ico'))
pygame.display.set_icon(pygame.image.load(resource_path(r'assets\image\ball.ico')))
screen: pygame.surface.Surface = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
new_game = game(screen)
new_game.start()
Expand Down
10 changes: 0 additions & 10 deletions pack_executable.py

This file was deleted.

0 comments on commit 0d04879

Please sign in to comment.