17 April 2022

Sonic Game Controller


 

For my project, I chose to make a controller for sonic the hedgehog. Sonic is a fairly simple game and because of that, I wanted to have simple controls. I struggled with choosing between three options early on, but I was able to cut it down to one and that was a ring. Rings in sonic are like coins in Mario. They’re the main if not only collectible and are extremely important in sonic lore. The only other idea that I had that better symbolized Sonic was a shoe. The ring itself is a simple gold ring. I didn’t want wires hanging out of it and since it’s a ring with an almost solid middle the only way I’d be able to have wires, or a breadboard would be to make the rung huge or put them in the middle. There are no direct signifiers. I almost chose to use text as a signifier but that would’ve ruined the design and almost felt like an insult. I don’t think a game that only has movement, and a jump option needs to tell its players how to perform those options. The vagueness of the ring sort of forces the player to move and once you move once it becomes apparent that, that’s how you make Sonic move. I chose to rely only on the accelerometer and movement because that’s what Sonic is all about. You don’t fight and sonic and when you do it happens because you ran and jumped on top of any enemy. The main goal in and Sonic game is usually to move fast and forward freely and chaotically and that’s the atmosphere my controller creates. My only question has to do with the design of the controller. How would you have used signifiers on the controller without ruining the design?

                                                               Schematic:


Code:

#include "Adafruit_TinyUSB.h"
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
#include <math.h>


// HID report descriptor using TinyUSB's 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);


int shakeThresh = 30; //max 40
const int debounce = 100;
const int thresh = 500;


void setup() {
// put your setup code here, to run once:
//Initialize CPB and Keyboard output
usb_hid.begin();
Serial.begin(9600);
CircuitPlayground.begin();

}


void loop() {
// put your main code here, to run repeatedly:
uint8_t const report_id = 0;
uint8_t const modifier = 0;
uint8_t keycode[6] = { 0 };
float x = CircuitPlayground.motionX();
Serial.print(x);
Serial.print("\t");

if(x < -3){
keycode[0] = 0x04;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
}
//shake
if(x > 3) {
keycode[0] = 0x07;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);


float x = CircuitPlayground.motionX();
if(x < 0){
CircuitPlayground.setPixelColor(2,0,0,map(x, -10, 0, 255, 0));
} else {
CircuitPlayground.setPixelColor(7,0,0,map(x, 0, 10, 0, 255));
}
Serial.println(x);
}
float shake = abs(CircuitPlayground.motionX())
+ abs(CircuitPlayground.motionY());
+ abs(CircuitPlayground.motionZ());
if(shake > shakeThresh) {
keycode[0] = 0x2C;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
CircuitPlayground.playTone(440, 200);
}


}


No comments:

Post a Comment

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