[UPDATED] Refined Final Project Idea + Progress

Last time I spoke in class, I was very much set on the idea of making a “big brother” surveillance camera. BUT, I realized that I would require a few equipments that are not in our sparkfun arduino kit. These equipments included a set of female jump wires, a separate breadboard(?) that can be attached to the servo, and another type of converter looking wire that I forgot the name of. Due to these technical difficulties, I thought my surveillance camera would become boring to the audience and so I decided to switch to a different idea.

Therefore, I resorted to my initial idea, which was to make a “spacewar” game. It is a game in which a spaceship (player) defends objects falling towards the earth from the outer-space. This has always been one of my favorite games since childhood and I loved the idea that I could realize it on my own.

Space War X on the App Store

I am currently in the process of developing the processing part first. I will get to the arduino once I have a working version on my computer. The arduino part will be incorporated with a push buttons to shoot shrapnels/bullets, another push button to accelerate, and a potentiometer to maneuver left and right directions.

I have accomplished my first milestone which is to have the starship maneuver and shoot bullets. I am not entirely sure if I am satisfied with the sprite that I am using, so this is subject to change. Below I have attached the video of the working version of my first milestone and the codes.

/*
David Lee
Main Code - version w/o arduino
*/

ArrayList <Bullet> bullets; 
Player player; 
PImage starship;

boolean [] keys = new boolean[128];


void setup(){
  size(480, 640);
  bullets = new ArrayList();
  player = new Player();
  starship = loadImage("starship6.png");
}

void draw() {
  background(0);
  for(Bullet temp : bullets){
    temp.move();
  }
  for(Bullet temp : bullets){
    temp.display(); 
  }
  //removeToLimit(30);
  
  player.display();
  player.move();
}


void keyPressed(){
  keys[keyCode] = true;
  if(keys[32]){
     Bullet temp = new Bullet(player.pos.x+80, player.pos.y);
     bullets.add(temp);
  }
}

void keyReleased(){
  keys[keyCode] = false;
}

void removeToLimit(int maxLength){
    while(bullets.size() > maxLength){
       bullets.remove(0); 
    }
  }
//Bullet Class

class Bullet{
  PVector pos;
  PVector acc;
  PVector vel;
  
  Bullet(float tx, float ty){
     pos = new PVector(tx, ty);
     acc = new PVector(0,-0.2);
     vel = new PVector(0, -2.5);
  }
  
  void display(){
     stroke(255);
     //point(x, y);
     rect(pos.x, pos.y, 3, 10);
  }
  
  void move(){
    vel.add(acc);
    pos.add(vel);
     //pos.y -= 2.5;
    
  }
}
//Player Class

class Player{
  PVector pos;
  PVector acc;
  PVector vel;
  
  Player(){
    pos = new PVector(width/2, height - 100);
    acc = new PVector(0.0, 0);
    vel = new PVector(4,4);
  }
  
  void display(){
    image(starship, pos.x, pos.y); 
  }
  
  
  void move(){
    vel = vel.add(acc);
    if(keys[LEFT])
      pos.x -= vel.x;
    if(keys[RIGHT])
      pos.x += vel.x;
    if(keys[UP])
      pos.y -= vel.y;
    if(keys[DOWN])
      pos.y += vel.y;
      
    if(pos.x < -50){
      pos.x = width; 
    }
    if(pos.x > width){
      pos.x = -50;  
    }
    if(pos.y > height){
      pos.y = -59; 
    }
    if(pos.y < -59){
      pos.y = height; 
    }
  }
}

 

Leave a Reply