added return variables from class
This commit is contained in:
@@ -49,6 +49,8 @@ class bullet {
|
|||||||
this.targety = targety;
|
this.targety = targety;
|
||||||
this.projectile.add(p5.Vector.mult(this.direction, this.speed));
|
this.projectile.add(p5.Vector.mult(this.direction, this.speed));
|
||||||
|
|
||||||
|
let hit = false;
|
||||||
|
let shot = true;
|
||||||
|
|
||||||
if (dist(this.projectile.x, this.projectile.y, this.targetx, this.targety) <= this.radius) {
|
if (dist(this.projectile.x, this.projectile.y, this.targetx, this.targety) <= this.radius) {
|
||||||
hit = true;
|
hit = true;
|
||||||
@@ -58,7 +60,8 @@ class bullet {
|
|||||||
bounceY = this.projectile.y;
|
bounceY = this.projectile.y;
|
||||||
shot = false;
|
shot = false;
|
||||||
}
|
}
|
||||||
|
return { hit, shot };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -73,7 +73,8 @@ let playerPosY = 300;
|
|||||||
let bullets = [];
|
let bullets = [];
|
||||||
let playerSpeed = 5;
|
let playerSpeed = 5;
|
||||||
let radius = 40;
|
let radius = 40;
|
||||||
|
let hit = false;
|
||||||
|
let shot = true;
|
||||||
async function Movementloop() {
|
async function Movementloop() {
|
||||||
if (booleanArray[1]) {
|
if (booleanArray[1]) {
|
||||||
playerPosX += 2;}
|
playerPosX += 2;}
|
||||||
@@ -117,9 +118,17 @@ function draw(){
|
|||||||
// clear the background with a transparent black color
|
// clear the background with a transparent black color
|
||||||
background(0,0,0,100);
|
background(0,0,0,100);
|
||||||
myBullet.draw();
|
myBullet.draw();
|
||||||
myBullet.update(playerPosX, playerPosY);
|
let { hit, shot } = myBullet.update(playerPosX, playerPosY);
|
||||||
// draw a circle at the mouse position
|
// draw a circle at the mouse position
|
||||||
circle(playerPosX, playerPosY, radius);
|
circle(playerPosX, playerPosY, radius);
|
||||||
|
if (hit) {
|
||||||
|
console.log("player hit");
|
||||||
|
}
|
||||||
|
if (!shot) {
|
||||||
|
console.log("player shot");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//test
|
//test
|
||||||
//test2
|
//test2
|
Reference in New Issue
Block a user