projectile dissapears after hit (doesn't return)
This commit is contained in:
16
web/game.js
16
web/game.js
@@ -142,7 +142,6 @@ async function Movementloop() {
|
|||||||
|
|
||||||
function shoot(directionX, directionY) {
|
function shoot(directionX, directionY) {
|
||||||
shot = true;
|
shot = true;
|
||||||
circle(500, 100, 50);
|
|
||||||
|
|
||||||
if (!projectile) {
|
if (!projectile) {
|
||||||
// Set the initial position of the projectile to the player's position
|
// Set the initial position of the projectile to the player's position
|
||||||
@@ -159,16 +158,31 @@ function shoot(directionX, directionY) {
|
|||||||
direction.normalize();
|
direction.normalize();
|
||||||
direction.mult(shotSpeed);
|
direction.mult(shotSpeed);
|
||||||
projectile.add(direction);
|
projectile.add(direction);
|
||||||
|
|
||||||
|
if (projectile.dist(target) >= 1) {
|
||||||
|
shot = false;
|
||||||
|
// projectile = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the function draw() is called every frame
|
// the function draw() is called every frame
|
||||||
function draw() {
|
function draw() {
|
||||||
keyPressed();
|
keyPressed();
|
||||||
|
// draw background
|
||||||
background(0, 0, 0, 100);
|
background(0, 0, 0, 100);
|
||||||
|
|
||||||
|
// draw player
|
||||||
|
fill(0, 255, 255)
|
||||||
circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
|
circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
|
||||||
|
|
||||||
|
// draw boss
|
||||||
|
fill(255,165,0)
|
||||||
|
circle(500, 100, 50);
|
||||||
|
|
||||||
// square(squareX,squareY,squareSize);
|
// square(squareX,squareY,squareSize);
|
||||||
// object_collision();
|
// object_collision();
|
||||||
|
|
||||||
|
if (shot == false) {
|
||||||
shoot(playerPosX, playerPosY);
|
shoot(playerPosX, playerPosY);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user