17 April 2021

Seen Game Controller

He happy, he blue, he ready to guide you through.


Description: This little blue bundle of happiness is the controller for the more emotionally blue game "Seen." Seen is controlled by 7 inputs: WASD movement, E for interact, Space for Jumping, and Shift to cover ears. These have been rebound to forward tilt, left tilt, back tilt, respectively. Jump is initiated when tilting to a greater extreme along any direction on any axis, which can be short jumped by tilting back. The potentiometers are enabling your E and Shift inputs by twisting, and there is a slide switch to turn the controller on/off. All feedback in these cases comes straight from the game with tilt causing your character to move and jump and in the case of shift potentiometer coving your ears. The least intuitive is the interaction as you must stand next to something interactable but it is the final control so thus it is the only one that is unique in this regard. I will admit the lack of labeling on the controller but promise that a single explanation is all that is required as 5 of the 7 controls are motion-based intuition that is highly responsive in the game leaving only two to be remembered. The two major themes of the game are hope and determination, fitting in right along with the controller in terms of mastery over it. However, it is a companion alongside your struggles as you explore Seen's dark world and as you use the buddy to push and pull your character to wherever he must go. This brings me to the design of the controller, I desired something round and blue as this is the identification of the hope and determination collectibles continuing to track that concept of the reward gained from struggles. It is meant to be held in one hand with your other assisting via the dials for when situations arise, given the more relaxed feel of the game they are not needed to be used demandingly, so it is not needed to have rapid-fire button press-esk inputs. A question I pose to those who wish to offer some manner of critique that I am greatly interested in, is thus: What input do you believe is the most functional for performing a jump action in a game if you cannot use a button? In my case, I could not simply use a tilt switch or z-axis as it would destroy and control over movement, thus my additional tilt mechanic, but it was not my first attempt...


Schematic


Code: 

//Libary Inclusions

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>

#include <Keyboard.h>

#include <Wire.h>

#include <SPI.h>


// https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardmodifiers/


#define XACCEL_MIN 0.1 //Min value for X axis on accel

#define XACCEL_MAX 8.0 //Max value for X axis on accel

#define YACCEL_MIN XACCEL_MIN //Same as above for Y

#define YACCEL_MAX XACCEL_MAX //Same as above for Y


#define FLIP_AXES true


const int debounce = 100;

int vertCheckW = 0;

int vertCheckS = 0;


void setup() {

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

  Serial.begin(9600); //Open Serial Monitor

  delay(100);

  CircuitPlayground.begin(); //Init CPE

  Keyboard.begin();

}


void loop() {

  // put your main code here, to run repeatedly:

  //Variable Tracking

  //Reading V from A1-A3, A1-A2 controlled via potentiometer, A3 controlled by slideswitch

  int pot1 = analogRead(A2);  //Min Value ~2 Max Value ~1000, Thresh for button press can effectively be 300 or so.

  int pot2 = analogRead(A3);  //Min Value ~2 Max Value ~1000, Thresh for button press can effectively be 300 or so.

  int onOff = analogRead(A1); //Min Value ~400ish Max Value ~1000, set thresh at about 900 to simulate on/off


  //Accel X is recording from X axis on accelerometer, same respectively for Y

  float accelX = CircuitPlayground.motionX(); //Defined Above: Min 0.1, max 0.8, thresh for motion should be around 3-4, with jumping being over 5 or so.

  float accelY = CircuitPlayground.motionY();


  //Controller Code, can only run if slideswitch is flipped "On" Coded this was as onboard (CPE) slideswitch is malfunctioning, simple switch simeply passes voltage through wires to CPE cap A1 or blocks it.

  if(onOff > 900) //On off check conditional

  {

  //Potentiometers

    if( pot1 > 300 )

    {

      Keyboard.press('e');//Presses E for interact, delayed so as to be a repeatable presss and not hold

      Keyboard.release('e');

      delay(1000);

    }

    if ( pot2 > 300 )

    {

      Keyboard.press(KEY_LEFT_SHIFT); //Holds shift key (Cover Ears), no delay as it is ment to be held until released (dialed back to below 300)

      //Test: If functioning should create capital letters if turned on and tilt action is performed.

    }else if ( pot2 < 300){

      Keyboard.release(KEY_LEFT_SHIFT);

    }

  //Accelerometer

  //Right Tilt

    if (accelX < -2.0)

    {

      Keyboard.press('d'); //Holds D key so as to continuously move right

      if (accelX < -5.0)

      {

        Keyboard.press(' '); //If tilted farther space will be held allowing you to jump in that direction

        //Note: A held jump goes higher than a "tapped one" so you can tilt and hold to jump higher/farther or tilt back to make it shorter

      }else if (accelX > -4.0){

        Keyboard.release(' ');

      }

    } else if (accelX > -2.0){

      Keyboard.release('d');

    }

    //Left Tilt

    if (accelX > 2.0)

    {

      Keyboard.press('a'); //Holds D key so as to continuously move right

      if (accelX > 5.0)

      {

        Keyboard.press(' '); //If tilted farther space will be held allowing you to jump in that direction

        //Note: A held jump goes higher than a "tapped one" so you can tilt and hold to jump higher/farther or tilt back to make it shorter

      }else if (accelX < 4.0){

        Keyboard.release(' ');

      }

    }else if (accelX < 2.0){

      Keyboard.release('a');

    }

    //Foward Tilt

    if (accelY < -3.0 && vertCheckW == 0)

    {

      Keyboard.press('w'); //Tap W key to move up

      Keyboard.release('w');

      vertCheckW = 1; //Prevents constant upward motion, must tilt back and retilt forward to go up again.

    }

    if (accelY < - 5.0){

        Keyboard.press(' '); //If tilted farther space will be held allowing you to jump in that direction

        //Note: A held jump goes higher than a "tapped one" so you can tilt and hold to jump higher/farther or tilt back to make it shorter

        if (accelY > -4.0){

          Keyboard.release(' ');

        }

    }

    if (accelY > -1.0){

      vertCheckW = 0;

    }

    //Backward Tilt

    if (accelY > 3.0 && vertCheckS == 0)

    {

      Keyboard.press('s'); //Tap W key to move up

      Keyboard.release('s');

      vertCheckS = 1; //Prevents constant upward motion, must tilt back and retilt forward to go up again.

    }

    if (accelY > 5.0){

        Keyboard.press(' '); //If tilted farther space will be held allowing you to jump in that direction

        //Note: A held jump goes higher than a "tapped one" so you can tilt and hold to jump higher/farther or tilt back to make it shorter

        if (accelY < 4.0){

          Keyboard.release(' ');

        }

    }

    if (accelY < 1.0){

      vertCheckS = 0;

    }

  }


  // Input Readings

  /*

  Serial.println(analogRead(A1)); //Electrical reading from A1

  Serial.print("\t");

  Serial.println(analogRead(A2)); //Electrical reading from A2

  Serial.print("\t");

  Serial.println(analogRead(A3)); //Electrical reading from A3

  Serial.print("\t");

  Serial.println("X: " + String(accelX)); //Accel Reading on XAxis

  Serial.print("\t");

  Serial.println("Y: " + String(accelY)); //Accel Reading on YAxis

  delay(400);

  */

  

}

Video Embed:



No comments:

Post a Comment

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