Pygame setup and fps label
This commit is contained in:
Vendored
+22
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"workbench.colorCustomizations": {
|
||||||
|
"activityBar.activeBackground": "#65c89b",
|
||||||
|
"activityBar.background": "#65c89b",
|
||||||
|
"activityBar.foreground": "#15202b",
|
||||||
|
"activityBar.inactiveForeground": "#15202b99",
|
||||||
|
"activityBarBadge.background": "#945bc4",
|
||||||
|
"activityBarBadge.foreground": "#e7e7e7",
|
||||||
|
"commandCenter.border": "#15202b99",
|
||||||
|
"sash.hoverBorder": "#65c89b",
|
||||||
|
"statusBar.background": "#42b883",
|
||||||
|
"statusBar.foreground": "#15202b",
|
||||||
|
"statusBarItem.hoverBackground": "#359268",
|
||||||
|
"statusBarItem.remoteBackground": "#42b883",
|
||||||
|
"statusBarItem.remoteForeground": "#15202b",
|
||||||
|
"titleBar.activeBackground": "#42b883",
|
||||||
|
"titleBar.activeForeground": "#15202b",
|
||||||
|
"titleBar.inactiveBackground": "#42b88399",
|
||||||
|
"titleBar.inactiveForeground": "#15202b99"
|
||||||
|
},
|
||||||
|
"peacock.color": "#42b883"
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class Config:
|
||||||
|
FPS=60
|
||||||
|
WINDOW_SIZE=(800,600)
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"defaults": {
|
||||||
|
"colours": {
|
||||||
|
"normal_bg": "#45494e",
|
||||||
|
"hovered_bg": "#35393e",
|
||||||
|
"disabled_bg": "#25292e",
|
||||||
|
"selected_bg": "#193754",
|
||||||
|
"dark_bg": "#15191e",
|
||||||
|
"normal_text": "#c5cbd8",
|
||||||
|
"hovered_text": "#FFFFFF",
|
||||||
|
"selected_text": "#FFFFFF",
|
||||||
|
"disabled_text": "#6d736f",
|
||||||
|
"link_text": "#0000EE",
|
||||||
|
"link_hover": "#2020FF",
|
||||||
|
"link_selected": "#551A8B",
|
||||||
|
"text_shadow": "#777777",
|
||||||
|
"normal_border": "#DDDDDD",
|
||||||
|
"hovered_border": "#B0B0B0",
|
||||||
|
"disabled_border": "#808080",
|
||||||
|
"selected_border": "#8080B0",
|
||||||
|
"active_border": "#8080B0",
|
||||||
|
"filled_bar": "#f4251b",
|
||||||
|
"unfilled_bar": "#CCCCCC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import pygame as pg
|
||||||
|
import pygame_gui
|
||||||
|
from constants import Config
|
||||||
|
|
||||||
|
class Game():
|
||||||
|
def __init__(self, screen, clock, manager):
|
||||||
|
self.screen = screen
|
||||||
|
self.clock = clock
|
||||||
|
self.manager = manager
|
||||||
|
self.fps_label = pygame_gui.elements.UILabel(
|
||||||
|
relative_rect=pg.Rect((10, 10), (120, 40)),
|
||||||
|
text="FPS: 0",
|
||||||
|
manager=self.manager
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.running = True
|
||||||
|
while self.running:
|
||||||
|
self.clock.tick(Config.FPS)
|
||||||
|
self.update()
|
||||||
|
self.draw()
|
||||||
|
return self.running
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
fps = str(int(self.clock.get_fps()))
|
||||||
|
self.fps_label.set_text('fps: ' + fps)
|
||||||
|
|
||||||
|
for event in pg.event.get():
|
||||||
|
if event.type == pg.QUIT:
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
self.manager.process_events(event)
|
||||||
|
|
||||||
|
time_delta = self.clock.tick(Config.FPS)/1000.0
|
||||||
|
self.manager.update(time_delta)
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self.screen.fill(self.manager.get_theme().get_colour('normal_bg'))
|
||||||
|
self.manager.draw_ui(self.screen)
|
||||||
|
pg.display.update()
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import pygame as pg
|
||||||
|
import pygame_gui
|
||||||
|
|
||||||
|
from constants import Config
|
||||||
|
from game.game import Game
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
running = True
|
||||||
|
|
||||||
|
pg.init()
|
||||||
|
# pygame.mixer.init()
|
||||||
|
pg.display.set_caption('Portal')
|
||||||
|
screen = pg.display.set_mode(Config.WINDOW_SIZE)
|
||||||
|
manager = pygame_gui.UIManager(Config.WINDOW_SIZE, theme_path="data/theme/theme.json")
|
||||||
|
|
||||||
|
clock = pg.time.Clock()
|
||||||
|
|
||||||
|
# implement game
|
||||||
|
game = Game(screen, clock, manager)
|
||||||
|
|
||||||
|
while running:
|
||||||
|
|
||||||
|
running = game.run()
|
||||||
|
|
||||||
|
pg.quit()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Binary file not shown.
Reference in New Issue
Block a user