Added font and default pygame setup.
This commit is contained in:
parent
6f7fe26232
commit
7d12c1703b
4 changed files with 115 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -160,3 +160,4 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
/settings.json
|
||||||
|
|
18
Flat-it License.txt
Normal file
18
Flat-it License.txt
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
All fonts copyright Flat-it(http://flat-it.com/)
|
||||||
|
|
||||||
|
This is a freeware typeface. This means that you can use it on your commercial or non-commercial works for free.
|
||||||
|
|
||||||
|
But here is a list of things you could do, Only if you want to:
|
||||||
|
|
||||||
|
* Mail me about your works
|
||||||
|
* Link http://flat-it.com/
|
||||||
|
* Send me a sample of the work you did using my typeface
|
||||||
|
* Mail me some print material you did using my typeface
|
||||||
|
* Credit "Flat-it"on your work
|
||||||
|
* Smile
|
||||||
|
|
||||||
|
to contact info@flat-it.com in JAPAN
|
||||||
|
|
||||||
|
|
||||||
|
Ryoichi Tsunekawa
|
||||||
|
Flat-it
|
BIN
PUSAB.otf
Normal file
BIN
PUSAB.otf
Normal file
Binary file not shown.
96
gd_pygame.py
Normal file
96
gd_pygame.py
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
from pygame._sdl2 import Window
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from wobbl_tools.data_file import load_dataclass_json, save_dataclass_json
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Settings:
|
||||||
|
fps: int = 60
|
||||||
|
window_size: tuple = (1000, 600)
|
||||||
|
|
||||||
|
|
||||||
|
class GDPygame:
|
||||||
|
def __init__(self):
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
self.screen = pygame.display.set_mode((1000, 600), pygame.RESIZABLE)
|
||||||
|
pygame.display.set_caption("Game")
|
||||||
|
self.window = Window.from_display_module()
|
||||||
|
|
||||||
|
self.loading_surface = self.generate_loading_surface()
|
||||||
|
self.screen.blit(self.loading_surface, (0, 0))
|
||||||
|
pygame.display.update()
|
||||||
|
|
||||||
|
self.settings = load_dataclass_json(Settings, "settings.json")
|
||||||
|
setattr(self.settings, "save", lambda: save_dataclass_json(self.settings, "settings.json"))
|
||||||
|
|
||||||
|
self.fps = self.settings.fps
|
||||||
|
|
||||||
|
# colors
|
||||||
|
self.gray = (20, 20, 20)
|
||||||
|
|
||||||
|
# pygame objects
|
||||||
|
self.clock = pygame.time.Clock()
|
||||||
|
self.mouse = pygame.mouse
|
||||||
|
self.pusab = pygame.font.Font("PUSAB.otf")
|
||||||
|
|
||||||
|
# loading finished
|
||||||
|
self.window.size = self.settings.window_size
|
||||||
|
|
||||||
|
self.running = True
|
||||||
|
|
||||||
|
def generate_loading_surface(self):
|
||||||
|
default_font = pygame.font.Font("PUSAB.otf", 32)
|
||||||
|
loading_text = default_font.render("Loading...", True, (240, 240, 240))
|
||||||
|
|
||||||
|
w, h = self.screen.get_size()
|
||||||
|
|
||||||
|
loading_surface = pygame.Surface((w, h), flags=pygame.SRCALPHA)
|
||||||
|
|
||||||
|
loading_surface.fill((40, 40, 40))
|
||||||
|
loading_surface.blit(loading_text, (w // 2 - loading_text.get_width() // 2, h // 2 - loading_text.get_height() // 2))
|
||||||
|
|
||||||
|
return loading_surface
|
||||||
|
|
||||||
|
def loop(self):
|
||||||
|
self.screen.fill(self.gray)
|
||||||
|
|
||||||
|
self.get_events()
|
||||||
|
if not self.running:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.loading_surface.get_alpha() > 0:
|
||||||
|
self.screen.blit(self.loading_surface, (0, 0))
|
||||||
|
self.loading_surface.set_alpha(self.loading_surface.get_alpha() - 4)
|
||||||
|
|
||||||
|
pygame.display.update()
|
||||||
|
self.clock.tick(self.fps)
|
||||||
|
|
||||||
|
def get_events(self):
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
self.exit()
|
||||||
|
return
|
||||||
|
|
||||||
|
elif event.type == pygame.VIDEORESIZE:
|
||||||
|
self.window_update(event.size)
|
||||||
|
|
||||||
|
def exit(self):
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
self.settings.save()
|
||||||
|
|
||||||
|
print("Bye!")
|
||||||
|
|
||||||
|
def window_update(self, size):
|
||||||
|
self.settings.window_size = size
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
geometry_dash = GDPygame()
|
||||||
|
|
||||||
|
while geometry_dash.running:
|
||||||
|
geometry_dash.loop()
|
Loading…
Reference in a new issue