Compare commits
39 Commits
cc5f12ce63
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
1bd3ebe2f6
|
|||
|
bd3a986699
|
|||
| ceca244290 | |||
| 72f1891c87 | |||
| 4dc7d0dda5 | |||
| e5b8316409 | |||
| 45123c39b6 | |||
| e932c88cc3 | |||
| 5a62ca10d0 | |||
| ccf08724ab | |||
| 2deb001322 | |||
| c155e11d87 | |||
| 0a2305f4cc | |||
| 2e59e718e6 | |||
| 647d230fe0 | |||
| f258cf8982 | |||
| 39045c3882 | |||
| a6a64cdf69 | |||
| 7b0338c092 | |||
| 7628c59b36 | |||
| c41f863205 | |||
| d0284cc578 | |||
| 26b0363764 | |||
| e2ed74b92a | |||
| 6023b9a2b5 | |||
| 655edc25ee | |||
| 5be3d93e52 | |||
| 90388fc661 | |||
| c0727b2f02 | |||
| decb36295d | |||
| 22c6903783 | |||
| d38eadd6c3 | |||
| 894ac59038 | |||
| 4abb2353e1 | |||
| 09ae4c8d7e | |||
| 108f99af5b | |||
| e78b07dcb9 | |||
| 5fa732b4cf | |||
| 8986a46ce3 |
127
__init__.py
127
__init__.py
@ -1,127 +0,0 @@
|
||||
import logging
|
||||
import pygame
|
||||
from random import randint
|
||||
#import NoPELib
|
||||
#import PDOLib
|
||||
|
||||
#Oh god here we go. I'm gonna screw up this entire thing
|
||||
|
||||
class Game:
|
||||
def __init__(self, surface, size):
|
||||
"""
|
||||
Ran when the game starts.
|
||||
|
||||
Args:
|
||||
surface (pygame.Surface): The surface you draw to.
|
||||
size (list[int, int]): The size of the surface.
|
||||
"""
|
||||
|
||||
pygame.init()
|
||||
self.surface = surface
|
||||
self.size = size
|
||||
self.clock = pygame.time.Clock()
|
||||
|
||||
# TODO: Add a random delay between the spin and fire
|
||||
|
||||
# TODO: Utiles 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.
|
||||
# gun-cylinder-stop: Plays directly after the load
|
||||
# animation is complete.
|
||||
# gun-spin/blank/shot are all used in their original ways.
|
||||
|
||||
#Sounds for the gun :3
|
||||
self.playSound = pygame.mixer.Sound.play
|
||||
self.gunBlank = pygame.mixer.Sound("sfx/gun-blank.mp3")
|
||||
self.gunShot = pygame.mixer.Sound("sfx/gun-shot.mp3")
|
||||
self.gunSpin = pygame.mixer.Sound("sfx/gun-spin.mp3")
|
||||
self.gunLoad = pygame.mixer.Sound("sfx/gun-load.mp3")
|
||||
self.gunCyclinder = pygame.mixer.Sound("sfx/gun-cylinder-stop.mp3")
|
||||
|
||||
self.gun = pygame.image.load_animation("gun.webp")
|
||||
self.gunFlash = pygame.image.load("images/muzzleflash.png")
|
||||
|
||||
self.shockScale = 0 #controls shock level sent to PDO (on a scale of 0 to 1)
|
||||
#gun variables
|
||||
self.startSpin = False
|
||||
self.spinning = False
|
||||
self.spinInc = 0
|
||||
|
||||
#render variables
|
||||
self.screenMid = self.size[0]/2
|
||||
self.gunScale = self.size[1]/1080
|
||||
self.gunMid = self.screenMid-(self.gun[0][0].size[0]*self.gunScale/2)
|
||||
# TODO
|
||||
# Make the gun scale based on width of screen as well as height
|
||||
|
||||
def fire(self):#LETS GO GAMBLING
|
||||
if randint(1,6) == 6:
|
||||
self.playSound(self.gunShot)
|
||||
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:
|
||||
self.startSpin = True
|
||||
|
||||
def draw(self):
|
||||
"""
|
||||
Ran once per frame, put your drawing code in here
|
||||
"""
|
||||
|
||||
#gun code WOO
|
||||
if self.startSpin == True or self.spinning == True:#check if space was pressed or if the gun is already spinning
|
||||
self.spinning = True #keep the gun spinning
|
||||
if self.spinInc == 0:
|
||||
self.playSound(self.gunSpin)
|
||||
self.spinInc += 1 #next gun frame
|
||||
if self.spinInc == len(self.gun): #if we've reached the end
|
||||
self.spinInc = 0 #reset frame count
|
||||
self.spinning = False #stop spinning
|
||||
self.startSpin = False #what did i say bitch? stop spinning
|
||||
self.shockScale += self.fire() #check if the user gets shot
|
||||
self.shockScale = min(self.shockScale, 1) #keeps shockScale in bounds
|
||||
|
||||
#screen code
|
||||
self.surface.fill("black")
|
||||
self.surface.blit(pygame.transform.scale_by(self.gun[self.spinInc][0],self.gunScale),(self.gunMid,0))#draw the gun
|
||||
#screen.blit(pygame.transform.scale_by(MainSurface,1),(0,yOffset))#renders the main surface to the screen, while also scaling it for the required display resolution
|
||||
|
||||
# TODO:
|
||||
# I've removed the whole "main surface" thing for now,
|
||||
# because I'm not sure how we're going to deal with it
|
||||
# from now on right now. I'll fix this later when it's
|
||||
# a bit clearer on how NoPE-Lib will draw the players
|
||||
# and how the base game should draw that.
|
||||
# - Brosef
|
||||
|
||||
# TODO:
|
||||
# Actually scale the gun with self.size, and centre it
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
self.clock.tick(60)
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Ran when the game closes
|
||||
"""
|
||||
pass
|
||||
58
__main__.py
58
__main__.py
@ -1,58 +0,0 @@
|
||||
# Import the game code
|
||||
import __init__
|
||||
|
||||
import argparse
|
||||
import tomllib
|
||||
import pathlib
|
||||
import pygame
|
||||
import os
|
||||
|
||||
# Store the current working directory
|
||||
# This is used to revert the cd change
|
||||
originalCWD = os.getcwd()
|
||||
|
||||
# Get the path of the game
|
||||
basePath = pathlib.Path(__file__).parent.resolve()
|
||||
|
||||
# Set the current working directory
|
||||
# to the base path of the game
|
||||
os.chdir(basePath)
|
||||
|
||||
# Load the game.toml data
|
||||
with open('game.toml', 'r') as f:
|
||||
gameData = tomllib.loads(f.read())
|
||||
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(prog=gameData['name'])
|
||||
parser.add_argument('-sw', '--width', type=int, default=1280)
|
||||
parser.add_argument('-sh', '--height', type=int, default=720)
|
||||
parser.add_argument('-f', '--fullscreen', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Initialise screen
|
||||
flags = 0
|
||||
if args.fullscreen: flags |= pygame.FULLSCREEN
|
||||
screen = pygame.display.set_mode((args.width, args.height), flags)
|
||||
pygame.display.set_caption(gameData['name'])
|
||||
|
||||
# Initialise game
|
||||
game = __init__.Game(screen, screen.size)
|
||||
|
||||
# Set to False when the game should exit
|
||||
run = True
|
||||
|
||||
while run:
|
||||
# Event loop
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
game.onEvent(event)
|
||||
|
||||
# Draw loop
|
||||
game.draw()
|
||||
|
||||
# Clean up
|
||||
os.chdir(originalCWD)
|
||||
game.close()
|
||||
pygame.quit()
|
||||
BIN
assets/gun-base.png
Normal file
BIN
assets/gun-base.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 276 KiB |
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 |
BIN
assets/gun-spin.webp
Normal file
BIN
assets/gun-spin.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 259 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
BIN
assets/surrounded.ogg
Normal file
BIN
assets/surrounded.ogg
Normal file
Binary file not shown.
BIN
assets/twiceoritsluck.ogg
Normal file
BIN
assets/twiceoritsluck.ogg
Normal file
Binary file not shown.
166
game.py
Normal file
166
game.py
Normal file
@ -0,0 +1,166 @@
|
||||
import logging
|
||||
import pygame
|
||||
import random
|
||||
import gameUtils
|
||||
import NoPELib
|
||||
|
||||
#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):
|
||||
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)
|
||||
self.em = NoPELib.ExpansionsManager(self.pm, includeExpansions=['ShockColar1'])
|
||||
|
||||
# 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.
|
||||
|
||||
# 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
|
||||
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.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)
|
||||
|
||||
#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
|
||||
|
||||
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.
|
||||
#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 = random.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 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
|
||||
if random.randint(1,6) == 6:
|
||||
self.playSound(self.gunShot)
|
||||
self.gun.playAnim('fire')
|
||||
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.')
|
||||
return 0.04
|
||||
#remember to add shock
|
||||
else:
|
||||
self.playSound(self.gunBlank)
|
||||
self.gun.playAnim('blank')
|
||||
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",random.randint(750,2000)/1000)
|
||||
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':
|
||||
self.shockScale += self.fire() #check if the user gets shot
|
||||
self.shockScale = min(self.shockScale, 1) #keeps shockScale in bounds
|
||||
|
||||
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))
|
||||
self.surf.blit(self.font.render(f'Current player: {self.currentlyPlaying.name}', True, (255, 255, 255)), (0, 0))
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Ran when the game closes
|
||||
"""
|
||||
pass
|
||||
@ -1,3 +1,4 @@
|
||||
../NoPELib/
|
||||
../PDOLib/
|
||||
../GameUtils/
|
||||
pygame-ce
|
||||
Reference in New Issue
Block a user