16 April 2022

Galaga Game Controller

 Final Controller: 



Description:

The video game I chose to make a controller for is the retro arcade game Galaga. I chose this game because I had always been a fan of classic games and thought it would be cool to design a controller for one as well. The idea behind my idea was originally to design a "retro" like controller that mimicked how old game systems were to look. For materials I used cardboard that I had spray painted with metallic silver to try and give it a retro theme along with gold knobs to bring out some contrast. The mapping for this controller are two potentiometers and two tact switches which controls all the components in the game. That being horizontal movement, vertical movement, fire/select, and pause. Making the game fully playable with just this controller. I went for full control with the design because a lot of retro games are short on inputs so i figured why not make it where you can control the entire game with just the controller. The controller was made in a way to somewhat mimic both a joy con system and a classic arcade setup which would make it super easy to pick up and relatively simple to play. Unfortunately I ran into mechanical issues where my CPE stopped running the code I had set, so I was not able to fully complete the project. If all was working normal, what is one significant design change whether that be physical or internal would you have made to allow this controller to stand out more?



#include <Adafruit_TinyUSB.h>

#include <bluefruit.h>

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>



//By Patrick Weatherford


uint8_t const desc_hid_report[] =

{

  TUD_HID_REPORT_DESC_KEYBOARD()

};


Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_KEYBOARD, 2, false);


const int SWITCH_ESCAPE = A3;

const int SWITCH_SHOOT = A4;

const int delaynumber = 100;

const int POT_HORIZONTAL = A1;

const int POT_VERTICAL = A2;

const int value = 0;

const int store = 0;


float floatMap(float x, float in_min, float in_max, float out_min, float out_max)

{

  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;

}


void setup() {

  CircuitPlayground.begin();

  pinMode(SWITCH_ESCAPE, INPUT);

  pinMode(SWITCH_SHOOT, INPUT);

  pinMode(POT_HORIZONTAL, INPUT);

  pinMode(POT_VERTICAL, INPUT);

  Serial.begin(9600);

  

  usb_hid.begin();

}


void loop() {

  uint8_t const report_id = 0;

  uint8_t const modifier = 0;

  uint8_t keycode[6] = {0};


  //Pause Game


  if(digitalRead(SWITCH_ESCAPE))

  {

    keycode[0] = 0x29;

    usb_hid.keyboardReport(report_id, modifier, keycode);

    delay(delaynumber);

    usb_hid.keyboardRelease(0);

  }


  //Fire/Select in pause menu

  

    if(digitalRead(SWITCH_SHOOT))

  {

    //if switch is flipped it will shoot 

    keycode[0] = 0x2C;

    usb_hid.keyboardReport(report_id, modifier, keycode);

    delay(delaynumber);

    usb_hid.keyboardRelease(0);

  }


  //Horizontal Movement

  

  if(analogRead(POT_HORIZONTAL))

  {

    int value = analogRead(POT_HORIZONTAL);

    float voltage = floatMap(value, 0, 1023, 0, 5);

    Serial.println(value);

    if(value < 300)

    {

      //click letter a on keyboard

      value = abs(value);

      keycode[0] = 0x04;

       usb_hid.keyboardReport(report_id, modifier, keycode);

    }

   if(value > 700)

    {

      //click letter d on keyboard

      keycode[0] = 0x07;

       usb_hid.keyboardReport(report_id, modifier, keycode);

    }

   if(300<value<700)

  {

    usb_hid.keyboardRelease(0);

  }

  

 }


 //Vertical Movement


  if(analogRead(POT_VERTICAL))

  {

    int value = analogRead(POT_VERTICAL);

    Serial.println(value);

    if(value < 300)

    {

      //click letter w on keyboard

      value = abs(value);

      keycode[0] = 0x1A;

       usb_hid.keyboardReport(report_id, modifier, keycode);

    }

   if(value > 700)

    {

      //click letter s on keyboard

      keycode[0] = 0x16;

       usb_hid.keyboardReport(report_id, modifier, keycode);

    }

   if(300<value<700)

  {

    usb_hid.keyboardRelease(0);

  }

  

 }


}




No comments:

Post a Comment

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