start.py#

Start.py:#

This file contains the main menu and game logic for the Walking Piano Game. The main menu allows the user to select between different game modes, such as Challenge Mode, Practice Mode, FreePlay, Settings, JukeBox, and Exit. The user can navigate through the menu using the mouse and select different options.

Classes:

ClickableLabel WalkingPianoGame

Functions:

csv_to_song_database

Authors: Devin Martin and Wesley Jake Anding

class start.ClickableLabel(text, song_id, font_size, x, y, anchor_x, anchor_y, batch, color=(255, 255, 255, 255), highlightable=True)#

Bases: object

A class representing a clickable label in the game UI.

Attributes#

labelpyglet.text.Label

The Pyglet label object.

song_idint

The ID of the song associated with the label.

original_colortuple

The original color of the label.

highlight_colortuple

The color of the label when highlighted.

highlightablebool

Whether the label is highlightable or not.

is_clicked(x, y)#

Checks if the label was clicked based on the provided coordinates.

Parameters#

xint

The x-coordinate of the click.

yint

The y-coordinate of the click.

Returns#

bool

True if the label was clicked, False otherwise.

update_highlight(x, y)#

Updates the label’s highlight state based on the provided coordinates.

Parameters#

xint

The x-coordinate of the mouse.

yint

The y-coordinate of the mouse.

class start.WalkingPianoGame(*args, **kwargs)#

Bases: BaseWindow

A class representing the Walking Piano Game This is sets up the menu and many parameters that can be changed within the settings before playing the piano game.

Attributes#

menu_batchpyglet.graphics.Batch

Batch for the main menu.

song_select_batchpyglet.graphics.Batch

Batch for the song selection menu.

song_select_batch_jukeboxpyglet.graphics.Batch

Batch for the jukebox song selection menu.

settings_batchpyglet.graphics.Batch

Batch for the settings menu.

player_mode_batchpyglet.graphics.Batch

Batch for the player mode selection menu.

game_modeslist

List of game modes.

selected_game_modestr

The currently selected game mode.

game_statestr

The current state of the game.

player_countint

The number of players.

autoplayint

Whether autoplay is enabled.

controller_sizestr

The size of the controller.

menu_options_labelslist

List of labels for the main menu options.

song_options_labelslist

List of labels for the song selection menu.

song_options_labels_jukeboxlist

List of labels for the jukebox song selection menu.

settings_options_labelslist

List of labels for the settings menu options.

player_mode_options_labelslist

List of labels for the player mode selection menu.

gamePianoGameUI

The current game instance.

outportstr

The MIDI output port.

inportstr

The MIDI input port.

filter_songs_based_on_mode_and_players()#

Filters the song database based on the selected game mode and number of players.

Returns#

dict

A dictionary of valid songs based on the selected game mode and number of players.

get_song_id_from_label(label)#

Retrieves the song ID from the given label.

Parameters#

labelClickableLabel

The label from which to retrieve the song ID.

Returns#

int

The ID of the song associated with the label.

handle_next_page_jukebox()#
handle_prev_page_jukebox()#
on_draw()#

Handles the drawing of the game window based on the current game state.

on_mouse_motion(x, y, dx, dy)#

Handles mouse motion events to update label highlights based on the current game state.

Parameters#

xint

The x-coordinate of the mouse.

yint

The y-coordinate of the mouse.

dxint

The change in the x-coordinate of the mouse.

dyint

The change in the y-coordinate of the mouse.

on_mouse_press(x, y, button, modifiers)#

Handles mouse press events based on the current game state.

Parameters#

xint

The x-coordinate of the mouse press.

yint

The y-coordinate of the mouse press.

buttonint

The mouse button pressed.

modifiersint

Any modifier keys pressed.

return_to_menu()#

Returns to the main menu.

setup_difficulty_selection()#

Sets up the difficulty selection labels.

setup_jukebox_song_selection(current_page=0)#

Sets up the jukebox song selection labels with pagination.

Parameters#

current_pageint, optional

The current page of the song selection (default is 0).

setup_menu()#

Sets up the main menu labels.

setup_player_mode_selection()#

Sets up the player mode selection labels.

setup_settings()#

Sets up the settings menu labels.

setup_song_selection()#

Sets up the song selection labels.

start_game(midi_file, game_mode, inport, outport, controller_size='88 key', player_count=1, autoplay=False)#

Starts the game with the selected settings.

Parameters#

midi_filestr

The MIDI file to play.

game_modestr

The selected game mode.

inportstr

The MIDI input port.

outportstr

The MIDI output port.

controller_sizestr, optional

The size of the controller (default is ‘88 key’).

player_countint, optional

The number of players (default is 1).

autoplayint: 0 for none, 1 for half autoplay (left hand automatic), 2 for full autoplay optional

Whether autoplay is enabled (default is False).

start.csv_to_song_database(csv_filename)#

Converts a CSV file into a song database dictionary.

Parameters#

csv_filenamestr

The path to the CSV file.

Returns#

dict

A dictionary representing the song database.