Description:
I wanted my controller to give the
player a better sense of the gameplay while playing. Galaga is a game that
requires the player to move left and right with the spaceship. I want to mimic
the spaceships movement in the game with the controller the player uses. The
player will have to tilt the controller left and right to move left and right in
the game. The CPE will be in the middle of the controller to be able to read
the movement of the controller tilting left or right. This direction of design
makes the game more immersive for the player. The controller is designed to
simulate a spaceship that you also play as in the game. The spaceship is also
having sticks to hold so it isn’t just someone holding a spaceship so I added
hand holds so the player can easily maneuver left and right while shaking to
shoot. The theme of the game is spaceships shooting each other while dodging
enemy attacks. The best way I can see to add to the theme is using a spaceship
to control the spaceship in the game. The shaking can signify the relationship between
the pressure the player feels while playing the game, maneuvering around enemy
attacks while shaking to shoot because shaking to shoot can be rather difficult
which is why it simulates the player’s struggle. My design manifests on
simulating a space struggle while play Galaga. The player having a struggle
battle against enemy ships in space moving left and right and shaking to shoot.
Does the hand holds on the controller improve the design or is there another
way to think about it?
#include "Adafruit_TinyUSB.h"
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
//Made by Mohammad Saadeh
//Variable for shake thresholdint shakeThresh = 25;
// Single Report (no ID) descriptoruint8_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);
//Variable for smoothingconst int debounce = 100;
const int thresh = 500;
void setup() {//Initialize CPE and Keyboard output
CircuitPlayground.begin();
//Right button initialize
pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN); //Button B
//being keyboard input
usb_hid.begin();
delay(1000);
}
void loop() {// put your main code here, to run repeatedly:
//Variables for values
//Accelerometer axis valuesfloat x = CircuitPlayground.motionX();
float y = CircuitPlayground.motionY();
float rad = atan2(y,x);
//set neopixel to light up when CPE is tilted left and rightif(x < 0) {
CircuitPlayground.setPixelColor(1,0,0,map(x, -10, 0, 255, 0));
} else {
CircuitPlayground.setPixelColor(8,0,0,map(x, 0, 10, 0, 255));
}
Serial.println(rad);
//shake motion initialize on accelerometer
float shake = abs(CircuitPlayground.motionX())
+ abs(CircuitPlayground.motionY())
+ abs(CircuitPlayground.motionZ());
uint8_t const report_id = 0; //unsigned 8bit intuint8_t const modifier = 0; //used by libraries to save space
uint8_t keycode[6] = {0}; // normal int that is 16 bit
//input space key on right button on CPEif(digitalRead(CPLAY_RIGHTBUTTON)){
keycode[0] = HID_KEY_SPACE;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
}
//Tilt Right to simulate right arrow key on keyboard
if(rad < -2.05 || rad > 2.85){
keycode[0] = HID_KEY_ARROW_RIGHT;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
}
//Tilt Left to simulate left arrow key on keyboard
if(rad > -1.05 && rad < 0.3){
keycode[0] = HID_KEY_ARROW_LEFT;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);
usb_hid.keyboardRelease(0);
}
//Shoot by shaking CPE also simulating space key on keyboard
if(shake > shakeThresh) {
keycode[0] = HID_KEY_SPACE;
usb_hid.keyboardReport(report_id, modifier, keycode);
delay(debounce);usb_hid.keyboardRelease(0);
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.