18 April 2022

Game Controller

 


Binding of Isaac Alternate Controller



Description:

The game I chose to make a controller for is a popular rogue like game that I have enjoyed for many years called Binding of Isaac. In this game you move your character with WASD, fire your weapon with all 4 of the arrow keys, hit "E" to place bombs and "Q' to use items. Understanding these inputs I linked them to the accelerometer of the Circuit Playground Express. With the CPE being attached to the full controller all you have to do is move the controller by leaning it around forward, backward, left, and right to move your character and to attack. Then whenever you need to use a bomb or and item you can hit the physical buttons on the CPE with the left being bound to E and the right to Q. When it came to figuring out how to map each input in a simple to use yet effective manner I found using the accelerometer for both movement and to fire the projectiles at the same time. This simultaneous movement and firing feels the most similar to how the game feels like to play normally. Since moving to dodge and stay alive is more important than doing damage, this influenced the design by having it focus on the movement and having the firing as a secondary issue. The best question I can ask for peer review help is in figuring out a better system that allows the user to move and fire at the same time with little to no delay to allow for dodging and staying alive due to the difficulty of the game.

Schematic:


 Code:

// By William Correa Espitia
#include <Keyboard.h>
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>

void setup() 
{
  CircuitPlayground.begin();
  pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN); // button A
  pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN); // button B
  Keyboard.begin();
}

void loop() 
{
  float y = CircuitPlayground.motionY();
  float x = CircuitPlayground.motionX();
  Serial.println(y);
  Serial.print(x);

 //BINDS THE LEFT BUTTON TO Q
  if(digitalRead(CPLAY_LEFTBUTTON)) {
    Keyboard.write('Q');
    delay(100);
  }
 //BINDS THE RIGHT BUTTON TO E
  if(digitalRead(CPLAY_RIGHTBUTTON)) {
    Keyboard.write('E');
    delay(100);
  }

   //BINDS BOTH S AND DOWN ARROW TO LEANING THE ACCELEROMETER BACK
    if (y >= 5)
  {
    Keyboard.press('s');
    Keyboard.press(KEY_DOWN_ARROW);
  }

 //BINDS BOTH W AND UP ARROW TO LEANING THE ACCELEROMETER FORWARD
  if (y <= -2)
  {
    Keyboard.press('w');
    Keyboard.press(KEY_UP_ARROW);  
  }
  
 //BINDS BOTH D AND RIGHT ARROW TO LEANING THE ACCELEROMETER TO THE RIGHT
  if(x <= -5)
  {
    Keyboard.press('d');
    Keyboard.press(KEY_RIGHT_ARROW);
  }
  
 //BINDS BOTH A AND LEFT ARROW TO LEANING THE ACCELEROMETER TO THE LEFT
  if(x >= 5)
  {
    Keyboard.press('a');
    Keyboard.press(KEY_LEFT_ARROW);
  }
  
  //RELEASES THE KEYS SO THEY CAN BE INPUT AGAIN
  if ((y > -2) && (y < 5))
  {
    Keyboard.release('w');
    Keyboard.release('s');
    Keyboard.release(KEY_UP_ARROW);
    Keyboard.release(KEY_DOWN_ARROW);
  }

  //RELEASES THE KEYS SO THEY CAN BE INPUT AGAIN
  if ((x > -5) && (x < 5))
  {
    Keyboard.release('a');
    Keyboard.release('d');
    Keyboard.release(KEY_LEFT_ARROW);
    Keyboard.release(KEY_RIGHT_ARROW);
  }
}


No comments:

Post a Comment

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