17 April 2022

Kingdom: New Lands Project

 





My game controller is “Kingdom Reins” which allows you to control your lord or lady in the indie hit Kingdom where you ride on a 2D plane, building up your domain’s defenses and population by strategically spending gold coins.


The conceptual model of my game is that the player is guiding the horse in-game in real life via the reins. The input is by pulling the reins left and right and up and down, which moves a platform containing the CPE on a set of hinges inside my enclosure. The CPE interprets this movement via the accelerometer X and Y. For example, pulling the reins right moves the character right, left moves the character left, and holding the reins up drops coins or pays for buildings. The only signifier is the reins protruding from the enclosure which gives the player the mental concept of using them as the only means of control. The only feedback is from the game itself, which displays how the player moves based on their control of the reins. 


I’m not entirely satisfied by how the reins movement translates to in-game movement, because of the nature of the accelerometer, the only way I could figure out to input where the reins were to the CPE was via pulling them like a puppet on a string to orient the CPE and then read its tilted value. Are there any other ways I could have incorporated the reins programming-wise or design-wise to make it read solely off of pulling the reins right, left, up or down?


#include <Keyboard.h>

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>

#include <math.h>


void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  CircuitPlayground.begin();

}


void loop() {

  // put your main code here, to run repeatedly:

       //read accelerometer x & y

  float x = CircuitPlayground.motionX();

  float y = CircuitPlayground.motionY();


  Serial.print("x");

  Serial.println(x);

  Serial.print("y");

  Serial.println(y);

 //input the keyboard based off of the accelerometers

  if (y > 1)

  {

    Keyboard.write('S');

  }

  

  if (x < -4)

  {

    Keyboard.write('A');

  }


  if(x > 4)

  {

    Keyboard.write('D');

  }

   




}


No comments:

Post a Comment

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