Laser Shooting Game (Star Wars) © GPL3+

This laser shooting game is a simple project with target characters from Star Wars movie.

  • 6,226 views
  • 9 comments
  • 24 respects

Components and supplies

About this project

In this article I will share Arduino-based Star Wars project that you can make on a budget. This project is a laser shooting game that will suit you as a homemade product. This project consists of 2 sub projects: making the blaster from cardboard and building the target board. I use recording module to use for the blaster sound effect and all target boards have an photoresistors and servo motors.

1. Hardware and Materials Required

9v Battery: https://amzn.to/366Kklr

Push Button: https://amzn.to/39ueCR5

Jumper Wires: https://amzn.to/37kTL0M

Male DC Barrel Jack Adapter for Arduino : https://amzn.to/35cDCcc

9v battery: https://amzn.to/2wPmnSP

Push Button: https://amzn.to/2I2lA3s

Jumper wires: https://amzn.to/398mQhq

Male DC Barrel Jack Adapter for Arduino : https://amzn.to/2VwyKxx

Micro Servo 9g : https://amzn.to/38bLtrY

9v Battery Clip Connector : https://amzn.to/32D4R0b

Cardboard : https://amzn.to/39ufbKH

Recording Module : https://amzn.to/2T746Jr

Red Dot Laser Pointer: https://amzn.to/39deipA

AA Batteries : https://amzn.to/37m9JHX

4 x 1.5 V AA Battery Holder: https://amzn.to/2MFXSwu

3 x 1.5 V AA Battery Holder : https://amzn.to/398ET6Y

LCD Module : https://amzn.to/2vqz8mA

Male Header Pins : https://amzn.to/2QB1f91

Natural Wood Craft Sticks : https://amzn.to/39rovPs

2. Making The Blaster

The Glie-44 was blaster pistol that was carried many Resistance members in Star Wars movie, including General Leia Organa and the pilot Poe Dameron. I made this blaster using image from google search. Print the image on paper, this will us to trace the main body and details onto cardboard. Cut out the image with scissors. Once done, trace it onto the cardboard.

I used recording module for the blaster sound effect. By pressing the record button on the module and play star wars blaster sound effect on my phone at the same time, I was able to load the sound the sound onto module. After that all electronics need to be assembled according to wiring diagram. Put the electronics into the blaster, when the momentary switch is pressed the gun shoots out a pulse of red LED light and a blaster sound is triggered.

3. Prepare The Targets

I used Palpatine image, and Red stormtroopers images as targets. I got images from google search and then printed the images on piece of paper. You can cut out the images and stick it on carboard by glue. Each target has photoresistor and each of them will need a hole that will allow sensor to be inserted. Targets will need servos to be attached to its side (glue will do just fine). I also added LCD display to display score and timer.

4. Progam The Arduino

It's now time to program the arduino and test it out.

Download the code and transfer it over to the Arduino. Don’t forget to install LCD library and servo library.

5. Have Fun

Try pointing the blaster at photoresistor, shooting photoresistor triggers servo and target board falls flat. If you shoot Palpatine, you get 5 points. If you shoot Red Stormtroopers, you only get 1 point. You can change things in the arduino program as well. If you are still having issues, let me know in the comments and I might be able to help you. REMEMBER, DON’T POINT LASER IN ANYONE’ EYES!

Code

Laser Shooting GameArduino
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define TOT_TARGETS 4
#define TOT_SENSORS 4
#define PIN_TARGET 7


Servo Targets[TOT_TARGETS];  //Servo
int targetSensor[] = {A0, A1, A2, A3};  // LDR Sensor
int readingSensor[TOT_SENSORS];
int targetTimer[] = {0, 0, 0, 0}; 
int score = 0;
int timer = 100;
unsigned long interval = 100; // the time we need to wait
unsigned long previousMillis = 0; // millis() returns an unsigned long.

void setup() {
  Serial.begin(9600);

  lcd.backlight();
  lcd.clear();
  lcd.begin();
  lcd.setCursor(0, 0);
  lcd.print("SCORE: 0");
  lcd.setCursor(0, 1);
  lcd.print("TIMER: 0");

  //attaches the servos from pin 7 to 10
  for (int targetNumber = 0; targetNumber < TOT_TARGETS; targetNumber++)
  {
    Targets[targetNumber].attach(targetNumber + PIN_TARGET);
    Targets[targetNumber].write(0);
  }
}

