17 April 2022

Game Controller: Downwell

    I chose to make my controller for a game called Downwell. I choose Downwell because it has very

simple controls, but requires a decent level of skill to get past the first few levels. I chose to model

my controller after the gun modules that you can find in the game that allow you to change the

shooting style of your gun boots. Downwell only has four actions that can be done with only three

inputs. Left and Right movement have been mapped to the x-axis of the accelerometer with the tilt

value being mapped to a range of -1 to 1, -1 being left tilt, 1 being right tilt, and 0 meaning the

controller is centered or level. The jumping and shooting actions are mapped to the light sensor on

the CPE and I cut a peep hole over the sensor to allow light to hit it. I then set a light level of 0 to

trigger the jump/shoot actions so that when the peep hole is covered it functions like pressing a button.

After playtesting the controller I actually found it to be quite responsive and I was able to play the

game almost as well as I could with the keyboard after only a few minutes. I think the tilt movement

adds a slight challenge without creating frustration.


My question is how could I have better fit the theme of the game, should I have used a different

design or different controls?



Code:

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

const int debounce = 50;

void setup() {
  CircuitPlayground.begin();
  Serial.begin(9600);
  delay(1000);
}

void loop() {
  float x = CircuitPlayground.motionX(); // Reads x axis tilt and stores it as a float.
  int input = map(x, -10, 10, 1, -2);  //map x axis to value between 1 and 3
   
  float light = CircuitPlayground.lightSensor(); // Reads light level and stores it as a float

  if(input < 0){             // if x axis is less than 0, meaning if tilting left
    Keyboard.release('d');   //make sure "right" button is unpressed
    Keyboard.press('a');     //press "left" button to move left
    delay(debounce);
  } else if (input > 0){     // if x axis is greater than 0, meaning if tilting right
    Keyboard.release('a');   //make sure "left" button is unpressed
    Keyboard.press('d');     //press "right" button to move right
    delay(debounce);
  } else  {                  //otherwise controller is centered
    Keyboard.release('a');   //so release both "left
    Keyboard.release('d');   //and right
  }

  if(light == 0 ){           // if there is no light, meaning the peep hole is covered
    Keyboard.press(' ');     // press space to jump/shoot
    delay(debounce);
  }  else {                  // if light is any other value
    Keyboard.release(' ');   // release space to stop jumping/shooting
  }
    
  delay(100);
}




No comments:

Post a Comment

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