25 November 2023

Custom Game Contoller


Super Mario Controller


    This is my custom controller for Super Mario Bros, which can be player online for free here. The controller is designed to visually look like the mystery box that can be found within more recent versions of the game, but still has the box with a question mark visual that this version of the game has. While at first, the controller doesn't really show any signifiers on how it's meant to be used outside of a light sensor, one should be able to easily assume that movement is involved in some way as there are no external knobs, buttons, switched, or joysticks, the only visible things is the light sensor at the top. Tilting the controller in different directions allows for most of the actions within the game, giving feedback to the player as they cause Mario to move and act. The obvious two are moving left and right, where tilting it in the desired direction moves you in that direction. Tilting the controller towards you, which has a similar motion of lifting it higher, allows you to jump, so doing the opposite and tilting it away, or moving it similarly to lowering it, should also do the opposite and allows you to crouch. The only missing control, using the fire flower power, it used with the light sensor, which is also the only possible control left. Covering the sensor and blocking light allows Mario to throw a fireball, almost like he is providing light now. If you were to have made this controller, what material(s) would you have used to build it.
Code:
#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Keyboard_da_DK.h>
#include <Keyboard_de_DE.h>
#include <Keyboard_es_ES.h>
#include <Keyboard_fr_FR.h>
#include <Keyboard_it_IT.h>
#include <Keyboard_sv_SE.h>

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

int lightReading = 0; // Measures from 0-1023

void setup()
{
  pinMode(A3, INPUT); // Light Sensor Connection

  pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLUP); // Use Right Button is Light Sensor isn't usable

  Keyboard.begin(); // Allow for Keyboard inputs with CPE

  Serial.begin(9600);
  CircuitPlayground.begin();
}

void loop()
{
  float x = CircuitPlayground.motionX(); // Left and Right Movement
  float y = CircuitPlayground.motionY(); // Jumping and Crouching Movement

  lightReading = analogRead(A3); // Light Level being Measured
 
  if(digitalRead(CPLAY_SLIDESWITCHPIN)) // Safty
  {
    // Move Right - Right Arrow
    if(x < -1.5)
    {
      Keyboard.press(KEY_RIGHT_ARROW);
      Serial.print("Right");
      Serial.print("\t");
    }
    else
    {
      Keyboard.release(KEY_RIGHT_ARROW);
    }

    // Move Left - Left Arrow
    if(x > 1.5)
    {
      Keyboard.press(KEY_LEFT_ARROW);
      Serial.print("Left");
      Serial.print("\t");
    }
    else
    {
      Keyboard.release(KEY_LEFT_ARROW);
    }

    // Crouch - Down Arrow
    if(y < -2.5)
    {
      Keyboard.press(KEY_DOWN_ARROW);
      Serial.print("Crouch");
      Serial.print("\t");
    }
    else
    {
      Keyboard.release(KEY_DOWN_ARROW);
    }

    // Jump - Up Arrow
    if(y > 1.5)
    {
      Keyboard.press(KEY_UP_ARROW);
      Serial.print("Jump");
      Serial.print("\t");
    }
    else
    {
      Keyboard.release(KEY_UP_ARROW);
    }

    //Fireball - Left Shift
    if(digitalRead(CPLAY_RIGHTBUTTON) | lightReading < 450)
    {
      Keyboard.press(KEY_LEFT_SHIFT);
      Serial.print("FIREBALL");
      Serial.print("\t");
    }
    else
    {
      Keyboard.release(KEY_LEFT_SHIFT);
    }
  }

  Serial.println("It's me, Mario!");
}
Video (link below if needed):
https://youtu.be/QaQcEwbcoKU

Schematic:






No comments:

Post a Comment

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