21 April 2021

Game controller project




For my controller I wanted to go for something simple yet effective. And I also chose a game with a simple yet fun controller scheme. I decided to use the game VVVVVV to showcase my game controller since the game only has 3 inputs. Simplicity was the key here and I wanted the game to fit the controller in a way. The game is simple in controls and graphics and my controller is just that, It labels the inputs you can preform at the zenith of the box, and when you tilt in one of the three directions, the tilt controls will activate, allowing you to game, just by tilting the box!

What should I add to make my box more fun to use?


CODE:

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>

#include <math.h>

#include <Keyboard.h>

//Made By Niles Garcia


//Variables

int lrGate = 5;

int fbGate = -5;

float lrTilt = 0;

float backTilt = 0;


void setup() {

    //Put your setup code here

    Serial.begin(9600);

    delay(9600);

    CircuitPlayground.begin();

    Keyboard.begin();

}

void loop() {



  //Motion Sensors

  lrTilt = CircuitPlayground.motionX();

  backTilt = CircuitPlayground.motionY();



  //Jump if tilting controller forward

   if(lrTilt > fbGate){

    Keyboard.press(' ');

  }

  else

    Keyboard.release(' ');  

  //If leaning right with controller, the character will move right

  if(lrTilt > lrGate){

    Keyboard.press('d');

    Serial.println("right");

  }

  else

    Keyboard.release('d');


  //If leaning left with controller, the character will move left

  if(lrTilt < -(lrGate)){

    Keyboard.press('a');

    Serial.println("left");

  }

  else

    Keyboard.release('a');

}

No comments:

Post a Comment

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