Kalam Warriorz _ An Interactive gaming experience

Published Jul 25, 2020
 2 hours to build
 Intermediate

An interactive and immersive (like real-life) game where the movements of the person (walk, run, jump, power activation) in real world are used to control the game's hero on screen. During this alien escapade, Dr.Kalam will help us throughout by supplying power-ups and health-packs. An interesting fitness motivator, a healthy time-pass and an inclusive gaming experience(for specially abled too) that would improve healthy lifestyle by increasing physical activity in this digital age.

display image

Components Used

Arduino Nano
Arduino Nano
1
Wire
Hook-up Wire 788133 RED 100 FT
1
Cardboard and Metal Foils
Used for building the "Motion Tracking Pad" which detects the movements of the person, including walking, running and jumping. Also activates power-ups and other boosters
1
Description

 

Building the Project

           Time to get our hands dirty by building stuff and writing codes. We won't use sensors, modules or other boards except for the Arduino. We are going to develop our own sensors/controls and display the game using the processing window. 

                                                Motion Tracking Pad ---> Arduino ---> Processing

 

1) Motion Tracking Pad (using cardboard and metal foils):

Detects the player's motion in real-world including detection of walking, running, jumping, bending down to control the hero's movements, and standing on the left/right leg for power-up activation. The Motion Tracking Pad is nothing but a combination of self-made pressure sensors using Cardboard and metal-foils. Let's start building it.

Steps :

  • Placement of metallic strips (take from metal foils/ metal cups/ chocolate wrappers/ wires, etc) and cardboards to make Motion Tracking Pads using custom-made low-cost pressure sensors.
  • Place the small cardboard sides containing metal foils against the larger cardboard piece by following the instructions given below.

        

             Wow....CONGRATS !!! We just built our own "Motion Tracking Pad". 

 

2) Connecting the Motion Tracking Pad with Arduino :

Let's proceed now.... Motion Tracking Pad is connected to Arduino for detection of movement and Arduino then conveys this detection message to the processing software which is used for building the game. Detection of movement is done by sensing the pattern inactivation of self-made pressure sensors in Motion Tracking Pad. Here is the pin-out diagram for the same;

Left Leg Tracking Pad --> Digital Pin 12     Right Leg Tracking Pad --> Digital Pin 13    Hand Tracking Pad --> Digital Pin 8

 

3) Coding in Arduino :

Arduino is a microcontroller development board used extensively by developers to build projects quickly. Hope you already have your Arduino IDE installed and have done the basic projects like Blink, etc. If not, click on the following link to download and use Arduino on your computer. Also, try doing the LED Blink project to understand how to work with Arduino.

Download Arduino : https://www.arduino.cc/en/main/software

Blink Example : https://www.arduino.cc/en/tutorial/blink

Ok... let us continue on with our project now! Now that we have the Motion Tracking Pad wired up to the Arduino in the previous step, let's connect Arduino to our computer and start coding it. Refer Arduino code given in the attachments. 

// Gets data from the Motion Tracking Pad
// Commnicates the following data to Processing software
// jump --> data=0
// crouching down --> data=30
// walking/running --> data=10
// standing on left leg --> data=70 --> activate powerup
// standing on right leg --> data=90 --> create your own powerup and add 
// standing --> data=100

int val1=0;
int val2=0;

void setup() 
{ 
  Serial.begin(9600);  
  pinMode(12, INPUT_PULLUP); // Left leg pad is connected to digital pin 12
  pinMode(13, INPUT_PULLUP); // Right leg pad is connected to digital pin 13
  pinMode(8, INPUT_PULLUP); // Hand pad is connected to digital pin 8
} 
 
void loop() { 

  // val=0-->Switch on,  val=1-->Switch off
  int val_1 = digitalRead(12); 
  int val_2 = digitalRead(13);
  int val_3 = digitalRead(8);  

  if ((val_1 != val1) || (val_2 != val2))
  {
    if (val_1 != val1) 
    {
      Serial.write(10);
      delay(100);
    }
    val1 = val_1;
  
    if (val_2 != val2) 
    {
      Serial.write(10);
      delay(100);
    }
    val2 = val_2;
  }
  else
  {
    if ( val_3==0) //duck down to avoid head obstacles
    {
      Serial.write(30);
    }
    else if (val_1==1 && val_2==1) //jump
    {
      Serial.write(0);
    }
    else if (val_1==0 && val_2==0) //stand
    {
      Serial.write(100);
      //Serial.println(100);
    }
    else if (val_1==1 && val_2==0) //standing on left leg
    {
      Serial.write(70);
    }
    else if (val_1==0 && val_2==1) //standing on right leg
    {
      Serial.write(90);
    }
  }

delay(100);

}

         PHEWWW.... We have completed the sensing and detecting parts of our project. Only one step ahead!

 

