138 lines
5.9 KiB
Python
138 lines
5.9 KiB
Python
import logging
|
|
import pygame
|
|
from random import randint
|
|
import gameUtils
|
|
|
|
#Oh god here we go. I'm gonna screw up this entire thing
|
|
|
|
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)
|
|
|
|
# TODO: Utilise self.pm (the player manager)
|
|
# TODO: Add animations for blank firing and real firing
|
|
# TODO: Utilise the following new sounds:
|
|
# gun-load: Should be played at the beginning of the game,
|
|
# and should have an animation accompanying it.
|
|
# see Brosef for the animation.
|
|
|
|
self.turnHandler = gameUtils.RoundTable(1, self.pm)
|
|
|
|
#Sounds for the gun :3
|
|
self.playSound = pygame.mixer.Sound.play
|
|
self.gunBlank = pygame.mixer.Sound("./assets/gun-blank.mp3")
|
|
self.gunShot = pygame.mixer.Sound("./assets/gun-shot.mp3")
|
|
self.gunSpin = pygame.mixer.Sound("./assets/gun-spin.mp3")
|
|
self.gunLoad = pygame.mixer.Sound("./assets/gun-load.mp3")
|
|
self.gunCyclinderStop = pygame.mixer.Sound("./assets/gun-cylinder-stop.mp3")
|
|
|
|
#Background Music commands
|
|
self.unloadMusic = pygame.mixer.music.unload
|
|
self.stopMusic = pygame.mixer.music.stop
|
|
self.playMusic = pygame.mixer.music.play
|
|
|
|
#self.gun = pygame.load_animation('./assets/gun-spin.webp')
|
|
self.gunFlash = pygame.image.load("./assets/muzzleflash.png")
|
|
|
|
self.gun = self.createAnimObj('gun', './assets/gun-base.png')
|
|
self.gun.addAnimation(gameUtils.AnimationHandler('spin', './assets/gun-spin.webp', 60))
|
|
|
|
self.shockScale = 0 #controls shock level sent to PDO (on a scale of 0 to 1)
|
|
|
|
#render variables
|
|
self.gunw=self.gun.size[0] #calculates width of gun anim
|
|
self.gunh=self.gun.size[1] #calculates height of gun anim
|
|
#NOTE: Brosef, istg you better not make the gun webm
|
|
# change sizes mid file, or so help me
|
|
#
|
|
# :3
|
|
# - Brosef
|
|
|
|
self.screenMidx = self.size[0]/2 #calculates horizontal midpoint of screen
|
|
self.screenMidy = self.size[1]/2 #calculates verticle midpoint of 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
|
|
|
|
|
|
#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
|
|
# 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 = randint(1,2)
|
|
if self.musicNumber == 1:
|
|
pygame.mixer.music.load("./assets/surrounded.ogg")
|
|
self.playMusic(-1)
|
|
pygame.mixer.music.set_volume(0.5)
|
|
if self.musicNumber == 2:
|
|
pygame.mixer.music.load("./assets/twiceoritsluck.ogg")
|
|
self.playMusic(-1)
|
|
pygame.mixer.music.set_volume(0.5)
|
|
|
|
|
|
def fire(self):#LETS GO GAMBLING
|
|
if randint(1,6) == 6:
|
|
self.playSound(self.gunShot)
|
|
self.turnHandler.playing[0].punish(self.shockScale)
|
|
print(f'{self.turnHandler.playing[0].name} is fucking dead.')
|
|
return 0.04
|
|
#remember to add shock
|
|
else:
|
|
self.playSound(self.gunBlank)
|
|
return 0
|
|
|
|
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.playSound(self.gunBlank)
|
|
elif event.key == pygame.K_2:
|
|
self.playSound(self.gunShot)
|
|
elif event.key == pygame.K_3:
|
|
self.playSound(self.gunSpin)
|
|
elif event.key == pygame.K_SPACE and not self.awaitingTimeout("FireDelay"):
|
|
self.gun.playAnim('spin')
|
|
elif event.type == gameUtils.AnimStart:
|
|
if event.objectID == self.gun.objectID and event.animationID == 'spin':
|
|
self.playSound(self.gunSpin)
|
|
elif event.type == gameUtils.AnimFinish:
|
|
if event.objectID == self.gun.objectID and event.animationID == 'spin':
|
|
self.timeout("FireDelay",randint(750,2000)/1000)
|
|
self.playSound(self.gunCyclinderStop)
|
|
|
|
elif event.type == gameUtils.Timeout and event.timeoutID == 'FireDelay':
|
|
self.shockScale += self.fire() #check if the user gets shot
|
|
self.shockScale = min(self.shockScale, 1) #keeps shockScale in bounds
|
|
self.turnHandler.next()
|
|
self.popup('Next player', f'Pass shocker to {self.turnHandler.playing[0].name},\nthen press R-CTRL+ENTER to continue.')
|
|
|
|
def update(self):
|
|
"""
|
|
Ran once per frame, put your drawing code and any
|
|
game logic that should be ran once per frame in here.
|
|
"""
|
|
|
|
#screen code
|
|
self.surf.fill("black")
|
|
self.surf.blit(gameUtils.centre(pygame.transform.scale_by(self.gun.getFrame(), self.gunScale), self.size))
|
|
|
|
def close(self):
|
|
"""
|
|
Ran when the game closes
|
|
"""
|
|
pass |