created a basic demonstraction of how text rendering should work, added some positive comments to the json opening code

This commit is contained in:
2025-06-24 17:15:45 +01:00
parent 1a34d7ca4a
commit b61a7114ba
2 changed files with 31 additions and 3 deletions

17
game.py
View File

@ -1,4 +1,4 @@
from PIL import Image from PIL import Image, ImageDraw, ImageFont
import logging import logging
import pygame import pygame
import gameUtils import gameUtils
@ -49,7 +49,7 @@ class Game(gameUtils.Game):
# an object or something, I don't know. Keep in mind you # an object or something, I don't know. Keep in mind you
# have to load all of the font files for use later. # have to load all of the font files for use later.
with open(f'./fonts/fonts.json', 'r') as f: with open(f'./fonts/fonts.json', 'r') as f:
j = json.loads(f.read()) self.fontList = json.loads(f.read())#loads the fonts from the json (Why the fuck was the variable called 'j' before????)
#for fontData in j: #for fontData in j:
# self.fonts.update() # self.fonts.update()
@ -87,7 +87,18 @@ class Game(gameUtils.Game):
# Don't remove this. It does important things. :3 # Don't remove this. It does important things. :3
super().update() super().update()
self.surf.fill((0, 0, 0)) self.Drawsurface = Image.new("RGB",(800,220),(255,255,255)) #creates a surface to draw the fonts on
self.textTest = ImageFont.truetype("./fonts/"+self.fontList[2]["file"],200) #loads the font
self.draw = ImageDraw.Draw(self.Drawsurface) #creates an object to let us draw to the surface
self.draw.text((10,10),"Hello", font=self.textTest, fill=(0,0,0)) #actually draws the text
self.pygameConvert = pygame.image.fromstring(self.Drawsurface.tobytes(), self.Drawsurface.size, self.Drawsurface.mode) #converts the pillow image to a pygame image
#no, there wasn't an easier way I could find to achieve this, stab me
self.surf.fill((0, 0, 0)) #sets the background colour
self.surf.blit(gameUtils.centre(self.pygameConvert,self.size)) #draws the text to center of the screen
#TODO: actually scale the text, however, more work needs to be done on the actual function of the game first
def close(self): def close(self):
""" """

17
launch.json Normal file
View File

@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger",
"type": "debugpy",
"request": "launch",
"python": "../PainJamLauncher/.venv/Scripts/python.exe",
"program": "../PainJamLauncher/__main__.py",
"args": ["captchaGame"],
"console": "integratedTerminal"
}
]
}