17 April 2022

Jump King Game Controller

 I made my controller for the game Jump King. I had to rework my whole controller concept because I came up with my initial idea before reading too much of the details from the final project page. Even though the controller is completely different, I still wanted to make it for Jump King. I decided to keep with the box design. I did add a cardboard flap that can be used as a cover for the controller. I thought this was a clever design idea so that someone can more easily store the controller and keep any dust away from the light sensor. I also made the controller reversible depending on the player's dominant hand. Based on where the light sensor hole is, you can hold the controller "upside down" so that you can cover the hole with your right thumb instead. I thought this was neat touch since I am left handed and I wanted to make something accessible for everyone. The game's objective and only controls are jumping. You can jump in different directions. That is why I made my controller use the accelerometer so that the player can tilt the controller to decide whether they want to jump to the right or the left. You also will see a small hole near the center of the controller. That hole is for the light sensor on the CPE. Covering the hole will charge the jump. When I first played Jump King I felt the controls to be a little bit awkward. I think I accomplished my goal with making my controller more comfortable to use than the game's original keyboard controls. Is there any other designs that I could of gone with to make the controller more related to the game?


Schematic:
 


Code:


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

// Variables
const int debounce = 100;
const int threshold = 500;
int light;


void setup()
    {
// Setup Code Here
CircuitPlayground.begin();
usb_hid.begin();
Serial.begin(9600);
delay(10000);
    }

void loop()
{
// Main Code Here
Serial.print(analogRead(A8)); //Light Sensor on CPE
Serial.print('\t');
int numReads = 15; // Number of Samples
int senseSum = 0; k < numReads; k++) 
{
senseSum += analogRead(A8);
delay(1);
}
int senseAve = senseSum / numReads; // Average of the sensor readings
Serial.println(senseAve);
delay(200);
int sense2bright = map(senseAve, 0, 1023, 0, 255);
// Light Function for Jumping
if (light <=300)
{
keycode[0] = HID_KEY_SPACE_BAR;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
}
// Axis values for the Accelerometer
float x = CircuitPlayground.motionX();
float y = CircuitPlayground.motionY();
float rad = atan2(y,x);

// Tilting the controller to jump to the right
if(rad < -2.0 | | rad > 3.0)
{
keycode[0] = HID_KEY_ARROW_RIGHT;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
}
// Tilting the controller to jump to the left
if(rad > -1.0 & & rad < 0.3)
{
keycode[0] = HID_KEY_ARROW_LEFT;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
}
}

Serial.print(CircuitPlayground.readCap(A3));
Serial.print("\t");
Serial.println(analogRead(A2));






No comments:

Post a Comment

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