Started work on game
This commit is contained in:
44
game.py
44
game.py
@ -1,8 +1,21 @@
|
|||||||
from PIL import Imgae
|
from PIL import Image
|
||||||
import logging
|
import logging
|
||||||
import pygame
|
import pygame
|
||||||
import gameUtils
|
import gameUtils
|
||||||
import NoPELib
|
import NoPELib
|
||||||
|
import random
|
||||||
|
import json
|
||||||
|
|
||||||
|
def normalDist(difficulty):
|
||||||
|
# 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):
|
class Game(gameUtils.Game):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -18,6 +31,24 @@ class Game(gameUtils.Game):
|
|||||||
# Don't remove this. It does important things. :3
|
# Don't remove this. It does important things. :3
|
||||||
super().__init__(*args, **kwargs)
|
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 = {}
|
||||||
|
|
||||||
|
with open(f'./fonts/fonts.json', 'r') as f:
|
||||||
|
j = json.loads(f.read())
|
||||||
|
|
||||||
|
#for fontData in j:
|
||||||
|
# self.fonts.update()
|
||||||
|
|
||||||
|
def createCaptcha(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def onEvent(self, event):
|
def onEvent(self, event):
|
||||||
"""
|
"""
|
||||||
Ran when an event is fired.
|
Ran when an event is fired.
|
||||||
@ -25,7 +56,14 @@ class Game(gameUtils.Game):
|
|||||||
Args:
|
Args:
|
||||||
event (pygame.Event): The event that was fired.
|
event (pygame.Event): The event that was fired.
|
||||||
"""
|
"""
|
||||||
pass
|
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):
|
def update(self):
|
||||||
"""
|
"""
|
||||||
@ -36,6 +74,8 @@ 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))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Ran when the game closes.
|
Ran when the game closes.
|
||||||
|
|||||||
@ -2,3 +2,4 @@
|
|||||||
../NoPELib/
|
../NoPELib/
|
||||||
../PDOLib/
|
../PDOLib/
|
||||||
pygame-ce
|
pygame-ce
|
||||||
|
Pillow
|
||||||
Reference in New Issue
Block a user