changed player variables
This commit is contained in:
48
web/game.js
48
web/game.js
@@ -67,16 +67,20 @@ async function disconnect() {
|
|||||||
console.log("Port is closed!");
|
console.log("Port is closed!");
|
||||||
}
|
}
|
||||||
//--------------------Game--------------------
|
//--------------------Game--------------------
|
||||||
|
// Game variables
|
||||||
let Playerposx = 500;
|
|
||||||
let Playerposy = 300;
|
|
||||||
const size = 10;
|
|
||||||
radius = size/2;
|
|
||||||
cirX = 500
|
|
||||||
cirY = 300;
|
|
||||||
const width = 1000;
|
const width = 1000;
|
||||||
const height = 600;
|
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;
|
squareX = 100;
|
||||||
squareY = 100;
|
squareY = 100;
|
||||||
const squareSize = 100;
|
const squareSize = 100;
|
||||||
@@ -92,37 +96,37 @@ function setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function keyPressed() {
|
function keyPressed() {
|
||||||
if (keyIsDown(LEFT_ARROW) && cirX > 0+radius) {
|
if (keyIsDown(LEFT_ARROW) && playerX > 0+radius) {
|
||||||
cirX -= speed;
|
playerX -= playerSpeed;
|
||||||
}
|
}
|
||||||
if (keyIsDown(RIGHT_ARROW) && cirX < width-radius) {
|
if (keyIsDown(RIGHT_ARROW) && playerX < width-radius) {
|
||||||
cirX += speed;
|
playerX += playerSpeed;
|
||||||
}
|
}
|
||||||
if (keyIsDown(UP_ARROW) && cirY > 0+radius) {
|
if (keyIsDown(UP_ARROW) && playerY > 0+radius) {
|
||||||
cirY -= speed;
|
playerY -= playerSpeed;
|
||||||
}
|
}
|
||||||
if (keyIsDown(DOWN_ARROW) && cirY < height-radius) {
|
if (keyIsDown(DOWN_ARROW) && playerY < height-radius) {
|
||||||
cirY += speed;
|
playerY += playerSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function Movementloop() {
|
async function Movementloop() {
|
||||||
if (booleanArray[1]) {
|
if (booleanArray[1]) {
|
||||||
cirX += speed;}
|
playerX += playerSpeed;}
|
||||||
if (booleanArray[3]) {
|
if (booleanArray[3]) {
|
||||||
cirX -= speed;}
|
playerX -= playerSpeed;}
|
||||||
if (booleanArray[2]) {
|
if (booleanArray[2]) {
|
||||||
cirY += speed;}
|
playerY += playerSpeed;}
|
||||||
if (booleanArray[0]) {
|
if (booleanArray[0]) {
|
||||||
cirY -= speed;}
|
playerY -= playerSpeed;}
|
||||||
}
|
}
|
||||||
|
|
||||||
function object_collision() {
|
function object_collision() {
|
||||||
var squareCenterX = squareX + squareSize / 2;
|
var squareCenterX = squareX + squareSize / 2;
|
||||||
var squareCenterY = squareY + 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) {
|
if (distance < squareSize / 2 + radius) {
|
||||||
squareX = random(0, width - squareSize);
|
squareX = random(0, width - squareSize);
|
||||||
@@ -138,7 +142,7 @@ function draw() {
|
|||||||
|
|
||||||
// draw a circle at the mouse position
|
// 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);
|
square(squareX,squareY,squareSize);
|
||||||
object_collision();
|
object_collision();
|
||||||
}
|
}
|
Reference in New Issue
Block a user