This repository has been archived on 2026-02-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
VerifyOrFuckingDie/game.py

108 lines
4.2 KiB
Python

from PIL import Image, ImageDraw, ImageFont
import logging
import pygame
import gameUtils
import NoPELib
import random
import json
def normalDist(difficulty):
"""
This function generates a random number between 0-1
that should be used to get a font with a difficulty
equal to or less than the number returned.
"""
# Create a random number between 0-1
v = random.randint(-1000, 1000) / 1000
# Redistribute the number
v = v**3
# Shift the number based on game difficulty
difficulty = difficulty * 1.5 - 0.25
v += difficulty
# Cap it to be 0-1 again and return
return min(max(v, 0), 1)
class Game(gameUtils.Game):
def __init__(self, *args, **kwargs):
"""
Ran when the game starts.
You have access to the following variables:
self.surf (pygame.Surface): This is the surface you draw onto.
self.pm (NoPELib.PlayerManager): This is where your players are stored.
self.cfg (dict): Everything from the `game.toml` file. You can access it like this: self.details['title']
"""
# Don't remove this. It does important things. :3
super().__init__(*args, **kwargs)
# A value between 0-1 that defines which fonts the game will use
self.gameDifficulty = 0
# The actual text in the captcha, used to check what the user typed
self.currentCaptchaText = ''
# The image of the captcha
self.currentCaptchaImg = ''
self.fonts = {}
# I haven't finished this yet, you might want to create
# an object or something, I don't know. Keep in mind you
# have to load all of the font files for use later.
with open(f'./fonts/fonts.json', 'r') as f:
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:
# self.fonts.update()
def createCaptcha(self):
"""
Use PIL (https://pillow.readthedocs.io/en/stable/handbook/tutorial.html)
to draw the fonts, add noise, random shapes, transforms etc. based on
self.gameDifficulty
"""
pass
def onEvent(self, event):
"""
Ran when an event is fired.
Args:
event (pygame.Event): The event that was fired.
"""
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
self.gameDifficulty -= 0.1
elif event.key == pygame.K_2:
self.gameDifficulty += 0.1
elif event.key == pygame.K_3:
self.createCaptcha()
print(self.gameDifficulty)
def update(self):
"""
Ran once per frame, put your drawing code and any
game logic that should be ran once per frame in here.
"""
# Don't remove this. It does important things. :3
super().update()
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):
"""
Ran when the game closes.
"""
pass