trying to shoot out projectiles (not working)
This commit is contained in:
33
web/game.js
33
web/game.js
@@ -75,15 +75,18 @@ const height = 600;
|
||||
let Playerposx = 500;
|
||||
let Playerposy = 300;
|
||||
const playerSize = 10;
|
||||
radius = playerSize/2;
|
||||
playerX = 500
|
||||
playerY = 300;
|
||||
playerSpeed = 3;
|
||||
let radius = playerSize/2;
|
||||
let playerX = 500
|
||||
let playerY = 300;
|
||||
let playerSpeed = 3;
|
||||
|
||||
|
||||
squareX = 100;
|
||||
squareY = 100;
|
||||
let squareX = 100;
|
||||
let squareY = 100;
|
||||
const squareSize = 100;
|
||||
let startPosX;
|
||||
let startPosY;
|
||||
let shotSpeed = 5;
|
||||
|
||||
// the function setup() is called once when the page is loaded
|
||||
function setup() {
|
||||
@@ -110,7 +113,6 @@ function keyPressed() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function Movementloop() {
|
||||
if (booleanArray[1]) {
|
||||
playerX += playerSpeed;}
|
||||
@@ -120,7 +122,7 @@ async function Movementloop() {
|
||||
playerY += playerSpeed;}
|
||||
if (booleanArray[0]) {
|
||||
playerY -= playerSpeed;}
|
||||
}
|
||||
}
|
||||
|
||||
function object_collision() {
|
||||
var squareCenterX = squareX + squareSize / 2;
|
||||
@@ -134,11 +136,26 @@ function object_collision() {
|
||||
}
|
||||
}
|
||||
|
||||
async function shoot(startPosX, startPosY) {
|
||||
circle(startPosX, startPosY, 30);
|
||||
let shootingCirclePos = createVector(startPosX, startPosY);
|
||||
let targetCirclePos = createVector(playerX, playerY);
|
||||
|
||||
let direction = p5.Vector.sub(targetCirclePos, shootingCirclePos);
|
||||
direction.normalize();
|
||||
direction.mult(shotSpeed);
|
||||
|
||||
shootingCirclePos.add(direction);
|
||||
|
||||
circle(shootingCirclePos.x, shootingCirclePos.y, 5);
|
||||
}
|
||||
|
||||
// the function draw() is called every frame
|
||||
function draw() {
|
||||
keyPressed();
|
||||
// clear the background with a transparent black color
|
||||
background(0, 0, 0, 100);
|
||||
shoot(500,100);
|
||||
|
||||
// draw a circle at the mouse position
|
||||
|
||||
|
Reference in New Issue
Block a user