trying to shoot out projectiles (not working)
This commit is contained in:
31
web/game.js
31
web/game.js
@@ -75,15 +75,18 @@ const height = 600;
|
|||||||
let Playerposx = 500;
|
let Playerposx = 500;
|
||||||
let Playerposy = 300;
|
let Playerposy = 300;
|
||||||
const playerSize = 10;
|
const playerSize = 10;
|
||||||
radius = playerSize/2;
|
let radius = playerSize/2;
|
||||||
playerX = 500
|
let playerX = 500
|
||||||
playerY = 300;
|
let playerY = 300;
|
||||||
playerSpeed = 3;
|
let playerSpeed = 3;
|
||||||
|
|
||||||
|
|
||||||
squareX = 100;
|
let squareX = 100;
|
||||||
squareY = 100;
|
let squareY = 100;
|
||||||
const squareSize = 100;
|
const squareSize = 100;
|
||||||
|
let startPosX;
|
||||||
|
let startPosY;
|
||||||
|
let shotSpeed = 5;
|
||||||
|
|
||||||
// the function setup() is called once when the page is loaded
|
// the function setup() is called once when the page is loaded
|
||||||
function setup() {
|
function setup() {
|
||||||
@@ -110,7 +113,6 @@ function keyPressed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function Movementloop() {
|
async function Movementloop() {
|
||||||
if (booleanArray[1]) {
|
if (booleanArray[1]) {
|
||||||
playerX += playerSpeed;}
|
playerX += playerSpeed;}
|
||||||
@@ -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
|
// the function draw() is called every frame
|
||||||
function draw() {
|
function draw() {
|
||||||
keyPressed();
|
keyPressed();
|
||||||
// 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);
|
||||||
|
shoot(500,100);
|
||||||
|
|
||||||
// draw a circle at the mouse position
|
// draw a circle at the mouse position
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user