Skip to content

Commit

Permalink
Make podium scale dependent on number of players, add a -n switch t…
Browse files Browse the repository at this point in the history
…o specify player number from command line (#14)

* Make the size of podiums dependent on the number of players

Will close #8
Will close #11

Partially addresses #12 ()

* Allow the number of players to be cnfigured using -n flag

Will close #12
  • Loading branch information
Agent-E11 authored Apr 30, 2024
1 parent ca0c03a commit 73b7763
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
3 changes: 3 additions & 0 deletions jeoparpy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@

#Flash drive
DRIVE = False

# The number of players
PLAYER_NUM = 3
6 changes: 4 additions & 2 deletions jeoparpy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import os
import sys

from .config import FPS_LIMIT, FULLSCREEN, SUBTRACT_ON_INCORRECT, SCREEN_SIZE
from .config import FPS_LIMIT, FULLSCREEN, PLAYER_NUM, SUBTRACT_ON_INCORRECT, SCREEN_SIZE
from .constants import ANIMATIONEND, ANSWER_TIMEOUT, AUDIOEND, SKIP_INTRO_FLAG
from .game import GameData, JeopGameState
from .ui import Controller, do_congrats, do_credits, do_intro, do_scroll
Expand Down Expand Up @@ -161,7 +161,9 @@ def handle_event_key(event, gameState, gameData):
elif gs.state == gs.WAIT_TRIGGER_AUDIO and event.key == K_m:
gs.set(gs.PLAY_CLUE_AUDIO, coords=gs.kwargs['coords'])

elif gs.state == gs.WAIT_BUZZ_IN and event.key in (K_1, K_2, K_3):
# Check if the state is WAIT_BUZZ_IN, and the key is a number coresponding to a player
elif gs.state == gs.WAIT_BUZZ_IN and event.key in range(K_1, K_1 + PLAYER_NUM):
# Get player id from key
p = event.key - K_1
if not gameData.players[p].hasAnswered:
gs.set(gs.BUZZ_IN, playerI=p, amount=gs.kwargs['amount'])
Expand Down
15 changes: 11 additions & 4 deletions jeoparpy/ui/maingame/podiapanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .podium import Podium
from ..resmaps import FONTS, IMAGES

from ...config import PLAYER_NUM

class PodiaPanel(JeopGameSurface):
"""
Expand Down Expand Up @@ -72,11 +73,17 @@ def update(self, gameState, gameData):

def _init_background(self):
img = pygame.image.load(IMAGES['rPanelBG']).convert()

sizeScalar = float(self.size[1]) / img.get_size()[1]

# Change the scalar depending on the number of players
# NOTE: I don't really know why this involves a 3
sizeScalar = sizeScalar * (3 / PLAYER_NUM)

img = pygame.transform.scale(img, self.size)
self.blit(img, (0, 0))

return sizeScalar * .75
return sizeScalar

def _init_podia(self, gameData, scalar):
podia = pygame.sprite.OrderedUpdates()
Expand All @@ -85,15 +92,15 @@ def _init_podia(self, gameData, scalar):
fonts = (('team1', 42), ('team2', 33), ('team3', 40), ('team1', 42), ('team2', 33))
fonts = tuple((FONTS[n], s) for n,s in fonts)

for i in range(5):
for i in range(PLAYER_NUM):
p = Podium(i, img, scalar, gameData.players[i].name,
fonts[i], nameBounds, podia)

return self._position_podia(podia)

def _position_podia(self, podia):
ph = podia.sprites()[0].rect.h - 10
padding = (self.size[1] - 5*ph) / 4
ph = podia.sprites()[0].rect.h
padding = (self.size[1] - PLAYER_NUM*ph) / 4
y = padding

for p in podia:
Expand Down
33 changes: 31 additions & 2 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,40 @@
'--skip-intro' : SKIP_INTRO_FLAG,
'-w' : WINDOWED_FLAG,
'--windowed' : WINDOWED_FLAG,
'--drive' : DRIVE_FLAG,
'--drive' : DRIVE_FLAG,
}

if __name__ == '__main__':
flags = set(optionsMap[o] for o in argv if o in optionsMap)
rawFlags = []

# Loop over args, add all args to rawFlags unless it is -n or the arg after it
i = 0
while i < len(argv):
if argv[i] == '-n':
i += 1
try:
num = int(argv[i])
if num < 3 or num > 5:
print("Please specify a number of players from 3 to 5")
print("Or, omit it and the number of players will default to 3")
exit(1)
except ValueError:
print(f'{argv[i]} is not a valid number')
exit(1)

config.PLAYER_NUM = num

elif argv[i] in ('-h', '--help'):
print('Sorry, the help flag has not been implemented yet')
exit(0)

elif argv[i] in optionsMap:
rawFlags.append(optionsMap[argv[i]])

i += 1

# Get rid of duplicates
flags = set(rawFlags)

# Override config options if args provided
if FULLSCREEN_FLAG in flags:
Expand Down

0 comments on commit 73b7763

Please sign in to comment.