xxxxxxxxxx
117
let heart = [
[0, 1, 1, 0, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 0, 0],
[0, 0, 0, 1, 0, 0, 0]
];
let score = 0;
let lives = 3;
let player;
function setup() {
createCanvas(800, 600);
player = new Player();
ball = new Ball();
// resetBall();
}
function draw() {
background(20);
noStroke();
fill(240);
player.update();
player.show();
ball.update();
ball.show();
show_score();
frame();
} // draw
function collide(a, b) {
let ball_left = b.pos.x - b.w / 2;
let ball_right = b.pos.x + b.w / 2;
let ball_top = b.pos.y - b.h / 2;
let ball_bottom = b.pos.y + b.h / 2;
let plr_left = a.pos.x - a.w / 2;
let plr_right = a.pos.x + a.w / 2;
let plr_top = a.pos.y - a.h / 2;
let plr_bottom = a.pos.y + a.h / 2;
if(
ball_left < plr_right &&
ball_right > plr_left &&
ball_bottom > plr_top &&
ball_top < plr_bottom
) {
return true
}
}
function pixelheart() {
stroke(190);
strokeWeight(2);
noFill();
let pixelsize = width/20;
rectMode(CENTER)
for (let i = 0; i < heart.length; i++) {
for (let j = 0; j < heart[0].length; j++) {
if (heart[i][j] === 1) {
rect(
width/2 - (heart.length/2) * pixelsize + (j * pixelsize),
height/2 - (heart.length/3) * pixelsize + (i * pixelsize),
pixelsize, pixelsize);
}
}
}
}
function show_score() {
// textFont("Consolas");
textFont("consolas")
textSize(20);
fill(255);
textAlign(LEFT, CENTER);
text(`SCORE ${score}`, 12, 20);
textAlign(RIGHT, CENTER);
text(`LIVES: ${lives}`, width-20, 20)
}
function frame() {
stroke(195);
strokeWeight(8);
noFill();
rectMode(CORNER);
rect(0, 0, width, height);
}
function debug() {
noFill();
stroke(255,0,0);
strokeWeight (5);
point(px -pw/2, py );
point(px +pw/2, py );
point(px, py - ph/2 );
point(px, py + ph/2)
}
function resetBall() {
ball.pos = createVector(100, 200);
ball.vel = createVector(4, -3);
}