xxxxxxxxxx
252
let ratio = 1/2;
let rec;
const FRAMES = 1000;
const FPS = 60;
function setup() {
const canvas = createCanvas(800*ratio, 800);
frameRate(FPS);
rec = setupRecording("AJ Rocket", canvas, FRAMES, {
avi: {
fps: FPS,
quality: 0.92,
}
});
reset();
}
let x;
let y;
let MissleStarty = y;
let circ = [];
let enemies = [];
let numberofe = 5;
let ded = false;
let stars;
function reset() {
x = 800*ratio/2;
y = 1000;
enemies = [];
circ = [];
stars = [];
doneFrame = null;
const count = 11;
for (let i=0; i<count; i++) {
const fract = i / count;
let r1 = sin(fract * TAU) * 150 + width / 2;
let yr = fract * 700 - 725;
//add variable E enemies to enemies list
enemies.push({ x: r1, y: yr });
}
const starCount = 50;
for (let i=0; i<starCount; i++) {
stars.push({
x: random() * width,
y: random() * height
});
}
frameCount = 0; // reset time
starAlpha = 0;
}
let starAlpha = 0;
function draw() {
background("black");
strokeWeight(3);
strokeJoin(ROUND);
if (doneFrame)
starAlpha > 0 && (starAlpha -= 0.01);
else
starAlpha < 1 && (starAlpha += 0.01);
fill(255,255,255,starAlpha * 255);
noStroke();
stars.forEach(star => {
star.y = (star.y + 0.5) % height;
circle(star.x, star.y, 2);
});
stroke(s_aP());
// Strive.drawTickAxes()
for (let i = 0; i < enemies.length; i++) {
fill(s_aR());
rect(enemies[i].x - 25, enemies[i].y - 25, 50, 50);
enemies[i].y += 2;
}
push()
// circle(x + 50, MissleStarty, 10);
// circle(x + 50, MissleStarty, 10);
fill(s_aB());
rect(x + 20, y - 40, 7, 30);
rect(x + 75, y - 40, 7, 30);
fill(0, 255, 255);
circle(x + 50, y + 10, 100);
fill(s_aB());
circle(x + 50, y + 10, 70);
fill(s_aO());
rect(x, y, 100);
fill(s_aG());
triangle(x, y + 100, x, y + 70, x + 25, y + 100);
triangle(x + 100, y + 100, x + 100, y + 70, x + 75, y + 100);
triangle(x, y, x, y + 25, x + 25, y);
triangle(x + 100, y, x + 75, y, x + 100, y + 25);
fill(s_aR());
// triangle(x, y + 100, x, y + 30, x - 25, y + 125);
// bezier(x, y + 100, x, y + 30, x + 30, y + 125, x - 30, y + 125);
beginShape();
curveVertex(x, y + 100);
curveVertex(x, y + 30);
curveVertex(x - 15, y + 35);
curveVertex(x - 25, y + 120);
endShape(CLOSE);
beginShape();
curveVertex(x + 100, y + 100);
curveVertex(x + 100, y + 30);
curveVertex(x + 100 + 15, y + 35);
curveVertex(x + 100 + 25, y + 120);
endShape(CLOSE);
// triangle(x + 100, y + 100, x + 100, y + 30, x + 125, y + 125);
fill(s_aP());
beginShape();
curveVertex(x, y + 100);
curveVertex(x, y + 30);
curveVertex(x - 5, y + 35);
curveVertex(x - 15, y + 100);
endShape(CLOSE);
beginShape();
curveVertex(x + 100, y + 100);
curveVertex(x + 100, y + 30);
curveVertex(x + 100 + 5, y + 35);
curveVertex(x + 100 + 15, y + 100);
endShape(CLOSE);
// triangle(x, y + 100, x, y + 25, x - 15, y + 110);
// triangle(x + 100, y + 100, x + 100, y + 25, x + 115, y + 110);
circle(x + 50, y + 50, 75);
fill(s_aR());
circle(x + 50, y + 50, 50);
pop()
if (keyIsPressed && frameCount % 5 == 0) {
if (key === "n") {
circ.push({ x: x+20 , y: y });
}
if (key === "m") {
circ.push({ x: x + 80, y: y });
}
}
if (circ) {
for (let i = 0; i < circ.length; i++) {
i % 2 == 0 ? fill(255, 223, 0) : fill(0, 255, 255);
circle(circ[i].x, circ[i].y - 48, 10);
circ[i].y -= 7;
enemies.forEach(enemy => {
const dist = sqrt(pow(enemy.x - circ[i].x, 2) + pow(enemy.y - circ[i].y, 2));
if (dist < 50) {
circ[i].dead = true;
enemy.dead = true;
}
});
if (circ[i].y > height)
circ[i].dead = true;
}
// for (let i = 0; i < circ.length; i++) {
// fill(0, 255, 255);
// circle(circ[i].x, circ[i].y - 48, 15);
// circ[i].y -= 7;
// }
}
enemies = enemies.filter(e => !e.dead);
circ = circ.filter(e => !e.dead);
if (doneFrame) {
const t = (frameCount - doneFrame) / 50;
const path = lerp((cos(t * TAU * 1) - 1) * 3, pow(t, 3), t);
y -= path;
if (t >= 3) {
reset();
if (rec.recording)
rec.stop();
}
} else {
if (y > 600)
y += (600 - y) * 0.1;
if(enemies.length == 0)
doneFrame = frameCount;
}
if (keyIsPressed == true) {
if (key === "ArrowDown") {
y += 4;
}
if (key === "ArrowUp") {
y -= 4;
}
if (key === "ArrowRight") {
x += 4;
}
if (key === "ArrowLeft") {
x -= 4;
}
}
if (rec.recording) rec.recordFrame();
}
let doneFrame;
function keyPressed() {
if (keyCode == 77 || keyCode == 78) {
}
if (ded) {
}
if (key == "Enter") {
// if (!rec.recording) {
// rec.start();
// reset();
// } else rec.stop();
saveCanvas();
}
}
function preload() {
pewpew = loadSound(
"https://assets.codepen.io/5720103/Laser+Gun+Sound+Effect.mp3"
);
dedsound = loadSound(
"https://assets.codepen.io/5720103/Zombie+Death++Sound+Effect.mp3"
);
backgroundSound = loadSound(
"https://assets.codepen.io/5720103/deepSpace.mp3"
);
shipdeath = loadSound(
"https://assets.codepen.io/5720103/444670__tissman__death.wav"
);
}