4) Coding in Processing :

Our Input controls and movement detection system are in place. Also, we have implemented the program in Arduino to gather movement data from the Motion Tracking Pad.

Processing is a visual design based software. Arduino and Processing have a similar implementation in terms of coding used. Click on the following link to download and use Processing on your computer.

https://processing.org/download/

Here, we have to convey the movement data recorded by Motion Tracking Pad using Arduino by sending it to the Processing software. Now we need to create the game in processing and move the hero based on the movement of players in the real world. Refer to the Processing code given in the attachments. The images and sound files used in the processing program are also attached along with it. 

import processing.serial.*; //library for serial communication
import processing.sound.*;  //library for using sound files

//Creating variables for images and sound files
PImage up;
PImage down;
PImage jump;
PImage fight;

PImage groundalien;
PImage ufo;

SoundFile power_catch;
SoundFile health_catch;
SoundFile jumping;
SoundFile GameOver;
SoundFile crying;
SoundFile air_hit;
SoundFile super_jump;

int a =0;

float ax = 1500; //air obstacle position
float av = 2;  //air obstacle velocity

float gx = 2000; //ground obstacle position
float gv = 10;  //ground obstacle velocity

float px = 3000; //px ==> pos of Power-ups
float hx = 8000; //hx ==> pos of Health Pack
int state = 0; //state ==> 0:stand, 1:walk, 2:crouch down, 3:jump

float health = 100; //Initial and Maximum health
int health_boost = 20; //Amount of Health increased each time healthpack is captured
float score = 0; //score of player

int game_flag=0; //if game flag==1 --> GAME OVER
int jump_flag = 0; 
int power_flag = 0;
int c = -1;

int yi= 200; //stores vertical position of the hero.. making him fly

int power = 0; //stores the powerups. maximum is 5

Serial port;  // port is variable that stores
int val;      // Data received from the serial port 

void setup()
{
  size(1200,800); //size(width,height).. for size of screen
  
  //establishing connection between Processing and Arduino
  String portName1 = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  port = new Serial(this, portName1, 9600);
  
  //loading the images used in the game. Thanks GOOGLE for giving links to those images.
  //If you need to use different images of your choice, add them in data folder and change the images here
  up = loadImage("deadpool.jpg"); 
  down = loadImage("deadpool2.png");
  jump = loadImage("deadpool3.jpg");
  fight = loadImage("deadpool5.jpg");
  groundalien = loadImage("alien1.jpg");
  ufo = loadImage("ufo.jpg");
  
  //loading the sounds used in the game.
  // SOUND CREDITS : zapsplat.com
  //If you need to use different sounds of your choice, add them in data folder and change the name of sound files here
  power_catch= new SoundFile(this, "power.mpg");
  health_catch= new SoundFile(this, "health_pack.mpg");
  jumping= new SoundFile(this, "jump.mpg");
  GameOver= new SoundFile(this, "game_over.mpg");
  crying= new SoundFile(this, "crying.mpg");
  air_hit= new SoundFile(this, "hit.mpg");
  super_jump= new SoundFile(this, "super_jump.mpg");
}

