Animated App – Space Cannon

In Computational Media, ITP

For our week 2 assignment, we were tasked with creating an animated application in processing. I knew I wanted to create a sort game environment that I could eventually build off of once I developed my skills more. Space Cannon hopefully will be the foundation to a more robust game.


 

Version 1 – Space Cannon at peace

 

// Background variables
float rgbred = 20;
float rgbgreen = 50;
float rgbblue = 70;
float shade = .15;

// Ammo Variables
float ammospeed = 0;
float ammovariation = 1;
float ammosize = 4;
float ammoX;
float ammoY;
float startX;
float startY;

// Mouse Click Variables
boolean ammoactivated = false;

// Pshape variables
PShape spaceship, bubble, ship;

void setup() {
size(800, 600);

//Pshape – spaceship
spaceship = createShape(GROUP);
bubble = createShape(ARC, -10, -12, 20, 25, -PI, 0, CHORD);
ship = createShape(ELLIPSE, -25, -10, 50, 20);
spaceship.addChild(ship);
spaceship.addChild(bubble);
}

void draw() {

//Glowing Night Sky
background(rgbred, rgbgreen, rgbblue);

rgbred = rgbred – shade;
rgbgreen = rgbgreen – shade;
rgbblue = rgbblue – shade;

if (rgbred < 1 || rgbred > 25) {
shade = shade * -1;
}

//Star Dust

for (float dusty = 20; dusty < height; dusty = dusty + 20) {
for (float dustx = 20; dustx < width; dustx = dustx + 20) {
fill(250, 255, 221, random(100, 200));
stroke(0);
strokeWeight(1);
ellipse(dustx, dusty, 3, 3);
}
}

//Planet
ellipseMode(CENTER);
fill(163, 10, 10);
ellipse(701, 79, 30, 30);
noStroke();
fill(255, 0, 0);
ellipse(700, 80, 30, 30);
smooth();
stroke(249, 252, 0);
strokeWeight(3);
noFill();
arc(700, 80, 50, 10, radians(-50), radians(230));

//Ammo
ammoX = startX + ammospeed;
ammoY = startY ;

if (ammoactivated) {
ellipse (ammoX, ammoY, ammosize, ammosize);
ammospeed = ammospeed +12;
}

if (ammoX>800) {
ammoactivated = false;
ammoX = 0;
ammospeed = 0;
}

// Spaceship
translate(mouseX, mouseY);
bubble.setFill(color(202, 75, 195));
ship.setFill(color(107, 48, 188));
shape(spaceship);
}

void mouseClicked() {
ammoactivated = true;
//ammoX = 0;
ammospeed = 0;
startX = mouseX;
startY = mouseY;
}

space cannon at war

 

// Background variables
float rgbred = 20;
float rgbgreen = 50;
float rgbblue = 70;
float shade = .15;

//Ammo Variables
float ammospeed = 0;
float ammovariation = 1;
float ammosize = 4;
float ammoX;
float ammoY;
float startX;
float startY;

//Mouse Click Variables
boolean ammoactivated = false;

// Pshape variables
PShape spaceship, bubble, ship;

void setup() {
size(800, 600);

//Pshape – spaceship
spaceship = createShape(GROUP);
bubble = createShape(ARC, -10, -12, 20, 25, -PI, 0, CHORD);
ship = createShape(ELLIPSE, -25, -10, 50, 20);
spaceship.addChild(ship);
spaceship.addChild(bubble);
}

void draw() {

//Glowing Night Sky
background(rgbred, rgbgreen, rgbblue);

rgbred = rgbred – shade;
rgbgreen = rgbgreen – shade;
rgbblue = rgbblue – shade;

if (rgbred < 1 || rgbred > 25) {
shade = shade * -1;
}

//Star Dust

for (float dusty = 20; dusty < height; dusty = dusty + 20) {
for (float dustx = 20; dustx < width; dustx = dustx + 20) {
float positionX = random(-10, 10) + dustx;
float positionY = random(-10, 10) + dusty;
fill(250, 255, 221, random(100, 200));
stroke(0);
strokeWeight(1);
ellipse(positionX, positionY, 3, 3);
}
}

//Planet
ellipseMode(CENTER);
fill(163, 10, 10);
ellipse(701, 79, 30, 30);
noStroke();
fill(255, 0, 0);
ellipse(700, 80, 30, 30);
stroke(249, 252, 0);
strokeWeight(3);
noFill();
arc(700, 80, 50, 10, radians(-50), radians(230));

//Ammo
ammoX = startX + ammospeed;
ammoY = startY ;

if (ammoactivated) {
ellipse (ammoX, ammoY, ammosize, ammosize);
ammospeed = ammospeed +12;
}

if (ammoX>800) {
ammoactivated = false;
ammoX = 0;
ammospeed = 0;
}

// Spaceship
translate(mouseX, mouseY);
bubble.setFill(color(202, 75, 195));
ship.setFill(color(107, 48, 188));
shape(spaceship);
}

void mouseClicked() {
ammoactivated = true;
ammoX = 0;
ammospeed = 0;
startX = mouseX;
startY = mouseY;
}

 

Submit a comment