Compare commits
14 Commits
647d230fe0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
1bd3ebe2f6
|
|||
|
bd3a986699
|
|||
| ceca244290 | |||
| 72f1891c87 | |||
| 4dc7d0dda5 | |||
| e5b8316409 | |||
| 45123c39b6 | |||
| e932c88cc3 | |||
| 5a62ca10d0 | |||
| ccf08724ab | |||
| 2deb001322 | |||
| c155e11d87 | |||
| 0a2305f4cc | |||
| 2e59e718e6 |
BIN
assets/gun-blank.webp
Normal file
BIN
assets/gun-blank.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
BIN
assets/gun-fire.webp
Normal file
BIN
assets/gun-fire.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 173 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.0 MiB After Width: | Height: | Size: 259 KiB |
58
game.py
58
game.py
@ -1,10 +1,17 @@
|
|||||||
import logging
|
import logging
|
||||||
import pygame
|
import pygame
|
||||||
from random import randint
|
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,17 +25,16 @@ 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: Add background music
|
|
||||||
# TODO: Add muzzle flash
|
|
||||||
# TODO: Add animations for blank firing and real firing
|
|
||||||
# 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.
|
||||||
# see Brosef for the animation.
|
# see Brosef for the animation.
|
||||||
|
|
||||||
self.turnHandler = gameUtils.RoundTable(1, self.pm)
|
# TODO: Add a hook to see if the current player has become inactive.
|
||||||
|
playerName = random.choice(list(self.pm.keys()))
|
||||||
|
self.currentlyPlaying = self.pm[playerName]
|
||||||
|
|
||||||
#Sounds for the gun :3
|
#Sounds for the gun :3
|
||||||
self.playSound = pygame.mixer.Sound.play
|
self.playSound = pygame.mixer.Sound.play
|
||||||
@ -48,6 +54,8 @@ class Game(gameUtils.Game):
|
|||||||
|
|
||||||
self.gun = self.createAnimObj('gun', './assets/gun-base.png')
|
self.gun = self.createAnimObj('gun', './assets/gun-base.png')
|
||||||
self.gun.addAnimation(gameUtils.AnimationHandler('spin', './assets/gun-spin.webp', 60))
|
self.gun.addAnimation(gameUtils.AnimationHandler('spin', './assets/gun-spin.webp', 60))
|
||||||
|
self.gun.addAnimation(gameUtils.AnimationHandler('blank', './assets/gun-blank.webp', 60))
|
||||||
|
self.gun.addAnimation(gameUtils.AnimationHandler('fire', './assets/gun-fire.webp', 60))
|
||||||
|
|
||||||
self.shockScale = 0 #controls shock level sent to PDO (on a scale of 0 to 1)
|
self.shockScale = 0 #controls shock level sent to PDO (on a scale of 0 to 1)
|
||||||
|
|
||||||
@ -65,10 +73,13 @@ 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
|
||||||
self.musicNumber = randint(1,2)
|
# Bro I'm gonna be honest, there's not much I'd change about that, you're good.
|
||||||
|
# The only thing I can think if just moving `set_volume()` to after both if statements.
|
||||||
|
self.musicNumber = random.randint(1,2)
|
||||||
if self.musicNumber == 1:
|
if self.musicNumber == 1:
|
||||||
pygame.mixer.music.load("./assets/surrounded.ogg")
|
pygame.mixer.music.load("./assets/surrounded.ogg")
|
||||||
self.playMusic(-1)
|
self.playMusic(-1)
|
||||||
@ -78,20 +89,32 @@ class Game(gameUtils.Game):
|
|||||||
self.playMusic(-1)
|
self.playMusic(-1)
|
||||||
pygame.mixer.music.set_volume(0.5)
|
pygame.mixer.music.set_volume(0.5)
|
||||||
|
|
||||||
|
def nextPlayer(self):
|
||||||
|
playerIndex = list(self.pm.keys()).index(self.currentlyPlaying.name)
|
||||||
|
playerIndex += 1
|
||||||
|
if playerIndex >= len(self.pm):
|
||||||
|
playerIndex = 0
|
||||||
|
playerName = list(self.pm.keys())[playerIndex]
|
||||||
|
self.currentlyPlaying = self.pm[playerName]
|
||||||
|
self.popup('Next player', f'Pass shocker to {self.currentlyPlaying.name},\nthen press R-CTRL+ENTER to continue.')
|
||||||
|
|
||||||
def fire(self):#LETS GO GAMBLING
|
def fire(self):#LETS GO GAMBLING
|
||||||
if randint(1,6) == 6:
|
if random.randint(1,6) == 6:
|
||||||
self.playSound(self.gunShot)
|
self.playSound(self.gunShot)
|
||||||
self.turnHandler.playing[0].punish(self.shockScale)
|
self.gun.playAnim('fire')
|
||||||
print(f'{self.turnHandler.playing[0].name} is fucking dead.')
|
expansionIDs = self.em.lookupPlayer(self.currentlyPlaying.name)
|
||||||
self.turnHandler.next()
|
shocker = self.em[expansionIDs[0]]
|
||||||
print(f'{self.turnHandler.playing[0].name} is up')
|
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.')
|
||||||
return 0.04
|
return 0.04
|
||||||
#remember to add shock
|
#remember to add shock
|
||||||
else:
|
else:
|
||||||
self.playSound(self.gunBlank)
|
self.playSound(self.gunBlank)
|
||||||
self.turnHandler.next()
|
self.gun.playAnim('blank')
|
||||||
print(f'{self.turnHandler.playing[0].name} is up')
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def onEvent(self, event):
|
def onEvent(self, event):
|
||||||
@ -116,10 +139,12 @@ class Game(gameUtils.Game):
|
|||||||
self.playSound(self.gunSpin)
|
self.playSound(self.gunSpin)
|
||||||
elif event.type == gameUtils.AnimFinish:
|
elif event.type == gameUtils.AnimFinish:
|
||||||
if event.objectID == self.gun.objectID and event.animationID == 'spin':
|
if event.objectID == self.gun.objectID and event.animationID == 'spin':
|
||||||
self.timeout("FireDelay",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:
|
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
|
||||||
|
|
||||||
@ -132,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):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user