Created
March 30, 2016 18:36
-
-
Save JasonMadeSomething/f0f1cec90593d7d0430335a08c88121f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Bloc Pong</title> | |
<link type="text/css" rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<h1 id="page-title">Bloc Pong</h1> | |
<canvas id="pong-table"></canvas> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Paddle(xPos, yPos, width, height) { | |
this.xPosition = xPos; | |
this.yPosition = yPos; | |
this.width = width; | |
this.height = height; | |
} | |
function Ball(xPos, yPos, radius) { | |
this.xPosition = xPos; | |
this.yPosition = yPos; | |
this.radius = radius; | |
} | |
function Player(){ | |
this.paddle = new Paddle(792, 312.5, 8, 75); | |
} | |
function Computer(){ | |
this.paddle = new Paddle(0, 312.5, 8, 75); | |
} | |
Paddle.prototype.render = function(context){ | |
context.beginPath(); | |
context.rect(this.xPosition, this.yPosition, this.width, this.height); | |
context.fillStyle = "black"; | |
context.fill(); | |
} | |
Ball.prototype.render = function(context){ | |
context.beginPath(); | |
context.arc(this.xPosition, this.yPosition, this.radius, 0, 0, false); | |
context.strokeStyle = 'black'; | |
context.stroke(); | |
context.fillStyle = 'black'; | |
context.fill(); | |
} | |
Player.prototype.render = function(context) { | |
this.paddle.render(context); | |
} | |
Computer.prototype.render = function(context) { | |
this.paddle.render(context); | |
} | |
var player = new Player(); | |
var computer = new Computer(); | |
var ball = new Ball(400, 275, 25); | |
function render(context){ | |
player.render(context); | |
computer.render(context); | |
ball.render(context); | |
} | |
window.onload = function() { | |
var canvas = document.getElementById("pong-table"); | |
var context = canvas.getContext('2d'); | |
render(context); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canvas { | |
padding: 0; | |
margin: auto; | |
display: block; | |
width: 800px; | |
height: 550px; | |
top: 0; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
position: absolute; | |
background-color: lightgrey; | |
} | |
#page-title { | |
text-align: center; | |
margin-bottom: 15px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment