xxxxxxxxxx
97
// https://openprocessing.org/sketch/2035935
let player, walls, env_solid, env_overlay;
let grid, tiles, num_rows, num_cols, cell_size;
let entities;
let spd = 2;
let MAX_W, MAX_H;
let bgcolor, fgcolor;
let flipperL, flipperR, ball;
let bounds;
function setup() {
new Canvas(800, 600);
world.gravity.y = 9.8;
world.allowSleeping = true;
bgcolor = 20;
fgcolor = 220;
background(bgcolor);
bounds = new Sprite([[0,-height/2],[width,-height/2],[width,height],[0,height],[0,-height/2]]);
bounds.color = bgcolor;
bounds.stroke = fgcolor;
bounds.collider = 'static';
flipperL = new Sprite([[20,60],[200,140],[450,180],[480,60]]);
flipperL.collider = 'kinematic';
flipperL.offset.x = -40;
player = new Sprite(40, 10, 20); //cell_size*2, cell_size*2, cell_size, cell_size);
player.color = fgcolor;
player.stroke = bgcolor;
// player.diameter = cell_size;
// player.textColor = fgcolor;
player.bounciness = 0.5;
camera.zoom = 0.5;
frameRate(60);
// player.collides(tiles, tile_collide);
player.score = 0;
}
// function tile_collide(player, tile) {
// // console.log("bonk");
// tile.color = color(random(255),random(255),random(255));
// player.score++;
// }
function draw() {
background(bgcolor);
// if (keyIsDown(74) || keyIsDown(83) || keyIsDown(DOWN_ARROW)) {
// player.vel.y += spd;
// player.vel.y = constrain(player.vel.y, -1, 1);
// }
// if (keyIsDown(75) || keyIsDown(87) || keyIsDown(UP_ARROW)) {
// player.vel.y -= spd;
// }
// if (keyIsDown(72) || keyIsDown(65) || keyIsDown(LEFT_ARROW)) {
// player.vel.x -= spd;
// }
// if (keyIsDown(76) || keyIsDown(68) || keyIsDown(RIGHT_ARROW)) {
// player.vel.x += spd;
// }
// camera.x = player.x;
// camera.y = player.y;
renderStats();
fill(220);
noStroke();
text(`Score: ${player.score}`, 10, height-24);
}
function keyPressed() {
if (key == "a") {
flipperL.rotateTo(-90,5);
}
if (key == " ") saveGif("peglin-rl.gif", 10);
// if (key == "l") player.x += cell_size;
// if (key == "h") player.x -= cell_size;
// if (key == "k") player.y -= cell_size;
// if (key == "j") player.y += cell_size;
}