06 April 2022

Scaffolding: Game Controller Progress Review

 Galaga Controller

    For this project, I wanted a more retro controller for the retro game I'm doing so my design is a little on the basic side but I want to get some changes in depending on how much time I have after getting all the code and physical aspects built. My controls will be simple, there will be a potentiometer and a tact switch on each side of the controller. On one side the pot will control horizontal movement and the opposite switch will control the firing of the gun. On the other side the pot will control the vertical menu sliders with the opposite side switch activating the pause menu. 









Pseudo Code Below:

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

int moveVert = 0;

int moveHor = 0;

int moveHorizontal = 0;

int moveVertical = 0;

boolean pressed1 = false;

boolean pressed2 = false;

//variables have not been perfectly identified and cpe mapping may be subject to change.


void setup() {
  // put your setup code here, to run once:

CircuitPlayground.begin();

pinMode(A1, INPUT_PULLUP);

pinMode(A2, INPUT_PULLUP);

Keyboard.begin();

Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  // firing code written, shoots as fast as you can toggle the switch

if(digitalRead(A1)){
  pressed2 = false;
  if(!pressed1){
    Keyboard.press('C');
    pressed1 = true;
  }
}
else{
  pressed1 = false;
  if(!pressed2){
    Keyboard.press('C');
    pressed2 = true;
  }
}

  //potentiometer mapping

  //spaceship movememnt
  moveVert = analogRead(A3);

  moveHor = analogRead(A4);

  moveVertical = map(moveVert, 0, 1023, 0, 10);

  moveHorizontal = map(moveHor, 0, 1023, 0, 10);

  //moving right and left whatever button that is
if(moveHorizontal == 10){

    Keyboard.press(right);
  }

  if(moveHorizontal != 0 && moveHorizontal != 10){

    Keyboard.releaseAll();

  }
  
if(moveHorizontal == 0){

    Keyboard.press(left);
  }


  //menu movement
  if(moveVertical == 10){

    Keyboard.press(right);
  }

  if(moveVertical != 0 && moveVertical != 10){

    Keyboard.releaseAll();

  }
  
if(moveVsertical == 0){

    Keyboard.press(left);
  }


  //Pause Menu
if(digitalRead(A2)){
  Keyboard.press(pause)
}
else{
  Keyboard.release(pause)
  }
}


Questions!


1. My design is a little basic but based off that what are some ways I can improve it and make it fit the theme of my game a little more?

2. Based on my schematic, what is some way I can improve it and feel as if it was written or drawn better? 

No comments:

Post a Comment

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