By: Zoran Diaz and John Stalvey
This controller is designed to put you right in the ground with your player character and navigate the ground using the iron you find in the ground. To do this, we made a box of iron filings that get triggered by four sensors. To move, simply rotate the controller in the direction you want to. By doing this, you'll move the filings up to the sensor, triggering the input. Even if you don't understand how it works fully, the controller lures you into seeing the filings all loose in its container. By just moving it around a bit, you get immediate feedback by seeing your character move in the game. The WASD keys are used for filing movement, and when you're ready to attack en enemy, simply smack the controller. You'll hear the ground minerals quiver, as the ground shakes at your aggression to attack! All of this connects to the general theme of the game, with digging deep underground and trying to attack multiple enemies. The ground will move and shake as you defeat your enemies, and the controller does a good job immersing yourself in the games world. It truly feels like you're making your way around the deep ground, and visualize the attacks in the game. How do you think this could improve the gameplay experience of DigDug?
Both Zoran and John worked on the initial idea of the controller. Zoran figured out how it would roughly work, while John expanded upon it with more specific details. Zoran worked on the code, including getting the filing sensors working, and most of the electronic aspects of the controller. While I (John) worked with a fair amount of the electronics, my main focus was 3D modelling the controller and 3D printing it, making sure everything would fit. I also added other pieces to the controller to make it more complete.
#include <Adafruit_Circuit_Playground.h>
#include <Adafruit_CircuitPlayground.h>
#include <Keyboard.h>
#define HALL_SENSOR_A1 A1
#define HALL_SENSOR_A7 A7
#define HALL_SENSOR_A6 A6
#define HALL_SENSOR_A4 A4
// Function declaration
void handleKeyPress(bool condition, bool *state, int key, const char* keyName);
// Key press state trackers
bool leftPressed = false;
bool upPressed = false;
bool downPressed = false;
bool rightPressed = false;
bool xPressed = false; // x is the keybind for attacking
const uint8_t TAP_THRESHOLD = 15; // Tap Detection Sensitivity; Lower numbers = more sensitive
void setup() {
Serial.begin(115200);
CircuitPlayground.begin();
// Configure accelerometer
CircuitPlayground.lis.setRange(LIS3DH_RANGE_2_G);
CircuitPlayground.lis.setClick(2, TAP_THRESHOLD); // Double tap detection
pinMode(HALL_SENSOR_A1, INPUT);
pinMode(HALL_SENSOR_A7, INPUT);
pinMode(HALL_SENSOR_A6, INPUT);
pinMode(HALL_SENSOR_A4, INPUT);
Keyboard.begin();
}
void loop() {
static unsigned long lastHallCheck = 0;
const unsigned long hallInterval = 200;
uint8_t click = CircuitPlayground.lis.getClick();
bool doubleTapDetected = (click & 0x20); // Check for double-tap
handleKeyPress(doubleTapDetected, &xPressed, 'x', "X");
// Hall sensors
if (millis() - lastHallCheck >= hallInterval) {
lastHallCheck = millis();
int sensorValueA1 = analogRead(HALL_SENSOR_A1);
int sensorValueA7 = analogRead(HALL_SENSOR_A7);
int sensorValueA6 = analogRead(HALL_SENSOR_A6);
int sensorValueA4 = analogRead(HALL_SENSOR_A4);
handleKeyPress(sensorValueA1 < 235, &leftPressed, KEY_UP_ARROW, "Up");
handleKeyPress(sensorValueA7 < 235, &upPressed, KEY_RIGHT_ARROW, "Right");
handleKeyPress(sensorValueA6 > 4, &rightPressed, KEY_DOWN_ARROW, "Down");
handleKeyPress(sensorValueA4 < 220, &downPressed, KEY_LEFT_ARROW, "Left");
}
delay(100); // How often sensor values are checked for inputting keyboard presses
}
// handleKeyPress functionality
void handleKeyPress(bool condition, bool *state, int key, const char* keyName) {
if (condition) {
if (!*state) {
Keyboard.press(key);
Serial.print(keyName);
Serial.println(" pressed");
*state = true;
}
} else {
if (*state) {
Keyboard.release(key);
Serial.print(keyName);
Serial.println(" released");
*state = false;
}
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.