void loop() {

  lcd.clear();
  lcd.setCursor(0, 0);  //(Column,Row)
  lcd.print("SCORE: ");
  lcd.setCursor(12, 0);
  lcd.print(score);
  lcd.setCursor(0, 1);  //(Column,Row)
  lcd.print("TIME: ");
  lcd.setCursor(12, 1);
  lcd.print(timer);

  unsigned long currentMillis = millis(); // grab current time

  // check if "interval" time has passed (100 milliseconds)
  if ((unsigned long)(currentMillis - previousMillis) >= interval) {

    for (int targetsensorNumber = 0; targetsensorNumber < TOT_SENSORS; targetsensorNumber++) {
      readingSensor[targetsensorNumber] = analogRead({(targetSensor[targetsensorNumber])});
    }
    previousMillis = millis();
    Serial.print(readingSensor[1]);
    Serial.println(readingSensor[2]);
  }
  villainTarget();
  targetDown();
  ifZero();
  Countdowntimer();
  
}

void villainTarget() {

  int target = random(1, 5);
  delay(10);
  if (target == 1) {
    targetTimer[0]++;
    Targets[0].write(90);
    delay(10);
    if (targetTimer[0] == 2) {
      targetTimer[0] = 0;
      Targets[0].write(0);
      delay(10);
    }
  } else if (target == 2) {
    targetTimer[1]++;
    Targets[1].write(90);
    delay(10);
    if (targetTimer[1] == 2) {
      targetTimer[1] = 0;
      Targets[1].write(0);
      delay(10);
    }

  } else if (target == 3) {
    targetTimer[2]++;
    Targets[2].write(90);
    delay(10);
    if (targetTimer[2] == 2) {
      targetTimer[2] = 0;
      Targets[2].write(0);
      delay(10);
    }
  } else if (target == 4) {
    targetTimer[3]++;
    Targets[3].write(90);
    delay(10);
    if (targetTimer[3] == 2) {
      targetTimer[3] = 0;
      Targets[3].write(0);
      delay(10);
    }
  }
}

void targetDown() {
  //Sith Trooper
  if (readingSensor[0] > 450) {
    score++;
    Targets[0].write(0);
    delay(100);
  }
  //Sith Trooper
  if (readingSensor[1] > 990) {
    score++;
    Targets[1].write(1);
    delay(100);
  }
  // Palpatine
  if (readingSensor[2] > 990) {
    score = score + 5;
    Targets[2].write(2);
    delay(100);
  }
  //Sith Trooper
  if (readingSensor[3] > 985) {
    score++;
    Targets[3].write(3);
    delay(100);
  }
}


void Countdowntimer() {
  timer--;
  delay(1000);
}

void ifZero() {
  if (timer == 0) {
    for (int targetNumber = 0; targetNumber < TOT_TARGETS; targetNumber++)
    {
      Targets[targetNumber].write(0);
    }
    lcd.clear();
    lcd.print(" YOUR SCORE: ");
    lcd.setCursor(12, 0);
    lcd.print(score);
    delay(10000);
    score=0;
    timer = 100;
  }
}

Schematics

Target Wiring Diagram
Target wiring diagram irkuuhvidz
Blaster Pistol Wiring Diagram
Blaster pistol wiring diagram ipywjsqm9h

Comments

Similar projects you might like

Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

  • 10,680 views
  • 8 comments
  • 28 respects

Arduino Mkr1000 and Java Swing Shooting Game

Project tutorial by pc1436

  • 1,305 views
  • 0 comments
  • 4 respects

Arduino Game By LCD

Project tutorial by Mohammed Magdy

  • 62,068 views
  • 57 comments
  • 196 respects

Arduino Touch Tic-Tac-Toe Game

Project tutorial by Nick Koumaris

  • 34,297 views
  • 23 comments
  • 59 respects

Arduino Pong Game - OLED Display

Project tutorial by Nick Koumaris

  • 12,297 views
  • 2 comments
  • 22 respects

2.4" Touchscreen with Retro Game Replicas

Project in progress by I.T

  • 5,851 views
  • 11 comments
  • 18 respects
Add projectSign up / Login