18 April 2022

Game Controller: World Next Door Controller

 Before I begin my description, I will admit to the fact that I have changed the original game and design of my controller to fit the new game. There were too many factors in the mechanics of the original that wouldn’t all work with my original plan. However, I have found a new game and all the mechanics in it work well with my code and I have slightly changed the new design to fit the game. 

For my controller, I used the sword design that the protagonist of World Next Door, Jun, finds in her possession through the playthrough of the game. In the original concept design, I have the arduino and the usb run through the handle up to the pendant at the hilt. The key inputs mostly rely on light and the x and y accelerometers in order to play the game. I went with more simpler inputs since WND is a more puzzle reliant for its battles/playstyle. The player would have to move the sword around and use your hand and/or a light source to use the game's mechanics. 
These factors are into the controller that resembles the protagonist's weapon, but also an easy way for the user to figure out how to play because of sword usage in pop culture (specifically anime) and other games. Instructions on the 'blade' of the sword will also be 'engraved' into it to make it even more obvious for the user. This gives the user a more fantastical experience, which reflects the adventure that Jun finds herself in, and also anime as well. It also doesn’t have to use the controller, yet focuses on the challenge of the puzzles/battles in game as you go on. 


For my question, instead of using a flashlight for my X function, what would you suggest using to replace that?


Images of Controller




Schematic



Video

(showcases the movement and interaction keys)


Gameplay in action in tutorial area (Obs kept cutting the recording on this)





Code



#include "Adafruit_TinyUSB.h"

#include <Adafruit_CircuitPlayground.h>

#include  <Adafruit_Circuit_Playground.h>



//HID report descriptor using TinyUSB template

//Single Report (no ID) descriptor

uint8_t const desc_hid_report[] =

{

  TUD_HID_REPORT_DESC_KEYBOARD()

};



// USB HID object. For ESP32 these values cannot be changed after this declaration

// desc report, desc len, protocol, interval, use out endpoint

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



  // Varaibles

const int debounce = 100;

const int thresh = 500;


int light; 




void setup() {

// pinMode(LEDpin, OUTPUT);

// Serial.begin(9600);

 //while(!Serial);

 

  CircuitPlayground.begin();

  // put your setup code here, to run once:

  pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);

  pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN);  //BUTTON A

  pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN); //BUTTON B


  usb_hid.begin();

}


void loop() {

  uint8_t const report_id = 0; // unsigned 8bit (1byte) int

  uint8_t const modifier = 0;  //used by libraries to save space 

  uint8_t keycode[6] = {0}; // normal int is 16 bit (4 bytes)


          

    //read accelerometer x and y

  float x = CircuitPlayground.motionX(); //move left and right

  float y = CircuitPlayground.motionY(); // move up and down

  float rad = atan2(y, x); 

  light = analogRead(A8); //cover light to interact/ press c & expose light to exit

  //sound = analogRead 

    Serial.print(x);

    Serial.print("\t");

    Serial.print(y);

    Serial.print("\t");

    Serial.println(rad);

    Serial.print("\t");

 // get code to have playground read when on z axis along with y & x 


      //go left

     if (x <= -4)

    {

      keycode[0] = 0x50; //x0x04;//a goes here

      //0x50; (Left arrow)

  usb_hid.keyboardReport(report_id, modifier, keycode);

   delay(debounce);

   usb_hid.keyboardRelease(0);

   }

     // go right

     if (x >= 4)

     {

      keycode[0] =  0x4F; //0x07; //insert d key here for test

    //0x4f ; (Right arrow)

    usb_hid.keyboardReport(report_id, modifier, keycode);

   delay(debounce);

      usb_hid.keyboardRelease(0);

      }

     //go up

     if (y >= 3)

     {

      keycode[0] =  0x52; //0x1A; //up arrow code 

      usb_hid.keyboardReport(report_id, modifier, keycode);

   delay(debounce);

      usb_hid.keyboardRelease(0);

      }

      //go down

     if (y <= -3)

     {

      keycode[0] =  0x51; //0x16; //down arrow code

      usb_hid.keyboardReport(report_id, modifier, keycode);

   delay(debounce);

   usb_hid.keyboardRelease(0);

      }

      

      // EXIT/BACK

      //also light function

       if (light  >=350){

          keycode[0] =   0x1B; //( X KEY)

   usb_hid.keyboardReport(report_id, modifier, keycode);

   delay(debounce);

   usb_hid.keyboardRelease(0); 

       }

   


     // Space/C interaction function

        // uses analog sensor-light 

        if (light <=5){

          keycode[0] =   0X06; 

           usb_hid.keyboardReport(report_id, modifier, keycode);

   delay(debounce);

   usb_hid.keyboardRelease(0); 

        }


        // set brightness of the LED

            // also set color of playground to red for crystal in sword

     

  }


No comments:

Post a Comment

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