-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.py
117 lines (85 loc) · 2.97 KB
/
globals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import pygame
import sys
import os
from PIL import Image, ImageEnhance
os.system("cls")
# PyGame settings
pygame.init()
pygame.font.init()
pygame.mixer.init()
# Screen settings
WIDTH, HEIGHT = 1200, 800
win = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Atari breakout!')
big_font = pygame.font.SysFont('Roboto', int(WIDTH/10))
normal_font = pygame.font.SysFont('Roboto', 50)
fpsClock = pygame.time.Clock()
def check_closed():
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
def safe_div(x, y):
'''
This function returns the division of two numbers if one of the two is not equal to zero. Otherwise it wil return zero. It is a protection against a zero division.
'''
if y == 0:
return 0
return x/y
def surface_to_PIL(surface):
raw_str = pygame.image.tostring(surface, "RGBA", False)
image = Image.frombytes("RGBA", surface.get_size(), raw_str)
return image
def PIL_to_surface(image):
raw_str = image.tobytes("raw", "RGBA")
surface = pygame.image.fromstring(raw_str, image.size, "RGBA")
return surface
def brightness(image, brightness):
return ImageEnhance.Brightness(image).enhance(brightness)
# Path settings
path = os.path.dirname(__file__)
res_path = os.path.join(path, "resources")
img_path = os.path.join(res_path, "images")
sound_path = os.path.join(res_path, "audio")
# Resouces settings
start_button_image = pygame.image.load(os.path.join(img_path, "start.png"))
start_button_hover_image = pygame.image.load(os.path.join(img_path, "start_hover.png"))
ball_image = pygame.image.load(os.path.join(img_path, "ball.png"))
paddle_image = pygame.image.load(os.path.join(img_path, "paddle.png"))
easterEgg_image_path = os.path.join(img_path, "easter_egg.png")
easterEgg_image = pygame.image.load(easterEgg_image_path)
easterEgg_image_fliped_PIL = Image.open(easterEgg_image_path).transpose(Image.FLIP_LEFT_RIGHT)
easterEgg_image_fliped = PIL_to_surface(easterEgg_image_fliped_PIL)
bounce_sound = pygame.mixer.Sound(os.path.join(sound_path, "ball.wav"))
# Colors
WHITE = (255, 255, 255, 255)
GREY = (127, 127, 127, 255)
BLACK = (0, 0, 0, 255)
FUCHSIA = (255, 0, 255, 255)
RED = (255, 0, 0, 255)
ORANGE = (255, 127, 0, 255)
JELLOW = (255, 255, 0, 255)
GREEN = (0, 255, 0, 255)
AQUA = (0, 255, 255, 255)
BLUE = (0, 0, 255, 255)
PURPLE = (255, 0, 255, 255)
DARK_RED = (127, 0, 0, 255)
DARK_GREEN = (0, 127, 0, 255)
DARK_BLUE = (0, 0, 127, 255)
LIGHT_RED = (255, 127, 127, 255)
LIGHT_GREEN = (127, 255, 127, 255)
LIGHT_BLUE = (127, 127, 255, 255)
# Block settings
blockwidth = WIDTH # This is temporarily and is gonna be overwritten
blockspace = 0 # This is temporarily and is gonna be overwritten
blockheight = 0 # This is temporarily and is gonna be overwritten
total_layers = 1 # This is temporarily and is gonna be overwritten
TOP_MARGIN = HEIGHT/6
BOTTOM_MARGIN = HEIGHT/2
# Paddle settings
PADDLE_WIDTH = 200
# Ball settings
BALL_SPEED = 5
# Scene settings
DIFFS = {1: "Easy", 2: "Normal", 3: "Hard"}
# Player settings
high_score = 0