Heroes of Congress
Heroes of Congress is a social deduction game where you play as a member of congress. While most players are peacekeepers, some players are out for war. It is the job of the peacekeepers to expose them and remove them from congress.
On this project I worked on UI and gameplay programming, for both the mobile and chromecast display, making use of the networking interface made by one of our other programmers. I also did our audio implementation. Below are some code snippets, starting with the audio implementation.
On this project I worked on UI and gameplay programming, for both the mobile and chromecast display, making use of the networking interface made by one of our other programmers. I also did our audio implementation. Below are some code snippets, starting with the audio implementation.
This image shows the initial setup of the audiomanager. It maintains two dictionaries, one of audiosources and their keys, each of which can play one related audio clip at at a time, and one of background music and their associated names. Background music and audio clips have separate volume settings, and background music loops by default.
After the initial setup, it shows the update function, where fade-in and fade-out is handled. During the update the audiomanager checks every listed audio clip, sees if it should currently be fading in or out, and if so adjusts the volume accordingly.
After the initial setup, it shows the update function, where fade-in and fade-out is handled. During the update the audiomanager checks every listed audio clip, sees if it should currently be fading in or out, and if so adjusts the volume accordingly.
Here we see one region of the audiomanager, the part that plays standard audio clips. When asked to play a clip, the manager will find an idle audiosource, and if none can be found it will add a new one. It will add the new audio source to the dictionary, set its volume and set it to play the given clip. We can also pass in an action to occur on completion of the audio clip, which will execute when the clip is fully done playing. There are two play functions, one for playing a sound file locally, and one for playing a sound file on the chromecast.
This is a smaller snippet, which is more standalone than the rest of the example code shown. At one point during the project we found the need to execute certain actions after a delay, but we did not inherit from monobehaviour. This prevented us from accessing coroutines to delay our execution. To prevent having to set up timers everywhere, I decided to make use of our MonobehaviourSingleton class to create a small Delayed Execute script, which is accessible from anywhere from its static instance (included in the MonobehaviourSingleton class). This small script provides the functionality to start a delayed execution of an action, and to provide an optional key with which the action can later be cancelled if needed.
This code is a small piece of the drag-and-drop system we had in place. Certain objects had to be moveable by using the touch screen. This code allowed us to set actions to play on completion or cancellation of a drag/drop. It is also responsible for moving the objects, which "stick" to the point the player touches (or clicks).
This last bit of code is from a display that shows all the players currently in the game, by showing their avatars in a grid. Here we see a loop through our playerdata, creating a "playerhead", which is the display object for their avatar, for each player and adding it to our grid. The player head is instantiated from a prefab, then has its graphics, ID and values set and the drag-and-drop script on it enabled and initialized.