-
Notifications
You must be signed in to change notification settings - Fork 0
/
stgs.py
118 lines (95 loc) · 3.67 KB
/
stgs.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
118
import os
import pygame
from pygame.constants import SRCALPHA
import colors
import math
#### Establishes file paths ####
PATH = os.getcwd()
ASSETSPATH = os.path.join(PATH, 'assets')
#### File for saving settings in game. Every variable set here is default. Clearing the settings file should load everything as default. ####
saveFile = 'save.p'
#### Either centers the player no matter what (False) or doesn't scroll over the boundary of the level (True and preferred) ####
CAMLIMIT = True
SHOWFPS = True
#### FPS BOIS ####
FPS = 60
#### Volumes ####
musicVolume = 1
fxVolume = 1
#### Returns the asset's path ####
def asset(assetName):
global ASSETSPATH
return os.path.join(ASSETSPATH, assetName)
#### Establishes window size ####
winWidth, winHeight = 1280, 720
#### Anti-Aliasing on text ####
aalias = True
#### Defines what key binding is set for each action ####
keySet = {'start': pygame.K_s, 'pRight': [pygame.K_RIGHT, pygame.K_d], 'pLeft': [pygame.K_LEFT, pygame.K_a], 'pUp': [pygame.K_UP, pygame.K_w], 'fullScreen': pygame.K_f, 'pause': pygame.K_p}
#### Changes movement from flying to platforming ####
platformer = False
def checkKey(move):
returnVal = False
keys = pygame.key.get_pressed()
try:
for k in move:
if keys[k]:
returnVal = True
except TypeError:
if keys[move]:
returnVal = True
return returnVal
#### Method works well however you have to set the black color (0,0,0) as the transparent color key in order to make the surface see through
class Spritesheet:
# utility class for loading and parsing spritesheets
def __init__(self, filePath, *args):
if len(args) > 0:
if args[0]:
self.image = filePath
else:
self.image = pygame.image.load(filePath)
else:
self.image = pygame.image.load(filePath)
self.width = self.image.get_width()
self.height = self.image.get_height()
def get_image(self, x, y, width, height):
# grab an image out of a larger spritesheet
img = pygame.Surface((width, height), pygame.SRCALPHA)
img.fill((0, 0, 0, 0))
img.blit(self.image, (0, 0), (x, y, width, height))
img = pygame.transform.scale(img, (width, height))
return img
if not __name__ == '__main__':
fonts = {'1': pygame.font.Font(os.path.join('fonts', 'YuseiMagic-Regular.ttf'), 40),
'2': pygame.font.SysFont('Comic Sans MS', 23),
'3': pygame.font.Font(os.path.join('fonts', 'PottaOne-Regular.ttf'), 32),
'4': pygame.font.Font(os.path.join('fonts', 'PottaOne-Regular.ttf'), 24),
'5': pygame.font.Font(os.path.join('fonts', 'YuseiMagic-Regular.ttf'), 60),
'6': pygame.font.Font(os.path.join('fonts', 'YuseiMagic-Regular.ttf'), 24),
}
def sAsset(assetName):
global ASSETSPATH
return os.path.join(ASSETSPATH, 'sounds', assetName)
DEBUG = True ## Not much use right now. Can be used to control try/except statement flows.
def dist(vec1, vec2):
dist1 = (vec1.x-vec2.x)**2
dist2 = (vec1.y-vec2.y)**2
return math.sqrt(dist1+dist2)
import pickle
def loadSave(file):
try:
with open(file, 'rb') as f:
data = pickle.load(f)
for k, v in data.items():
globals()[k] = v
except:
print("No Save File")
def saveData(file, game):
saveDict = { # Each value must correspond to a global variable in this file
'musicVolume': game.mixer.musicVolume,
'fxVolume': game.mixer.fxVolume,
'aalias': game.antialiasing,
'SHOWFPS': game.showFps,
}
with open(file, 'wb') as f:
pickle.dump(saveDict, f)