18 April 2021

Game Controller: Orb of Zot

 




The Description:

The Orb of Zot game controller idea for the Dungeon Crawl Stone Soup game originated from the final winning “mcguffin” you needed to acquire after exploring the dungeon and to win the game, the Orb of Zot. I modeled the controller off of it to give a conceptual connection to the game itself and allow players to feel powerful using it to interact and control a character on their own quest to get the “Orb”. I wanted to do a full orb but decided it would be difficult for the player to hold and play at the same time. The Orb contains five interactive sensors that allow the player to move around and interact with the game world. There is a potentiometer that sticks out of the side of the Orb and allows the player to determine the orientation of their character before using the hole in the top of the Orb to trip the light sensor. This confirms the player's choice and begins moving them in the character in the chosen direction. The orientation determined by the potentiometer was determined by the amount of resistance and was marked on the side of the Orb and an arrow on the potentiometer to make it easier for the player. If the player tapped the side of the Orb, their character would rest and recover their health after a fight. If the player is standing over a staircase when they lift and tilt the Orb, it triggers the tilt sensor (which is bound to the > key) and the character descends a level to continue exploring the dungeon and searching for the Orb of Zot.


My question is, does this concept seem entertaining and engaging enough to learn to play the game this way instead of with a keyboard?


The Schematic:




The Video:



The Code:

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

#define SAMPLE   5  // Sample window for average level
#define INPUT_FLOOR     0  // Lower range of mic sensitivity in dB SPL
#define INPUT_CEILING  110  // Upper range of mic sensitivity in db SPL
#define TILT A0

const int debounce = 200;
int fAcing;
boolean moving = false;
boolean Rest = true;

boolean wEst = false;
boolean eAst = false;
boolean nOrth = false;
boolean sOuth = false;

void setup(){
  CircuitPlayground.begin();
  //put your setup code here, to run once:
  pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN);  //BUTTON A
  Keyboard.begin();
  //https://www.arduino.cc/en/Reference/KeyboardModifiers
}

void loop(){
  // put main code here, runs repeatedly:
  //mapping item pickup(g key) to the left button being pressed
  if(digitalRead(CPLAY_LEFTBUTTON)){
    Keyboard.write('5');
    delay(debounce);
  }


  //function to use light to actually move character
  Move();

  //calling function to determine direction
  DirectionFaced();

  //mapping downstairs use(> key) to a tilt switch so you have to tilt to go down stairs
  int TILT_VALUE = digitalRead(TILT);
  //if box is turned verticle or on it's side
  if (TILT_VALUE == HIGH){
    Keyboard.write('>');
    delay(debounce); 
  }

  float m = 0; //peak level
  //read microphone and get loadest level over sample window
  m = CircuitPlayground.mic.soundPressureLevel(SAMPLE);
  
  //limit to floor value
  m = max(INPUT_FLOOR, m);
  
    if(m >= 70 && Rest == false){
      Keyboard.write('5');
      delay (1000);
      Rest = true;
    }
   else{
//      Serial.print("Can't rest here");
      delay (debounce);
      Rest = false;
   }


  Serial.println(m);
  Serial.println("\t");
//  Serial.println(Rest);
  Serial.print("\t");
  Serial.println(analogRead(A2));
}

//using the potentiometer as arrow keys to determine character facing
void DirectionFaced(){
  int pot = analogRead(A2);
  //turned to right around 90 degrees from south(0)
  while(eAst == false && (pot > 800 && pot < 1000) ){
      //Keyboard.write(215);
      fAcing = 215;
      delay (debounce);
      eAst = true;
      wEst = false;
      sOuth = false;
      nOrth = false;
      }
  //turned to right around 270 degrees from south(0)
  while(wEst == false && (pot > 300 && pot < 500)){
      //Keyboard.write(216);
      fAcing = 216;
      delay (debounce);
      wEst = true;
      eAst = false;
      sOuth = false;
      nOrth = false;
      }
  //turned all the way to the left(0)
  while(sOuth == false && (pot > 0 && pot < 200)){
      //Keyboard.write(217);
      fAcing = 217;
      delay (debounce);
      wEst = false;
      eAst = false;
      sOuth = true;
      nOrth = false;
      }
  //turned to right around 180 degrees from south(0)   
  while(nOrth == false && (pot > 600 && pot < 800)){
      //Keyboard.write(218);
      fAcing = 218;
      delay (debounce);
      wEst = false;
      eAst = false;
      sOuth = false;
      nOrth = true;
      }
}

//function to only allow character movement when there is enough light
void Move(){
//read an analog sensor - light
  int light = analogRead(A8);
  if(light >= 50){
  Keyboard.write(fAcing);
  delay (debounce);
  moving = true;
  }
  else{
  moving = false;
  }
}

No comments:

Post a Comment

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