Break Out

Developer
Size
12,431 Kb
Views
26,312

How do I make an break out?

Second entry on my "game a week" challenge.. What is a break out? How do you make a break out? This script and codes were developed by Aitor on 16 September 2022, Friday.

Break Out Previews

Break Out - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Break Out</title> <link href='https://fonts.googleapis.com/css?family=Orbitron:400,500,700,900' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<canvas width="640" height="480"></canvas> <script src="js/index.js"></script>
</body>
</html>

Break Out - Script Codes CSS Codes

html,
body { background: #000; color: #fff; margin: 0; padding: 0; overflow: hidden;
}

Break Out - Script Codes JS Codes

"use strict";
var _class, _temp, _class2, _temp2, _class3, _temp3, _class4, _temp4, _class5, _temp5;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var canvas = document.querySelector("canvas"), context = canvas.getContext("2d");
var DEBUG = false;
var Point = function () { function Point() { var x = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; var y = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; _classCallCheck(this, Point); this.x = x; this.y = y; } Point.prototype.set = function set(x, y) { this.x = x; this.y = y; return this; }; Point.prototype.add = function add(x, y) { this.x += x; this.y += y; return this; }; Point.prototype.addVector = function addVector(v) { return this.add(v.x, v.y); }; Point.prototype.subtract = function subtract(x, y) { this.x -= x; this.y -= y; return this; }; Point.prototype.subtractVector = function subtractVector(v) { return this.subtract(v.x, v.y); }; Point.prototype.invertX = function invertX() { this.x = -this.x; return this; }; Point.prototype.invertY = function invertY() { this.y = -this.y; return this; }; Point.prototype.invert = function invert() { return this.invertX().invertY(); }; Point.prototype.multiply = function multiply(x, y) { this.x *= x; this.y *= y; return this; }; Point.prototype.multiplyVector = function multiplyVector(v) { return this.multiply(v.x, v.y); }; Point.prototype.multiplyScalar = function multiplyScalar(k) { return this.multiply(k, k); }; _createClass(Point, [{ key: "lengthSquared", get: function get() { return this.x * this.x + this.y * this.y; } }, { key: "length", get: function get() { return Math.sqrt(this.lengthSquared); } }]); return Point;
}();
var Rect = function (_Point) { _inherits(Rect, _Point); function Rect() { var x = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; var y = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; var width = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2]; var height = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3]; _classCallCheck(this, Rect); var _this = _possibleConstructorReturn(this, _Point.call(this, x, y)); _this.width = width; _this.height = height; return _this; } Rect.prototype.contains = function contains(x, y) { return x > this.x && y > this.y && x < this.x + this.width && y < this.y + this.height; }; Rect.prototype.containsPoint = function containsPoint(p) { return this.contains(p.x, p.y); }; Rect.prototype.containsRect = function containsRect(r) { return this.contains(r.left, r.top) && this.contains(r.right, r.bottom); }; Rect.prototype.collides = function collides(r) { return r.contains(this.left, this.top) || r.contains(this.right, this.top) || r.contains(this.left, this.bottom) || r.contains(this.right, this.bottom); }; _createClass(Rect, [{ key: "left", get: function get() { return this.x; } }, { key: "top", get: function get() { return this.y; } }, { key: "right", get: function get() { return this.x + this.width; } }, { key: "bottom", get: function get() { return this.y + this.height; } }, { key: "halfWidth", get: function get() { return this.width * 0.5; } }, { key: "halfHeight", get: function get() { return this.height * 0.5; } }, { key: "centerX", get: function get() { return this.x + this.halfWidth; } }, { key: "centerY", get: function get() { return this.y + this.halfHeight; } }]); return Rect;
}(Point);
var State = { TITLE: 0, PREPARE: 1, GAME: 2, GAME_OVER: 3, WON: 4
};
var Stage = { contains: function contains(x, y) { return x > 0 && y > 0 && x < this.width && y < this.height; }, containsVector: function containsVector(v) { return this.contains(v.x, v.y); }, get max() { return Math.max(canvas.width, canvas.height); }, get min() { return Math.min(canvas.width, canvas.height); }, get width() { return canvas.width; }, get height() { return canvas.height; }, get centerX() { return canvas.width * 0.5; }, get centerY() { return canvas.height * 0.5; }, get leftBorder() { return this.centerX - (Brick.WIDTH + 1) * 9; }, get rightBorder() { return this.centerX + (Brick.WIDTH + 1) * 9; }
};
var Key = function () { var keys = new Array(256), hooks = {}; for (var index = 0; index < keys.length; index++) { keys[index] = false; } function keyup(e) { var key = e.keyCode; keys[key] = false; if (hooks[key]) { hooks[key](); } } function keydown(e) { var key = e.keyCode; keys[key] = true; } return { ENTER: 13, ESCAPE: 27, SPACE: 32, NUM_0: 48, NUM_1: 49, NUM_2: 50, NUM_3: 51, NUM_4: 52, NUM_5: 53, NUM_6: 54, NUM_7: 55, NUM_8: 56, NUM_9: 57, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, start: function start() { window.addEventListener("keyup", keyup); window.addEventListener("keydown", keydown); }, stop: function stop() { window.removeEventListener("keyup", keyup); window.removeEventListener("keydown", keydown); }, on: function on(key, fn) { hooks[key] = fn; return this; }, off: function off(key) { hooks[key] = null; return this; }, isDown: function isDown(key) { return keys[key]; }, isUp: function isUp(key) { return !keys[key]; } };
}();
var Item = (_temp = _class = function (_Point2) { _inherits(Item, _Point2); function Item(x, y, color) { _classCallCheck(this, Item); var _this2 = _possibleConstructorReturn(this, _Point2.call(this, x, y)); _this2.color = color; var itemTypeIndex = Math.round(Math.random() * (Item.TYPES.length - 1)); _this2.type = Item.TYPES[itemTypeIndex]; return _this2; } Item.prototype.move = function move() { this.add(0, 3); return this; }; Item.prototype.render = function render(now) { context.save(); context.translate(this.x, this.y); context.fillStyle = this.color; context.fillRect(Item.WIDTH * -0.5, Item.HEIGHT * -0.5, Item.WIDTH, Item.HEIGHT); context.font = "bold 20px Orbitron, sans-serif"; context.textAlign = "center"; context.textBaseline = "middle"; context.fillStyle = "#fff"; if (this.type === Item.LARGE) { context.fillText("L", 0, 3); } else if (this.type === Item.SMALL) { context.fillText("S", 0, 3); } else if (this.type === Item.POWERBALL) { context.fillText("P", 0, 3); } else { context.fillText("U", 0, 3); } context.restore(); }; return Item;
}(Point), _class.WIDTH = 20, _class.HEIGHT = 20, _class.LARGE = "large", _class.SMALL = "small", _class.POWERBALL = "powerball", _class.TYPES = ["large", "small", "powerball"], _temp);
var Particle = (_temp2 = _class2 = function (_Point3) { _inherits(Particle, _Point3); function Particle(x, y, color) { _classCallCheck(this, Particle); var _this3 = _possibleConstructorReturn(this, _Point3.call(this, x, y)); var vx = (Math.random() - 0.5) * 5; var vy = (Math.random() - 0.5) * 5; _this3.velocity = new Point(vx, vy); _this3.color = color; _this3.life = 1.0; return _this3; } Particle.prototype.update = function update(now) { this.addVector(this.velocity); this.life -= 0.1; return this; }; Particle.prototype.render = function render(now) { context.save(); context.translate(this.x, this.y); context.globalAlpha = this.life; context.fillStyle = this.color; context.fillRect(Particle.WIDTH * -0.5, Particle.HEIGHT * -0.5, Particle.WIDTH, Particle.HEIGHT); context.restore(); }; _createClass(Particle, [{ key: "isDead", get: function get() { return this.life <= 0.0; } }]); return Particle;
}(Point), _class2.WIDTH = 4, _class2.HEIGHT = 4, _temp2);
var Brick = (_temp3 = _class3 = function (_Rect) { _inherits(Brick, _Rect); function Brick() { var tx = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; var ty = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; var isUndestructible = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; var hitsToDestroy = arguments.length <= 3 || arguments[3] === undefined ? 3 : arguments[3]; _classCallCheck(this, Brick); var _this4 = _possibleConstructorReturn(this, _Rect.call(this, tx * Brick.WIDTH, ty * Brick.HEIGHT, Brick.WIDTH, Brick.HEIGHT)); _this4.tx = tx; _this4.ty = ty; _this4.initialHitsToDestroy = hitsToDestroy; _this4.hitsToDestroy = hitsToDestroy; _this4.isUndestructible = isUndestructible; _this4.isDestroyed = false; return _this4; } Brick.prototype.destroy = function destroy() { var force = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; if (force) { this.hitsToDestroy = 0; this.isDestroyed = true; } else { if (this.hitsToDestroy > 0) { this.hitsToDestroy--; } if (this.hitsToDestroy === 0) { this.isDestroyed = true; } } return this; }; Brick.prototype.restore = function restore() { this.hitsToDestroy = this.initialHitsToDestroy; this.isDestroyed = false; return this; }; Brick.prototype.render = function render(now) { if (this.isDestroyed) { return; } context.save(); context.translate(this.x, this.y); context.fillStyle = this.color; context.fillRect(0, 0, this.width, this.height); context.restore(); }; Brick.prototype.setInitialPosition = function setInitialPosition() { // TODO: Make this code more clear this.x = Stage.centerX - (this.tx * (this.width + 1) - (this.width + 1) * 7) - this.halfWidth; this.y = 50 + this.ty * (this.height + 1) - this.halfHeight; return this; }; Brick.prototype.resize = function resize() { return this.setInitialPosition(); }; _createClass(Brick, [{ key: "initialColor", get: function get() { if (this.isUndestructible) { return "#0cf"; } else if (this.initialHitsToDestroy > 1) { return "#f0c"; } else { return "#fc0"; } } }, { key: "color", get: function get() { if (this.isUndestructible) { return "#0cf"; } else { if (this.initialHitsToDestroy > 1) { var value = Math.round(this.hitsToDestroy / this.initialHitsToDestroy * 255); return "rgb(" + value + ",0," + Math.round(value * 0.5) + ")"; } else { return "#fc0"; } } } }]); return Brick;
}(Rect), _class3.WIDTH = 50, _class3.HEIGHT = 20, _temp3);
var Ball = (_temp4 = _class4 = function (_Rect2) { _inherits(Ball, _Rect2); function Ball() { _classCallCheck(this, Ball); var _this5 = _possibleConstructorReturn(this, _Rect2.call(this, Stage.centerX, Stage.centerY, Ball.WIDTH, Ball.HEIGHT)); _this5.velocity = new Point(Ball.DEFAULT_VEL_X, Ball.DEFAULT_VEL_Y); _this5.isPowerful = false; return _this5; } Ball.prototype.move = function move() { this.addVector(this.velocity); return this; }; Ball.prototype.over = function over(pad) { this.y = pad.y - this.height; this.x = pad.centerX - this.halfWidth; return this; }; Ball.prototype.throw = function _throw() { this.x = Math.random() * this.halfWidth; this.y = -Ball.DEFAULT_VEL_Y; return this; }; Ball.prototype.bounceY = function bounceY() { this.velocity.invertY(); return this; }; Ball.prototype.bounceX = function bounceX() { this.velocity.invertX(); return this; }; Ball.prototype.bounce = function bounce() { return this.bounceX().bounceY(); }; Ball.prototype.bounceBrick = function bounceBrick(brick) { this.rewind(); if (this.centerY >= brick.top && this.centerY <= brick.bottom) { return this.bounceX(); } else { return this.bounceY(); } }; Ball.prototype.bouncePad = function bouncePad(pad) { this.velocity.x = (this.centerX - pad.centerX) / this.halfWidth; return this.bounceY(); }; Ball.prototype.rewind = function rewind() { this.subtractVector(this.velocity); return this; }; Ball.prototype.setInitialVelocity = function setInitialVelocity() { return this.velocity.set(Ball.DEFAULT_VEL_X, Ball.DEFAULT_VEL_Y); }; Ball.prototype.setInitialPosition = function setInitialPosition() { this.x = Stage.centerX - this.halfWidth; this.y = Stage.centerY - this.halfHeight; return this.setInitialVelocity(); }; Ball.prototype.render = function render(now) { context.save(); context.translate(this.x, this.y); context.fillStyle = "#fff"; context.fillRect(0, 0, this.width, this.height); context.restore(); }; Ball.prototype.resize = function resize() { this.setInitialPosition(); }; return Ball;
}(Rect), _class4.WIDTH = 10, _class4.HEIGHT = 10, _class4.DEFAULT_VEL_X = 0, _class4.DEFAULT_VEL_Y = 5, _temp4);
var Pad = (_temp5 = _class5 = function (_Rect3) { _inherits(Pad, _Rect3); function Pad() { _classCallCheck(this, Pad); var _this6 = _possibleConstructorReturn(this, _Rect3.call(this, Stage.centerX, Stage.height * 0.9, Pad.WIDTH, Pad.HEIGHT)); _this6.velocity = new Point(); _this6.isSmall = false; _this6.isLarge = false; _this6.friction = 0.9; return _this6; } Pad.prototype.moveLeft = function moveLeft() { this.velocity.x -= 1.0; return this; }; Pad.prototype.moveRight = function moveRight() { this.velocity.x += 1.0; return this; }; Pad.prototype.move = function move() { if (this.isLarge && this.width != Pad.WIDTH_L) { this.width += (Pad.WIDTH_L - this.width) * 0.1; } else if (this.isSmall && this.width != Pad.WIDTH_S) { this.width += (Pad.WIDTH_S - this.width) * 0.1; } else { if (this.width != Pad.WIDTH) { this.width += (Pad.WIDTH - this.width) * 0.1; } } this.addVector(this.velocity); this.velocity.multiplyScalar(this.friction); return this; }; Pad.prototype.render = function render(now) { context.save(); context.translate(this.x, this.y); context.fillStyle = "#fff"; context.fillRect(0, 0, this.width, this.height); context.restore(); }; Pad.prototype.setInitialPosition = function setInitialPosition() { this.x = Stage.centerX - this.halfWidth; this.y = Stage.height * Pad.DEFAULT_POS_Y - this.halfHeight; return this; }; Pad.prototype.resize = function resize() { return this.setInitialPosition(); }; return Pad;
}(Rect), _class5.WIDTH = 100, _class5.WIDTH_L = 200, _class5.WIDTH_S = 50, _class5.HEIGHT = 10, _class5.DEFAULT_POS_Y = 0.9, _temp5);
var lifes = 3, state = State.TITLE, countdown = 3, startCountdown = null, destructibleBricks = 0, destroyedBricks = 0;
var pad = new Pad(), ball = new Ball(), bricks = [], items = [], particles = [];
for (var y = 0; y < 10; y++) { for (var x = 0; x < 15; x++) { bricks.push(new Brick(x, y, y % 5 === 0 ? true : false, y % 2 === 0 ? 2 : 1)); }
}
for (var index = 0; index < bricks.length; index++) { var brick = bricks[index]; if (!brick.isUndestructible) { destructibleBricks++; }
}
function explosion(v, color) { for (var index = 0; index < 10; index++) { particles.push(new Particle(v.x, v.y, color)); }
}
function frame() { var now = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; update(now); render(now); window.requestAnimationFrame(frame);
}
function updateParticles(now) { for (var index = particles.length - 1; index >= 0; index--) { var particle = particles[index]; particle.update(now); if (particle.isDead) { particles.splice(index, 1); } }
}
function update(now) { if (state === State.PREPARE || state === State.GAME) { if (Key.isDown(Key.LEFT)) { pad.moveLeft(); } else if (Key.isDown(Key.RIGHT)) { pad.moveRight(); } pad.move(); if (pad.x < Stage.leftBorder) { pad.x = Stage.leftBorder; } else if (pad.x > Stage.rightBorder - pad.width) { pad.x = Stage.rightBorder - pad.width; } if (state === State.PREPARE) { if (!startCountdown) { startCountdown = now; } else { countdown = 3 - Math.floor((now - startCountdown) / 1000); if (countdown <= 0) { startCountdown = null; state = State.GAME; ball.throw(); } } ball.over(pad); updateParticles(now); } else if (state === State.GAME) { ball.move(); if (ball.y > Stage.height) { lifes--; if (lifes === 0) { state = State.GAME_OVER; } else { state = State.PREPARE; pad.isLarge = false; pad.isSmall = false; ball.isPowerful = false; ball.setInitialPosition(); while (items.length > 0) { var item = items.pop(); explosion(item, item.color); } } } else if (ball.y < 0) { ball.bounceY(); explosion(ball, "#fff"); } else if (ball.x < Stage.leftBorder + ball.halfWidth) { ball.bounceX(); explosion(ball, "#0cf"); } else if (ball.x > Stage.rightBorder - ball.width) { ball.bounceX(); explosion(ball, "#f0c"); } if (ball.collides(pad)) { ball.bouncePad(pad); explosion(ball, "#fff"); } destroyedBricks = 0; for (var index = 0; index < bricks.length; index++) { var brick = bricks[index]; if (!brick.isDestroyed) { if (ball.collides(brick)) { if (!brick.isUndestructible) { brick.destroy(ball.isPowerful); if (brick.isDestroyed && Math.random() > 0.85) { items.push(new Item(brick.centerX, brick.centerY, brick.initialColor)); } } if (!ball.isPowerful || brick.isUndestructible) { ball.bounceBrick(brick); } explosion(ball, brick.color); } } else { destroyedBricks++; if (destroyedBricks === destructibleBricks) { state = State.WON; } } } for (var index = items.length - 1; index >= 0; index--) { var item = items[index]; item.move(); if (pad.containsPoint(item)) { if (item.type === Item.LARGE) { pad.isLarge = true; if (pad.isSmall === true) { pad.isSmall = false; } } else if (item.type === Item.SMALL) { pad.isSmall = true; if (pad.isLarge === true) { pad.isSmall = false; } } else if (item.type === Item.POWERBALL) { ball.isPowerful = true; } explosion(item, item.color); items.splice(index, 1); } else if (item.y > Stage.height) { items.splice(index, 1); } } updateParticles(now); } }
}
Key.on(Key.SPACE, function () { if (state === State.GAME_OVER || state === State.WON) { state = State.TITLE; } else if (state === State.TITLE) { lifes = 3; pad.setInitialPosition(); ball.setInitialPosition(); for (var index = 0; index < bricks.length; index++) { var brick = bricks[index]; brick.restore(); } state = State.PREPARE; }
});
if (DEBUG) { Key.on(Key.NUM_1, function () { pad.isLarge = !pad.isLarge; if (pad.isLarge) { pad.isSmall = false; } }).on(Key.NUM_2, function () { pad.isSmall = !pad.isSmall; if (pad.isLarge) { pad.isLarge = false; } }).on(Key.NUM_3, function () { ball.isPowerful = !ball.isPowerful; });
}
function renderBackground(now) { context.save(); context.translate(Stage.centerX, Stage.centerY); context.scale(2, 2); context.save(); context.rotate(now * 0.001); context.translate(-Stage.centerX, -Stage.centerY); context.fillStyle = "#0cf"; context.fillRect(0, 0, Stage.max * (1 / 3), Stage.max); context.fillStyle = "#fc0"; context.fillRect(Stage.max * (1 / 3), 0, Stage.max * (1 / 3), Stage.max); context.fillStyle = "#f0c"; context.fillRect(Stage.max * (2 / 3), 0, Stage.max * (1 / 3), Stage.max); context.restore(); context.restore();
}
function renderLifes() { context.font = "bold 20px Orbitron, sans-serif"; context.textAlign = "left"; context.textBaseline = "top"; context.fillStyle = "#fff"; context.fillText("LIFES: " + lifes, Stage.leftBorder + 20, Stage.height - 30);
}
function renderDebug() { context.font = "normal 10px monospace"; context.fillStyle = "#000"; context.fillText("LARGE: " + pad.isLarge + " (Use 1 to toggle)", Stage.leftBorder + 21, Stage.height - 101); context.fillText("SMALL: " + pad.isSmall + " (Use 2 to toggle)", Stage.leftBorder + 21, Stage.height - 91); context.fillText("POWER BALL: " + ball.isPowerful + " (Use 3 to toggle)", Stage.leftBorder + 21, Stage.height - 81); context.fillStyle = "#fff"; context.fillText("LARGE: " + pad.isLarge + " (Use 1 to toggle)", Stage.leftBorder + 20, Stage.height - 100); context.fillText("SMALL: " + pad.isSmall + " (Use 2 to toggle)", Stage.leftBorder + 20, Stage.height - 90); context.fillText("POWER BALL: " + ball.isPowerful + " (Use 3 to toggle)", Stage.leftBorder + 20, Stage.height - 80);
}
function renderCountdown(now) { var a = 1.0 - (now - startCountdown) % 1000 / 1000; context.save(); context.globalAlpha = a; context.translate(Stage.centerX, Stage.centerY); context.scale(a, a); context.font = "bold 100px Orbitron, sans-serif"; context.textAlign = "center"; context.textBaseline = "middle"; context.fillStyle = "#fff"; context.fillText("" + countdown, 0, 0); context.restore();
}
function renderBouncingText(now, bouncingText) { var a = Math.abs(Math.sin(now / 1000)), s = Math.abs(Math.sin(now / 1000)) + 0.5; context.save(); context.translate(Stage.centerX, Stage.centerY); context.scale(s, s); context.rotate(Math.sin(now / 1000) * Math.PI * 0.125); context.font = "bold 100px Orbitron, sans-serif"; context.textAlign = "center"; context.textBaseline = "middle"; context.fillStyle = "#fff"; context.fillText(bouncingText, 0, 0); context.restore(); context.save(); context.font = "bold 20px Orbitron, sans-serif"; context.textAlign = "center"; context.textBaseline = "middle"; context.fillStyle = "#fff"; var text = "PRESS SPACE TO CONTINUE"; var fullMeasure = context.measureText(text); for (var index = 0; index < text.length; index++) { var measures = context.measureText(text.substr(0, index)); context.fillText(text.substr(index, 1), Stage.centerX + measures.width - fullMeasure.width * 0.5, Stage.height * 0.9 + Math.sin(now / 100 + index)); } context.restore();
}
function renderTitle(now) { renderBackground(now); renderBouncingText(now, "BREAK OUT");
}
function renderGameOver(now) { renderBouncingText(now, "GAME OVER");
}
function renderWon(now) { renderBouncingText(now, "YOU WON!");
}
function renderLeftBorder() { context.fillStyle = "#0cf"; context.fillRect(0, 0, Stage.leftBorder, Stage.height);
}
function renderRightBorder() { context.fillStyle = "#f0c"; context.fillRect(Stage.rightBorder, 0, Stage.width - Stage.rightBorder, Stage.height);
}
function render(now) { if (state === State.PREPARE || state === State.GAME) { context.clearRect(0, 0, Stage.width, Stage.height); } else { context.fillStyle = "rgba(0,0,0,0.2)"; context.fillRect(0, 0, Stage.width, Stage.height); } if (state === State.TITLE) { renderTitle(now); } else if (state === State.PREPARE || state === State.GAME) { pad.render(now); ball.render(now); for (var index = 0; index < bricks.length; index++) { var brick = bricks[index]; brick.render(now); } for (var index = 0; index < items.length; index++) { var item = items[index]; item.render(now); } for (var index = 0; index < particles.length; index++) { var particle = particles[index]; particle.render(now); } renderLeftBorder(now); renderRightBorder(now); renderLifes(now); if (state === State.PREPARE) { renderCountdown(now); } } else if (state === State.GAME_OVER) { renderGameOver(now); } else if (state === State.WON) { renderWon(now); } if (DEBUG) { renderDebug(); }
}
function resize() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; pad.resize(); ball.resize(); for (var index = 0; index < bricks.length; index++) { var brick = bricks[index]; brick.resize(); }
}
Key.start();
resize();
frame();
window.addEventListener("resize", resize);
Break Out - Script Codes
Break Out - Script Codes
Home Page Home
Developer Aitor
Username AzazelN28
Uploaded September 16, 2022
Rating 4.5
Size 12,431 Kb
Views 26,312
Do you need developer help for Break Out?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Aitor (AzazelN28) Script Codes
Name
Blending Experiment 29
Branches
Follow the lines
Circuitry
Asteroids
Date Input
Fire
Physics 101
Superformula
Adventure
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!