changed player variables

This commit is contained in:
Mees Roelofsz
2023-11-25 16:33:52 +01:00
parent 70bc9f14d5
commit 9d33b5b855

View File

@@ -67,16 +67,20 @@ async function disconnect() {
console.log("Port is closed!");
}
//--------------------Game--------------------
let Playerposx = 500;
let Playerposy = 300;
const size = 10;
radius = size/2;
cirX = 500
cirY = 300;
// Game variables
const width = 1000;
const height = 600;
speed = 3;
// Player variables
let Playerposx = 500;
let Playerposy = 300;
const playerSize = 10;
radius = playerSize/2;
playerX = 500
playerY = 300;
playerSpeed = 3;
squareX = 100;
squareY = 100;
const squareSize = 100;
@@ -92,37 +96,37 @@ function setup() {
}
function keyPressed() {
if (keyIsDown(LEFT_ARROW) && cirX > 0+radius) {
cirX -= speed;
if (keyIsDown(LEFT_ARROW) && playerX > 0+radius) {
playerX -= playerSpeed;
}
if (keyIsDown(RIGHT_ARROW) && cirX < width-radius) {
cirX += speed;
if (keyIsDown(RIGHT_ARROW) && playerX < width-radius) {
playerX += playerSpeed;
}
if (keyIsDown(UP_ARROW) && cirY > 0+radius) {
cirY -= speed;
if (keyIsDown(UP_ARROW) && playerY > 0+radius) {
playerY -= playerSpeed;
}
if (keyIsDown(DOWN_ARROW) && cirY < height-radius) {
cirY += speed;
if (keyIsDown(DOWN_ARROW) && playerY < height-radius) {
playerY += playerSpeed;
}
}
async function Movementloop() {
if (booleanArray[1]) {
cirX += speed;}
playerX += playerSpeed;}
if (booleanArray[3]) {
cirX -= speed;}
playerX -= playerSpeed;}
if (booleanArray[2]) {
cirY += speed;}
playerY += playerSpeed;}
if (booleanArray[0]) {
cirY -= speed;}
playerY -= playerSpeed;}
}
function object_collision() {
var squareCenterX = squareX + squareSize / 2;
var squareCenterY = squareY + squareSize / 2;
var distance = dist(cirX, cirY, squareCenterX, squareCenterY);
var distance = dist(playerX, playerY, squareCenterX, squareCenterY);
if (distance < squareSize / 2 + radius) {
squareX = random(0, width - squareSize);
@@ -138,7 +142,7 @@ function draw() {
// draw a circle at the mouse position
circle(constrain(cirX,0+radius,width-radius), constrain(cirY,0+radius,height-radius), size);
circle(constrain(playerX,0+radius,width-radius), constrain(playerY,0+radius,height-radius), playerSize);
square(squareX,squareY,squareSize);
object_collision();
}