void draw()
{
  
  
  if (game_flag==0) // when game_flag=0 --> GAME OVER
  {
  if (0 < port.available())       // If data is available
  {  
    val = port.read();            // read it and store it in val
  }
  
  // val=0 --> jump
  // val=10 --> walking/running
  // val=30 --> crouching down
  // val=70(standing on left leg) --> activate powerup
  // val=90(standing on right leg) --> create your own powerup and add
  // val=100 --> standing
  
  canvas();
  
  if (val==100 && power_flag==0) //hero standing on both legs
  {
    hero_up();
  }
  
  // lie down to avoid flying obstacle
  if (val==30 && power_flag==0)
  {
  canvas();
  state = 2;
  hero_down();
  }
  
  // jump to avoid ground obstacles
  if (val==0 && power_flag==0)
  {
  canvas();
  state = 3;
  hero_jump();
  }
  
  // walking
  if (val==10 && power_flag==0)
  {
  canvas();
  state = 1;
  hero_walking();
  air_obstacles();
  ground_obstacles();
  }
  
  // activating the powerup 
  if (val==70 && (power>0) && (power_flag==0))
  {
    super_jump.play();
    power--;
    delay(500);
    jump_flag = 1;
    power_flag=1;
  }
  if ( yi>220 || (jump_flag == 1 && val!=70))
    {
     jump_flag=0;
     power_flag=0;
     yi=200;
     c=-c;
    }
  if (yi>180 && jump_flag == 1 && val==70)
  {
    fill(255,0,0);
    circle(100,100,100);
  }
  if (yi>=0 && jump_flag == 1 && val==70)
  {
    superjump();
  } 
  else if (yi<0 && jump_flag==1 && val==70)
  {
    c=-c;
    superjump();
  }
  
  // creating powerups and healthpacks
  // ... and making them available on screen at regular intervals
  powerups();
  healthpack();
  
  air_obstacles();
  fill(0); 
  
  //displaying obstacles on the screen
  image(ufo, ax, 360, ufo.width/1.5, ufo.height/1.5); //image(img, x-position, y-position, width, height)
  image(groundalien, gx, 510, groundalien.width/2, groundalien.height/2);
  
  //displaying Score, Health, Powerups
  data_display();
  
  if (health<0)
    game_over();
  }
}

// HERO MOVEMENTS ---------------------------------------------------------------------------------------------
void hero_up() //standing
{
  image(up, 100, 400, up.width, up.height);
}

void hero_down() //crouching down
{
  image(down, 100, 490, down.width/2.5, down.height/2.5);
}

void hero_jump() //jumping
{
  image(jump, 100, 200, jump.width/2, jump.height/2);
  
  gx = gx-20;
}

void hero_walking() //walking, running 
{
  image(up, 100, 380, up.width, up.height);
  score = score + 5;
}

// BACKGROUND -------------------------------------------------------------------------------------------------
void canvas()
{
  background(255);
  fill(50,255,120);
  rect(0,400+up.height,width,height);
} 

// AIR OBSTACLES : FLYING UFO ---------------------------------------------------------------------------------
void air_obstacles()
{
  //fill(0);
  //rect(ax,400,100,100);
  image(ufo, ax, 360, ufo.width/1.5, ufo.height/1.5);
  ax=ax-av;
  
  if ((ax<-200))
  {
    ax = random(2500,3000);
    av = random(1,5);
  }
  
  if ((ax>=0 && ax<=300) && state!=2)
  {
    health= health-1;
    air_hit.play();
  }
}

// GROUND OBSTACLES : ALIENS -----------------------------------------------------------------------------------
void ground_obstacles()
{
  //fill(0);
  //rect(gx,530,100,100);
  image(groundalien, gx, 510, groundalien.width/2, groundalien.height/2);
  gx=gx-gv;
  
  if ((gx<-200)&&(abs(gx-ax)>=300))
  {
    gx = random(1000,1500);
    gv = random(5,7);
  }
  
  if ((gx>=0 && gx<=200) && state!=3)
  {
    health= health-1;
    air_hit.play();
  }
}

// POWERUPS ----------------------------------------------------------------------------------------------------
void powerups()
{ 
  fill(251, 255, 0);
  circle(px,400,60);
  px=px-10;
  
  //when power_up goes out of screen or is taken, it is made available again after sometime
  if (px<-200)
    px = random(4000,6000); 
  if ((px>=0 && px<=400) && state==3)
  {
    px = random(10000,15000);
    fill(0);
    if (power<5)
    {
      power = power+1;
      power_catch.play();
    }
  }
}

// SUPERPOWERS -------------------------------------------------------------------------------------------------
void super_freeze()
{
  delay(3000);
  fill(0,0,255);
  circle(100,100,100);
  delay(1000);
}

void superjump()
{
  image(jump, 100, yi, jump.width/2, jump.height/2);
  yi=yi+c;
  gx = gx-10;
  state =2;
  score = score + 10;
}

