const debug = false; const cellSize = 40; const halfCellSize = cellSize / 2; const rows = Math.floor(window.innerHeight / cellSize - 1); const cols = Math.floor(window.innerWidth / cellSize - 1); const ypx = rows * cellSize; const xpx = cols * cellSize; const bombDelay = 1500; const expodeDelay = 500; const nextBombTime = 500; //const overlappedBorder = -Math.floor(halfCellSize); // px const gameFrameRate = 60; const steppOnStart = 1; const yOffsetDraw = cellSize - cellSize / 4; const offsetCollision = cellSize / 4; const grid = []; // grid[iy][ix] const explodeSize = 2; const softItemRandomFactor = 0.8; const hardItemRandomFactor = 0.95; const softItem = 2; const hardItem = 3; const freePlace = 0; const enemies = []; const damping = 2; const enemiSpeed = 4; const snapBomb = false; let explosionSound; var socket; function setup() { socket = io.connect('http://localhost:3000'); createCanvas(windowWidth, windowHeight); //createCanvas(cols * cellSize, rows * cellSize); explosionSound = loadSound("sound/explosion.mp3"); frameRate(gameFrameRate); // Attempt to refresh at starting FPS for (let iy = 0; iy < rows; iy++) { const row = []; for (let ix = 0; ix < cols; ix++) { rect(ix * cellSize, iy * cellSize, cellSize); if (Math.random() > softItemRandomFactor) { row.push(softItem); // push soft item //text("🌿", ix * cellSize, iy * cellSize + cellSize - cellSize / 4); } else if (Math.random() > hardItemRandomFactor) { row.push(hardItem); } else { row.push(freePlace); } } grid.push(row); } grid.push([]); // add one free row // put player on free place let randPosition; // proc nelze deklarovat uvnitr while??? do { player1.x = (Math.floor(Math.random() * cols) * cellSize) + cellSize / 2; player1.y = (Math.floor(Math.random() * rows) * cellSize) + cellSize / 2; randPosition = positionsToCellsIdx({ x: player1.x, y: player1.y, }); console.log(randPosition); } while (grid[randPosition.yi][randPosition.xi] !== freePlace); // put enemy on free place let enemi = { x: 0, y: 0 }; do { enemi.x = (Math.floor(Math.random() * cols) * cellSize) + cellSize / 2; enemi.y = (Math.floor(Math.random() * rows) * cellSize) + cellSize / 2; randPosition = positionsToCellsIdx({ x: enemi.x, y: enemi.y, }); console.log(randPosition); } while (grid[randPosition.yi][randPosition.xi] !== freePlace); enemies.push(makeEnemy(enemi.x, enemi.y)); } function draw() { background(0, 255); fill(0, 90, 255); textSize(cellSize / 1.2); for (let iy = 0; iy < rows; iy++) { for (let ix = 0; ix < cols; ix++) { rect(ix * cellSize, iy * cellSize, cellSize); text(iy, ix); if (grid[iy][ix] === softItem) { text("🌿", ix * cellSize, iy * cellSize + yOffsetDraw); } else if (grid[iy][ix] === hardItem) { text("🪨", ix * cellSize, iy * cellSize + yOffsetDraw); } } } //debugger; // draw bomb drawBombs(); detonateBomb(); drawExplosions(); // draw movePlayer(); moveEnemies(); drawPlayer(); drawEnemies(); }