Compare commits

...

5 Commits

4 changed files with 19 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 174 KiB

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 KiB

After

Width:  |  Height:  |  Size: 259 KiB

22
game.py
View File

@ -2,9 +2,16 @@ import logging
import pygame import pygame
import random import random
import gameUtils import gameUtils
import NoPELib
#Oh god here we go. I'm gonna screw up this entire thing #Oh god here we go. I'm gonna screw up this entire thing
def transform(value, minA, maxA, minB, maxB):
"""
Translates `value` from `minA`-`maxA` to `minB`-`maxB`.
"""
return ((value - minA) / (maxA - minA)) * (maxB - minB) + minB
class Game(gameUtils.Game): class Game(gameUtils.Game):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
""" """
@ -18,8 +25,8 @@ 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)
self.em = NoPELib.ExpansionsManager(self.pm, includeExpansions=['ShockColar1'])
# TODO: Utilise self.pm (the player manager)
# TODO: Utilise the following new sounds: # TODO: Utilise the following new sounds:
# gun-load: Should be played at the beginning of the game, # gun-load: Should be played at the beginning of the game,
# and should have an animation accompanying it. # and should have an animation accompanying it.
@ -66,6 +73,7 @@ class Game(gameUtils.Game):
self.gunScale = min(self.size[1]/self.gunh,self.size[0]/self.gunw) #calculates how to scale the gun so that it stays on the screen self.gunScale = min(self.size[1]/self.gunh,self.size[0]/self.gunw) #calculates how to scale the gun so that it stays on the screen
self.font = pygame.font.SysFont('', 64)
#Selects random music to play at the start of the game, might change because I just threw this together. #Selects random music to play at the start of the game, might change because I just threw this together.
#I feel horrible writing this code this feels super unoptimised :c #I feel horrible writing this code this feels super unoptimised :c
@ -94,7 +102,13 @@ class Game(gameUtils.Game):
if random.randint(1,6) == 6: if random.randint(1,6) == 6:
self.playSound(self.gunShot) self.playSound(self.gunShot)
self.gun.playAnim('fire') self.gun.playAnim('fire')
self.currentlyPlaying.punish(self.shockScale) expansionIDs = self.em.lookupPlayer(self.currentlyPlaying.name)
shocker = self.em[expansionIDs[0]]
iMin, iMax = self.currentlyPlaying.expansions['ShockCollar1']['shcokRange']
v = round(transform(self.shockScale, 0, 1, iMin, iMax))
print(f'Shocking {self.currentlyPlaying.name} with intensity {v}')
shocker.step((False, 0.5, v))
print(f'{self.currentlyPlaying.name} is fucking dead.') print(f'{self.currentlyPlaying.name} is fucking dead.')
return 0.04 return 0.04
#remember to add shock #remember to add shock
@ -127,11 +141,12 @@ class Game(gameUtils.Game):
if event.objectID == self.gun.objectID and event.animationID == 'spin': if event.objectID == self.gun.objectID and event.animationID == 'spin':
self.timeout("FireDelay",random.randint(750,2000)/1000) self.timeout("FireDelay",random.randint(750,2000)/1000)
self.playSound(self.gunCyclinderStop) self.playSound(self.gunCyclinderStop)
elif event.objectID == self.gun.objectID and event.animationID in ['blank', 'fire']:
self.nextPlayer()
elif event.type == gameUtils.Timeout and event.timeoutID == 'FireDelay': elif event.type == gameUtils.Timeout and event.timeoutID == 'FireDelay':
self.shockScale += self.fire() #check if the user gets shot self.shockScale += self.fire() #check if the user gets shot
self.shockScale = min(self.shockScale, 1) #keeps shockScale in bounds self.shockScale = min(self.shockScale, 1) #keeps shockScale in bounds
self.nextPlayer()
def update(self): def update(self):
""" """
@ -142,6 +157,7 @@ class Game(gameUtils.Game):
#screen code #screen code
self.surf.fill("black") self.surf.fill("black")
self.surf.blit(gameUtils.centre(pygame.transform.scale_by(self.gun.getFrame(), self.gunScale), self.size)) self.surf.blit(gameUtils.centre(pygame.transform.scale_by(self.gun.getFrame(), self.gunScale), self.size))
self.surf.blit(self.font.render(f'Current player: {self.currentlyPlaying.name}', True, (255, 255, 255)), (0, 0))
def close(self): def close(self):
""" """