-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframework.py
More file actions
68 lines (50 loc) · 2.66 KB
/
framework.py
File metadata and controls
68 lines (50 loc) · 2.66 KB
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
import signal
import sys
import x11
from log import log
class game_framework:
def __init__(self):
signal.signal(signal.SIGINT, self.stop_game) #hook Ctrl+C to a more elgant closing function
self.x_win = x11.window(); #private instance of the window class
def stop_game(self, sig=0, frame=0) -> None:
log.printr("game_framework.stop_game(): starting program stop")
self.x_win.elegant_exit();
log.printr("game_framework.stop_game(): exited window.elegant_exit()")
log.printr("game_framework.stop_game(): calling sys.exit()")
sys.exit();
def spawn_window(self, width:int=250, height:int=250, resizable:bool=False, title:str="", color:int=[255,255,255], draw_stepping:bool=False) -> None:
self.x_win.create_win(width,height,resizable,title,color,draw_stepping);
def step_window(self):
self.x_win.step_win();
def is_drawing(self):
return self.x_win.is_drawing_frame;
def get_window_resolution(self) -> tuple:
return self.x_win.get_window_resolution();
def get_window_fps(self) -> float:
return self.x_win.get_window_fps();
def get_mouse(self) -> tuple:
return self.x_win.get_pointer()
def get_font_names(self) -> list:
return self.x_win.get_font_list();
def is_key_down(self, key:str) -> bool:
return self.x_win.is_x11_key_down(ord(key));
def get_arrow_keys(self):
return self.x_win.get_x11_arrow_keys_down();
def create_line(self, x1:int, y1:int,
x2:int, y2:int, color:int=[0,0,0],
width:int=2, style:str="solid"):
return self.x_win.create_x11_line_with_color(x1,y1,x2,y2,color,width,style);
def create_rectangle(self, x:int, y:int,
width:int, height:int, color:int=[0,0,0], filled:bool=True, edge_width:int=2):
return self.x_win.create_x11_rectangle_with_color(x,y,width,height,color,filled,edge_width);
def create_text(self, x:int, y:int,
text:str, color:int=[0,0,0], font=None):
return self.x_win.create_x11_text_with_color(x,y,text,color,font);
def create_font(self, name:str=""):
return self.x_win.create_x11_font(name);
def create_circle(self, x:int, y:int,
width:int, height:int, color:int=[0,0,0],
filled:bool=True):
return self.x_win.create_x11_circle_with_color(x,y,width,height,color,filled)
def create_point(self, x:int, y:int, color:int=[0,0,0]):
return self.x_win.create_x11_point_with_color(x,y,color);