Data Types

Table of Contents



Numbers

I utilized numeric data types such as integers and floating-point decimals to initialize physics variables. These values are updated every frame to calculate the player’s downward velocity and gravity.

// Physics variables
    this.vy = 0;
    this.gravity = 0.5;
    this.isGrounded = false;



Strings

Handled string data types for text manipulation and asset pathing.

this.titleElement.innerHTML = "LEVEL 2: THE CHASE";

Did string concatenation by combining a dynamic environment variable with a static file path string

src: gameEnv.path + "/images/projects/red-riding/chase.png",



Booleans

Implemented boolean data types as state flags. These true/false flags track binary conditions in the game logic, such as checking if the player is currently touching the floor or preventing duplicate score submissions.

this.wonGame = true;
this.isGrounded = true;
this.scoreSubmitted = true;     



Arrays

Managed linear collections of data using arrays. The code stores a sequence of coordinate maps and uses array operations.

const cookiePositions = [{ x: 0.1, y: 0.8 }, { x: 0.3, y: 0.75 }, { x: 0.5, y: 0.8 }, { x: 0.7, y: 0.75 }, { x: 0.9, y: 0.8 }];

Utilized an empty array literal (centerPoints) to dynamically build a tracking path for the Wolf

sampleSpline(controlPoints, numSamples) {
      const samples = [];
      const maxT = controlPoints.length - 1;
      for (let i = 0; i <= numSamples; i++) {
          samples.push(this.getSplinePoint((i / numSamples) * maxT, controlPoints));
      }
      return samples;
  }



Objects (JSON)

Utilized JavaScript object literals, structured identically to JSON, to act as configuration dictionaries. This groups mixed data types.

const sprite_data_wolf = {
      id: 'Wolf',
      src: gameEnv.path + "/images/projects/red-riding/wolfff.png",
      SCALE_FACTOR: 3.5,
      STEP_FACTOR: 1000,
      ANIMATION_RATE: 8,
}: