-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.py
More file actions
120 lines (95 loc) · 2.52 KB
/
App.py
File metadata and controls
120 lines (95 loc) · 2.52 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
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
'''
==============================================================================
Primary application class
(C++ version)
3/11/2014
SDLTutorials.com
Tim Jones
(Python3 version)
22/03/2016
www.inf.ufsm.br/~rtrindade
Rafael Gauna Trindade
==============================================================================
'''
import pygame, os
from TextureBank import TextureBank
from Log import Log
os.environ['SDL_VIDEO_CENTERED'] = '1'
class App:
Running = True
WindowWidth = 1024
WindowHeight = 768;
def OnEvent(self, Event):
'''Capture Pygame Events
App.onEvent(event) -> None'''
pass
def Init(self):
'''Initialize our Pygame game / app
App.Init() -> bool'''
try:
pygame.init()
except Exception as e:
Log("Unable to Init Pygame:",e)
return False
try:
self.Window = pygame.display.set_mode((self.WindowWidth, self.WindowHeight))
pygame.display.set_caption("My Pygame game")
except Exception as e:
Log("Unable to create Pygame Window:",e)
return False
# Adaptation for SDL_SetRenderDrawColor
self.DisplayDrawColor = (255,255,255)
self.textureBank = TextureBank()
if not self.textureBank.Init():
Log("Unable to init TextureBank")
return False
return True
def Loop(self):
'''Logic Loop
App.Loop() -> None'''
pass
def Render(self):
'''Render loop (draw)
App.Render() -> None'''
self.Window.fill(self.DisplayDrawColor)
try:
# Check if your texture ID exists!
self.textureBank.Get("Test").Render(0,0)
except Exception as e:
Log("Error to render Texture:",e)
pygame.display.flip()
def Cleanup(self):
'''Free up resources
App.Cleanup -> None'''
self.textureBank.Cleanup()
pygame.quit()
def Execute(self):
'''Main loop of the game. Call Init, seek events, call for modules to
threat the events, loop and renderization. Delay the game for relative
FPS.
App.Execute() -> bool'''
if not self.Init():
return False
while(self.Running):
for event in pygame.event.get():
self.OnEvent(event)
if event.type == pygame.QUIT:
self.Running = False
self.Loop()
self.Render()
# Breath
pygame.time.Clock().tick(60)
self.Cleanup()
return True
def GetInstance(self):
'''Return Instance of App Object
App.GetInstance() -> App'''
return self
def GetWindowsWidth(self):
'''Return Windows Width
App.GetWindowsWidth() -> int'''
return self.GetWindowsWidth
def GetWindowsHeight(self):
'''Return Windows Height
App.GetWindowsHeight() -> int'''
return self.GetWindowsHeight