function Paddle(options) { if (typeof(options) == 'undefined') options={}; var x = options.x !== undefined ? options.x : 0; var y = options.y !== undefined ? options.y : 0; var sx = options.sx !== undefined ? options.sx : 0; var size = options.size !== undefined ? options.size : 0; function movePaddle(dir) { x += dir * sx; } function getX1() { return x - (size / 2); } function getX2() { return x + (size / 2); } function getY() { return y; } function increaseDifficulty() { size -= 4; if (size < 20) { size = 20; } sx += 2; } function update(ctx) { if (x <= (size / 2)) { x = size / 2; } if (x >= (ctx.canvas.width - (size / 2))) { x = (ctx.canvas.width - (size / 2)); } } function draw(ctx) { ctx.beginPath(); ctx.fillStyle = '#000000'; ctx.strokeStyle = '#000000'; ctx.lineWidth = 5; ctx.moveTo(x - size / 2, y); ctx.lineTo(x + size / 2, y); ctx.stroke(); } return { 'x': x, 'y': y, 'sx': sx, 'size': size, 'movePaddle': movePaddle, 'getX1': getX1, 'getX2': getX2, 'getY': getY, 'increaseDifficulty': increaseDifficulty, 'update': update, 'draw': draw }; }