-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframepie.py
121 lines (97 loc) · 3.72 KB
/
framepie.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
119
120
121
import pygame
import functools
import os
# Check if being run internally
if __name__ == '__main__':
raise ValueError("Do not run this directly please.")
# Initialize Pygame
pygame.init()
# Set initial values
screen = 0
clock = pygame.time.Clock()
background_color = (0, 0, 0)
dt = 0
# Values you can change easily
FPS = 60
# Set up the screen
screen = pygame.display.set_mode((800, 400))
pygame.display.set_caption('FramePie')
# Get the window size
w, h = pygame.display.get_surface().get_size()
# Set the window icon
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)
# Set the window resolution
def set_window_resolution(res=(800, 600)):
global screen, w, h
w, h = res[0], res[1]
screen = pygame.display.set_mode((w, h))
# Update the screen
def update(clear_screen=True):
global dt
pygame.display.flip()
if clear_screen:
pygame.draw.rect(screen, background_color, (0, 0, 20000, 20000))
dt = clock.tick_busy_loop(FPS) / 1000.0
for event in pygame.event.get():
if event.type == pygame.QUIT:
raise SystemExit("Application terminated by user")
# Set the window background color
def set_window_background_color(color=(0, 0, 0)):
global background_color
if len(color) != 3:
raise ValueError('Color (value 3) in "set_window_background_color" must have 3 values exactly')
background_color = color
# Set the window name
def set_window_name(name="FramePie"):
if not isinstance(name, str):
raise TypeError('name in "set_window_name (value 1)" is not a string')
pygame.display.set_caption(name)
# Draw a polygon
def draw_polygon(poly=[(0, 0), (10, 20), (20, 0)], colors=(100, 0, 0), offsets=(0, 0), outline_width=0):
pygame.draw.polygon(screen, colors, poly+offsets, outline_width)
# Draw a rectangle
def draw_rect(size=(100, 100), position=(0, 0), color=(100, 0, 0), type=0):
# Check for errors
if len(color) != 3:
raise ValueError('Color (value 3) in "draw_rect" must have 3 values exactly')
elif len(position) != 2:
raise ValueError('Position (value 2) in "draw_rect" must have 2 values exactly')
elif len(size) != 2:
raise ValueError('Size (value 1) in "draw_rect" must have 2 values exactly')
pygame.draw.rect(screen, color, pygame.Rect(position[0], position[1], size[0], size[1]), type)
# Get a draw image
@functools.lru_cache(maxsize=512)
def transform_image(image, transform=None, flip=(False, False)):
if transform:
image = pygame.transform.scale(image, transform)
return pygame.transform.flip(image, *flip)
# Draw a surface
def draw_surface(surface, position=(0, 0), main_surface=screen):
pygame.Surface.blit(main_surface, surface, position)
# Draw an image
def draw_image(image, position=(0,0),transform=None,flip=(False,False),surface=screen):
image = transform_image(image, transform, flip)
surface.blit(image, position)
# Get some input
def get_input(input):
keys = pygame.key.get_pressed()
if keys[input]:
return True
def to_delta(number):
return number * dt
def load_image(path_to_file='icon.png', transparent=True):
if not os.path.exists(path_to_file):
raise FileNotFoundError('The requested file location "'+path_to_file+'" was not found in active directory "'+os.getcwd()+'"')
surface = pygame.image.load(path_to_file)
if transparent == True:
return surface
else:
return surface.convert_alpha()
def get_mouse_position():
return pygame.mouse.get_pos()
def get_index(Array:list,index:int):
if index >= Array.__len__() or index <=-1:
return None
else:
return Array[index]