27 March 2021

Scaffolding: Progress Review

I'm making my controller use the up, down, left and right movement for the game Frogger. The CPE will be controlling the up and down movement with buttons D4 and D5 while the potentiometer will be moving the frog left to right and light up two LEDs whenever it’s turned in a certain direction and turn off when turned in other. It is a game controller that uses the replacement of arrow keys. It also is similar to playing with a game controller for PC games if using keyboard isn’t your style. The two questions I have are as follows:

How can I improve upon my code?

What could I add to make it more appealing towards the final product of my game controller?

#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>

//Variable for gameplay movement and LED lights
const int UpButton = 4;
const int DownButton = 5;
const int LEDpin = 13;
int neoState = 0;
int current = 0;
int previous = 0;
int pot = 0;

//Setting up game controller before playing game
void setup()
{
  //Buttons for controlling up and down
  pinMode(UpButton, INPUT); //CPLAY_LEFTBUTTON
  pinMode(DownButton, INPUT); //CPLAY_RIGHTBUTTON

  //LED for lighting up whenever player turns potentiometer to left or right for movement
  pinMode(LEDpin, OUTPUT); //LED D13

  //Initiate library
  CircuitPlayground.begin();

  //Wait for player to start using controller for game
  Serial.begin(9600);
  while(!Serial){
    for (int i = 0; i < 10; i++){
      CircuitPlayground.clearPixels();
      CircuitPlayground.setPixelColor(i, 200, 200, 0);
      delay(100);
      if(i >= 10){
        i = 0;
      }
    }
  } 

  //Start playing the game with controller
  for(int i = 0; i < 3; i++) {
    CircuitPlayground.clearPixels();
    delay(200);
    for(int i = 0; i < 10; i++){
      CircuitPlayground.setPixelColor(i, 0, 200, 0);
    }
    delay(200);
  }

  CircuitPlayground.clearPixels();
  Serial.println("Beginning Game. Please wait...");
  delay(500);
  Serial.println("Begin Playing!");
}
  
//Code to run game movements and LED lights while playing game
void loop() 
{
  //When UpButton is pressed
  if(digitalRead(UpButton) == HIGH)
  {
    //Moving character up
    digitalWrite(LEDpin, HIGH);
    Serial.println("Up"); //Prints whenever player moves their character up
    delay(100);
  }

  else 
  {
    //Stops character from moving up
    digitalWrite(LEDpin, LOW);
    Serial.println("Stop"); //Prints whenever player stops character from moving up
    delay(100);
  }

  //When DownButton is pressed
  if(digitalRead(DownButton) == HIGH)
  {
    //Moving character down
    digitalWrite(LEDpin, HIGH);
    Serial.println("Down"); //Prints whenever player moves character down
    delay(100);
  }

  else 
  {
    //Stops character from  moving down
    digitalWrite(LEDpin, LOW);
    Serial.println("Stop"); //Prints line whenever player stops character from moving down
    delay(100);
  }
  
}
  


                                                                                                                                                                        









No comments:

Post a Comment

Note: Only a member of this blog may post a comment.