//this has been completely commented! Good job Antny!
//include the following header files#include "vid_sender.h"
#include "led_ctrl.h"
#include "game_state.h"
#include "monster.h"
#include "buttons.h"
//Remember that the functionality here is that the first word defines the class and the second names it essentially.
//e.g. there's now a Gamestate class with the name Gamestate, and three monster classes with the names DirectMonster, Wanderer, and MusicMonster
//I can see this section being much more complex in the future with different game modes as defined in the gamestate header file contributing to which classes need to be defined.
Gamestate gamestate;
Monster DirectMonster; // Right Monster; // Monster 0 //future iterations will likely need to redefine these with names to make it easier for us to track certain monsters. Especially when certain ones will have different abilities
int DirectMonsterType = 0;
Monster Wanderer; // Left_Monster; // Monster 1
int WanderMonsterType = 1;
Monster MusicMonster; // Music Monster in the Kitchen; // Monster 2
int MusicMonsterType = 2;
Monster Observed; //Observed Monster
int ObservedMonsterType = 3;
SerialSender sid; //from vid)sender.cpp
Buttons buttons; //from buttons.cpp
LED_Manager leds; //from led_ctrl.cpp
#define TARGET_PERIOD 50 //not sure if this is used ever?
#define SERIAL_PERIOD 100 // change in time in milliseconds befere sending another serial packet
#define FLASHING_INTERVAL 20 // seconds until lights reset intensity if flashing
unsigned long start_time; //used at the loop. Returns the time since the program started.
unsigned long last_serial_time; //used at the very bottom of this code
int difficulty = 1; //starting difficulty
float intensity = 0; //declares the intensity which will change and be used on the loop
void setup() {
buttons.setup(); //check buttons.cpp for this, but it sets up which pins on the arduino will do what. AKA pin 30 on the arduino will look for changes in status to display cam0
DirectMonster.setup(DirectMonsterType, difficulty); //check monster.cpp for this, but it sets up DirectMonster's attributes
Wanderer.setup(WanderMonsterType, difficulty); //same as above
MusicMonster.setup(MusicMonsterType, difficulty); // same as above
Observed.setup(ObservedMonsterType, difficulty); // same as above
sid.setup(); //set up baud rate basically
leds.setup(); //void LED_Manager::setup() is in led_ctrl.cpp that shows what sets up here. But basically, this is where we will assign pin numbers on the arduino to the LEDs
gamestate.setup(); //check the game_state.cpp file, but sets up the attributes of the power, power draw and such for all items as well as getst the game state set to 0
}
void loop() {
// Read Inputs
start_time = millis(); //returns the time since the program started. Nothing whacky here
buttons.read(); //returns the status of all buttons on the control panel. Are any of them pressed? This information will be important for below code, but for this innocuous line, it's just to get those values
// Determine action
if (gamestate.gamemode == 0){
// idle/initialization. All this really does is set the ambient lighting to what it should be then waits for the user to press the music button to start the game
leds.set_idle_lighting();
sid.update_vid(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate); // play the menu
sid.update_powerdraw(1); //sets the powerdraw to min powerdraw since nothing else is turned on?
sid.update_power(1); //sets the power to max value
if(buttons.cam0.value == 1){
// press cam 1 to start game
gamestate.next_state(); //starting the game basically just means going to the next state in the game. In this scenario, it puts the player from initializing to being in play
}
//Difficulty setting prior to start
if(buttons.cam1.value == 1){
// press cam 2 reps night 2
gamestate.NightUP(); //increase the difficulty of the night
gamestate.next_state(); //starting the game basically just means going to the next state in the game. In this scenario, it puts the player from initializing to being in play
}
if(buttons.cam2.value == 1){
// press cam 3 reps night 3
gamestate.NightUP(); //increase the difficulty of the night
gamestate.NightUP(); //increase the difficulty again
gamestate.next_state(); //starting the game basically just means going to the next state in the game. In this scenario, it puts the player from initializing to being in play
}
if(buttons.cam3.value == 1){
// press cam 4 reps night 4
gamestate.NightUP(); //increase the difficulty of the night
gamestate.NightUP(); //increase the difficulty again
gamestate.NightUP(); //increase the difficulty again
gamestate.next_state(); //starting the game basically just means going to the next state in the game. In this scenario, it puts the player from initializing to being in play
}
}
if (gamestate.gamemode == 1){ //intro time
if(buttons.music.value == 1){
// press music to skip
gamestate.next_state(); //starting the game basically just means going to the next state in the game. In this scenario, it puts the player from initializing to being in play
gamestate.update(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate.difficulty,1);
}
leds.set_idle_lighting();
sid.update_vid(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate); // play the menu
sid.update_powerdraw(1); //sets the powerdraw to min powerdraw since nothing else is turned on?
sid.update_power(1); //sets the power to max value
}
else if (gamestate.gamemode == 2){
// Game is in-play. The following are a summation of all the things the game is checking during this time essentially.
DirectMonster.update(DirectMonsterType, buttons.DirectMonster_door, buttons.cam1, buttons.cam4, buttons.MusicMonster_light, gamestate.music, gamestate.difficulty); //this updates the status of the first monster. The only input we'll need that can affect the monster's status is if the door is closed. In a future iteration, this may likely take in more inputs based on what could affect the monster's positioning. For instance, is the cam view on it? That can affect the status of the monster
Wanderer.update(WanderMonsterType, buttons.Wanderer_door, buttons.cam1, buttons.cam4, buttons.MusicMonster_light, gamestate.music, gamestate.difficulty); //naturally, the same as the above
MusicMonster.update(MusicMonsterType, buttons.music, buttons.cam1, buttons.cam4, buttons.MusicMonster_light, gamestate.music, gamestate.difficulty); //remember, there's no door for the third monster. But, we do need to play music to block it in the same way. That's why it's an input here
Observed.update(ObservedMonsterType, buttons.cam0, buttons.cam1, buttons.cam4, buttons.MusicMonster_light, gamestate.music, gamestate.difficulty); //naturally, the same as the above
leds.set_ingame_lighting(buttons, DirectMonster, Wanderer, MusicMonster, Observed, sid.current_vid_packet, gamestate.music, gamestate.audience, gamestate.cooldown); //delete music and packet
gamestate.update(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate.difficulty,0); //this whole thing finds what the power draw, power, music and sets the game to game over if the power is less than 0 or the monsters killed the player. This is the game mode-setter
sid.update_vid(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate); //using these inputs, this function will update to what video should be playing on the monitor and ship it to Mok's script
sid.update_power(gamestate.power); //the current power was found in gamestate.update() we'll use that value as an input here and ship that to Mok's video script
sid.update_powerdraw(gamestate.power_draw); //the current power draw was also found in that gamestate.update() and is gonna be sent to Mok
sid.update_music(gamestate.music); //the current music state was also found in that gamestate.update() and is gonna be sent to Mok
sid.update_time(gamestate.Current_time); //the current time state was also found in that gamestate.update() and is gonna be sent to Mok
sid.update_difficulty(gamestate.difficulty); //the current time state was also found in that gamestate.update() and is gonna be sent to Mok
}
else if (gamestate.gamemode == 4){
// Game is over and u died
leds.set_death_lighting();
sid.update_vid(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate); // play the menu //play the game over video...
if(buttons.music.value == 1){ // press music buttton to start the next night
difficulty = 1; //starting difficulty
gamestate.update(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate.difficulty,1);
gamestate.nextGame();
DirectMonster.ResetGame(DirectMonsterType);
Wanderer.ResetGame(WanderMonsterType);
MusicMonster.ResetGame(MusicMonsterType);
Observed.ResetGame(ObservedMonsterType);
gamestate.gamemode = 0; //starting the game basically just means going to the next state in the game. In this scenario, it puts the player from initializing to being in play
}
}
else if (gamestate.gamemode == 3){
// Game is over and you're onto the next night
leds.set_win_lighting();
sid.update_vid(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate); // play the menu //tell the guest they won the night!
if(buttons.music.value == 1){
// press music buttton to start the next night
gamestate.nextGame();
DirectMonster.ResetGame(DirectMonsterType);
Wanderer.ResetGame(WanderMonsterType);
MusicMonster.ResetGame(MusicMonsterType);
Observed.ResetGame(ObservedMonsterType);
gamestate.NightUP(); //increase the difficulty of the night
gamestate.update(buttons, DirectMonster, Wanderer, MusicMonster, Observed, gamestate.difficulty,1);
gamestate.gamemode = 2; //starting the game basically just means going to the next state in the game. In this scenario, it puts the player from initializing to being in play
}
}
// Send outputs
if((millis() - last_serial_time) > SERIAL_PERIOD){
sid.send(sid.current_vid_packet, gamestate.Current_time);
last_serial_time = millis();
}
}