// HEALTH BOOSTER -----------------------------------------------------------------------------------------------
void healthpack()
{
  fill(251, 0, 0);
  circle(hx,400,60);
  hx=hx-10; //health pack position (hx) is made to move 10 pixels in every frame... speed is 10 pixels
  
  //when health_pack goes out of screen or is taken, it is made available again after sometime
  if (hx<-200)
    hx = random(8000,10000);
  if ((hx>=0 && hx<=400) && state==3) 
  {
    health_catch.play();      //music for getting health boost
    hx = random(10000,15000); //generates a random starting position for health pack
    health = health+health_boost;
  }
  if (health>100) //Max health = 100
    health=100;
}

// SCORE AND HEALTH DISPLAY -------------------------------------------------------------------------------------
void data_display()
{
  textSize(32);
  text("Health: ", 800, 120); //displaying health bar
  if(health>=50)
    fill(0,255,0);
  else
    fill(255,0,0);
  
  rect(930,80,health*2, 50);
  fill(0, 102, 153);
  
  text("Score: "+score, 800, 60); //displaying score
  
  fill(255,0,0);
  rect(800,150,350,60);
  fill(251, 255, 0);
  int dpx = 830;
  for (int i=0; i<power; i++) //displaying powerup circles 
  {
    circle(dpx,180,50);
    dpx = dpx+70;
  }
}

// GAME OVER and DISPLAY BOARD------------------------------------------------------------------------------------
void game_over()
{
  background(0,255, 0);
  textSize(150);
  fill(255,0,0);
  text("GAME OVER",200,150);
  textSize(100);
  fill(0);
  text("Score: "+score, 100, 350);
  text("Time: "+(millis()/1000), 100, 450);
  if(score<=10000)
    text("WEAK",200,650);
  else if(score>=10000 && score<=20000)
    text("GOOD",200,650);
  else if(score>=20000 && score<=30000)
    text("MR.STRONG",200,650);
  else
    text("BAILWAAN",200,650);
  game_flag=1;     // game over
  GameOver.play(); // playing bgm 
  crying.play();
}

Don't worry if you can't open .mpg sound files attached directly. When you use them in the program it works fine, because that format is acceptable in processing software.          

           HURRAY !!! We have done with the gaming interface too... What's next? 

           Time for us to power our project and start playinggg....

 

5) Connecting Arduino to the computer :

Now that you have everything set up, let's connect Arduino to the computer using USB Cable. 

Time to have someeee funnnn !!!!

 

Testing :

          I tested this game with my friends and neighborhood kids.  Here are their names and the classes they are studying in;

  • Daniel       -   UKG std
  • Jerishna   -    3rd std
  • Rakesh     -   4th std
  • Jaden       -   6th std
  • Jerishan   -   6th std

Below is the image of the scoreboard and suggestions that I got from them. Use these to improve this idea if you are interested.

Feed-backs and Score-Board

 

Previous version :

          Here is the actual version of the game "Kalam Warriorz" whose Motion Tracking Pad I built with Plywood. I made this game and played it along with one of my friends who was visually challenged. Although it is the first version of the game, it consists of a good storyline too. It had 2 superheroes; one ground hero and the flying hero. 

Some additional features :

  • Visually challenged friendly interface.
  • Flying hero: Controlled by my visually challenged friend using Light Dependent Resistor(LDR). Closing LDR will prevent light from falling on it --> Arduino detects it --> makes the flying hero move UP. He gets to know of flying obstacles using a vibrator which starts vibrating when the flying hero is in the path of an obstacle.
  • The health of both ground and flying heroes is updated using the RED, GREEN and BLUE LED's.
  • The storyline with Dr.Abdul Kalam as the mentor and the players as heroes.

 

Scope for Improvement :

  • Adaption for the Specially abled: At present, there are no proper sources of digital entertainment for the visually challenged and specially-abled. By adding vibrators we could alert the visually challenged kid using vibrations whenever the alien comes near so that he could get the sense of the game and could play on his own.
  • Learning: Kids retain a huge chunk of knowledge when they study their subjects with interest and gaming/playing is the activity that interests almost all kids. With adaptations, small chunks of learning material can be displayed along with the game flow. For eg; Certain power-ups could be achieved when the kid answers a question correctly.
  • Fitness: Redefining fitness by motivating children to play the game, which in turn would indirectly enable them to pursue healthy practices like exercises because they have to jump, crouch down, jog and stand on one leg during the course of the game.
Codes

Downloads

pinout Download
Comments
Ad