27 November 2023

Cookie Clicker: The Cookie Controller Edition


Cookie Clicker The Controller Edition!

So the conceptual model for the design was that I wanted to make a cookie for the controller as it would be almost comedic to be playing the game cookie clicker whilst using a cookie controller that is the overall idea for the model of the controller. For the input to output mapping we have where the mostly 1:1 movement controls with moving the controller in any which direction will move the cursor in said direction, also with the clicking of the cursor you go from broken cookie to full cookie which allows for no click or to click. So for the signifiers and feedback we have the signifier that for the game itself has a full cookie, and when we have our full cookie together we can click our cursor allowing for that feedback of oh when I have the cookie together it will click and when broken/pulled apart there will be no clicking as is intended. So this gives the affordances that when the cookie looks like the cookie onscreen it will click and give benefits to the player and when broken it will give nothing to the player, also for movements sake when you move the cookie controller any which way it moves that direction so overall the player should understand when moving that the cursor will move that direction. For my question to yall, what would you have done differently about the model of the controller, it feels lackluster to me.






 

#include <Adafruit_CircuitPlayground.h>

#include <Mouse.h>

// values to adjust the sensitivity and speed of the mouse.
// X axis
#define XACCEL_MIN 0.5      // Minimum range of X axis acceleration
#define XACCEL_MAX 4.0      // Maximum range of X axis acceleration
#define XMOUSE_RANGE 20.0   // Range of velocity for mouse movements
#define XMOUSE_SCALE 1      // Scaling value to apply to mouse movement

// Y axis
#define YACCEL_MIN XACCEL_MIN
#define YACCEL_MAX XACCEL_MAX
#define YMOUSE_RANGE XMOUSE_RANGE
#define YMOUSE_SCALE 1

// Set this true to flip the mouse X/Y axis with the board X/Y axis
#define FLIP_AXES true


// linear interpolation function that is used to transform
// each axis of acceleration to mouse velocity/speed. Linear_interpolation
float lerp
(float x, float x0, float x1, float y0, float y1) {
  // Check if the input value (x) is outside its desired range
    if (x <= x0) {
    return y0;
  }
  else if (x >= x1) {
    return y1;
  }
  return y0 + (y1-y0)*((x-x0)/(x1-x0));
}
const int pResistor = A0;

int value;

void setup() {
  // Initialize Circuit Playground library.
  CircuitPlayground.begin();
  // Initialize Arduino mouse library.
  Mouse.begin();
  pinMode(pResistor, INPUT);
  Serial.begin(9600);
  delay(1000);
}

void loop() {
  // Check if the slide switch is enabled (on +) and if not then just exit out, run the loop again
  if (!CircuitPlayground.slideSwitch()) {
    return;
  }

  value = analogRead(pResistor);
  Serial.println(value);
  if (value < 500){
    Mouse.click();
  }
  else{
    Mouse.release();
  }

  // Grab x, y acceleration values
  float x = CircuitPlayground.motionX();
  float y = CircuitPlayground.motionY();
  // Use the magnitude of acceleration to interpolate the mouse velocity.
  float x_mag = abs(x);
  float x_mouse = lerp(x_mag, XACCEL_MIN, XACCEL_MAX, 0.0, XMOUSE_RANGE);
  float y_mag = abs(y);
  float y_mouse = lerp(y_mag, YACCEL_MIN, YACCEL_MAX, 0.0, YMOUSE_RANGE);
  // Change the mouse direction based on the direction of the acceleration.
  if (x < 0) {
    x_mouse *= -1.0;
  }
  if (y < 0) {
    y_mouse *= -1.0;
  }
  // Apply any global scaling to the axis (to flip it for example) and truncate
  // to an integer value.
  x_mouse = floor(x_mouse*XMOUSE_SCALE);
  y_mouse = floor(y_mouse*YMOUSE_SCALE);

  // Move mouse.
  if (!FLIP_AXES) {
    // Non-flipped axes, just map board X/Y to mouse X/Y.
    Mouse.move((int)x_mouse, (int)y_mouse, 0);
  }
  else {
    // Flipped axes, swap them around.
    Mouse.move((int)y_mouse, (int)x_mouse, 0);
  }

  // Small delay to wait for button state changes and slow down processing a bit.
  delay(10);
}

No comments:

Post a Comment

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