Brick Breaker and shooter game scripts with p5.js and html PDF

Title Brick Breaker and shooter game scripts with p5.js and html
Course Development Concepts
Institution Centennial College
Pages 9
File Size 156.8 KB
File Type PDF
Total Downloads 28
Total Views 150

Summary

Concatenated scripts for a brick breaker style game mixed with a space shooter type game.
Image not included, so you may want to provide your own. Made with p5.js and html...


Description

this is a title



var var var var var var

bricks = []; player; playerX = 260; playerY = 700; playerW = 240; playerH = 60;

function setup() { createCanvas(800, 800); for (i = 0; i < 7; i++) { var x = i * 95 + 80; var y = 100; var b = new Brick(x, y); bricks.push(b); } for (i = 0; i < 7; i++) { var x = i * 95 + 80; var y = 200; var b = new Brick(x, y); bricks.push(b); } for (i = 0; i < 7; i++) { var x = i * 95 + 80; var y = 300; var b = new Brick(x, y); bricks.push(b); } for (z = 0; z < 1; z++) { var x = 400; var y = 1200; var b = new Brick(x, y); bricks.push(b); } ball = new Ball(400, 670); } function draw() { background(0); player = new Player(playerX, playerY, playerW, playerH); ball.display(); ball.movement(); ball.canvasCollision(); if (ball.playerCollision(playerX, playerY, playerW, playerH)) { ball.deflectY(); ball.y = playerY - 15; if (ball.xspeed > 0) { if(ball.x < playerX + 120) { ball.deflectX(); } } else if (ball.xspeed < 0) { if(ball.x > playerX + 120) { ball.deflectX(); } } } player.display(); controls(); var edge = false;

for (i = 0; i < bricks.length; i++) { bricks[i].display(); bricks[i].movement(); if (bricks[i].x + bricks[i].width > width || bricks[i].x < 0) { edge = true; } if (ball.brickCollisionU(bricks[i].x, bricks[i].y)) { ball.deflectY(); ball.y = bricks[i].y - 15; bricks.splice(i, 1); } if (ball.brickCollisionD(bricks[i].x, bricks[i].y)) { ball.deflectY(); ball.y = bricks[i].y + 50 + 15; bricks.splice(i, 1); } if (ball.brickCollisionL(bricks[i].x, bricks[i].y)) { ball.deflectX(); ball.x = bricks[i].x - 15; bricks.splice(i, 1); } if (ball.brickCollisionR(bricks[i].x, bricks[i].y)) { ball.deflectX(); ball.x = bricks[i].x + 80 + 15; bricks.splice(i, 1); } } if (edge) { for (i = 0; i < bricks.length; i++) { bricks[i].moveDown(); } } if (bricks.length == 1) { gameWon(); } gameOver(); } function controls() { if(keyIsDown(LEFT_ARROW)) { playerX -= 15; } if (keyIsDown(RIGHT_ARROW)) { playerX += 15; } } function gameWon() { fill(255); rect(0, 0, 800, 800); fill(0); textSize(80); text("YOU WIN!", 200, 400); } function gameOver() { if (ball.y > height && bricks.length !== 1) { fill(150, 0, 0); rect(0, 0, 800, 800);

fill(255); textSize(80); text("GAME OVER", 200, 400); } }

function Ball(x, y) { this.x = x; this.y = y; this.xspeed = -4; this.yspeed = -2; this.display = function () { fill(255); rect(this.x, this.y, 15, 15); } this.movement = function () { this.x = this.x + this.xspeed; this.y = this.y + this.yspeed; } this.canvasCollision = function () { if (this.x = width) { this.xspeed *= -1; } if (this.y this.ry && this.y < this.ry + this.rh) || (this.y > this.ry && this.y < this.ry + this.rh)) && (this.x + 15 >= this.rx && this.x this.ry && this.y < this.ry + this.rh) || (this.y > this.ry && this.y + 15< this.ry + this.rh)) && (this.x = this.rx + this.rw - this.rw/2)) { return true; } else { return false; } } this.brickCollisionD = function (rx, ry) { this.rx = rx; this.ry = ry; this.rw = 80; this.rh = 50;

if ((this.y = this.ry + this.rh/2) && ((this.x + 15 > this.rx && this.x < this.rx + this.rw) || (this.x + 15 > this.rx + this.rw && this.x < this.rx + this.rw) || (this.x < this.rx && this.x + 15 > this.rx))) { return true; } else { return false; } } this.brickCollisionU = function (rx, ry) { this.rx = rx; this.ry = ry; this.rw = 80; this.rh = 50; if ((this.y + 15 >= this.ry && this.y + 15 this.rx && this.x < this.rx + this.rw) || (this.x + 15 > this.rx + this.rw && this.x < this.rx + this.rw) || (this.x < this.rx && this.x + 15 > this.rx))) { return true; } else { return false; } } this.playerCollision = function (rx, ry, rw, rh) { this.rx = rx; this.ry = ry; this.rw = rw; this.rh = rh; if ((this.x + 15 > this.rx && this.x < this.rx + this.rw) && (this.y + 15 > this.ry && this.y + 15 < this.ry + this.rh)) { return true; } else { return false; } } this.deflectY = function () { if (this.yspeed > 0) { if (this.yspeed = 8) { this.yspeed *= -1; } } else if (this.yspeed < 0) { if (this.yspeed >= -8) { this.yspeed *= -1.5; } else if(this.yspeed 0) {

if (this.xspeed = 8) { this.xspeed *= -1; } } else if (this.xspeed < 0) { if (this.xspeed >= -8) { this.xspeed *= -1.5; } else if(this.xspeed...


Similar Free PDFs