xxxxxxxxxx
125
var bgColor = 255;
var changeDir1 = false;
var aim = false;
var bullets = [];
//var shootY = 450;
function setup() {
createCanvas(700, 500);
obs1 = new Dropper(100, height / 2 + 50, 50, 60, 1);
shooter = new Shooter(width / 2 - 25, height, width / 2 + 25, height, width / 2, height - 50);
//bullet = new Bullet(shooter.cx, 450, 3, 15);
for (var i = 0; i < 10; i++) {
bullets[i] = new bullet();
//bullets[i].render();
}
}
function draw() {
background(bgColor);
obs1.move();
obs1.render();
// obs2.move();
// obs2.render();
shooter.render();
shooter.move();
//shooter.shoot();
for (var i = 0; i < bullets.length; i++) {
bullets[i].display();
}
}
function mousePressed() {
//bullet = new Bullet(shooter.cx, 450, 3, 15);
bullets.push(new bullet(shooter.cx, 450, 3, 15));
}
class Dropper {
constructor(x, y, w, h, s) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.s = s;
}
move() {
if (this.x > width - this.w) changeDir1 = true;
else if (this.x <= 0) changeDir1 = false;
if (this.x >= 0 && changeDir1 == false) this.x = this.x + this.s;
else if (changeDir1 == true) this.x = this.x - this.s;
}
render() {
fill('red');
rect(this.x, this.y, this.w, this.h);
}
}
class Shooter {
constructor(ax, ay, bx, by, cx, cy) {
this.ax = ax;
this.ay = ay;
this.bx = bx;
this.by = by;
this.cx = cx;
this.cy = cy;
}
render() {
triangle(this.ax, this.ay, this.bx, this.by, this.cx, this.cy);
}
move() {
if (keyIsDown(LEFT_ARROW)) {
this.ax -= 5;
this.bx -= 5;
this.cx -= 5;
}
if (keyIsDown(RIGHT_ARROW)) {
this.ax += 5;
this.bx += 5;
this.cx += 5;
}
}
// shoot() {
// if (mouseIsPressed) {
// rect(this.cx-1.5, shootY, 3, 15);
// shootY--;
// }
// }
}
function bullet(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.display = function () {
rect(this.x, this.y, this.w, this.h);
}
// shoot() {
// if (mouseIsPressed) this.y-=10;
// }
}