Hi, I’m back with a second tutorial video where we hack together a simple Pong game using javascript and html5. In this one do I use a bigger fontsize, so that the video better can be viewed on mobile devices. Let me know in the comments if I should use the settings in the previous video, use the fontsize in this video or use an even bigger font 🙂 (btw. the font I use in the video are Anonymous Pro, http://www.marksimonson.com/fonts/view/anonymous-pro).
:: Annotated Source ::
https://github.com/maxwihlborg/youtube-tutorials/blob/master/pong/index.html
:: Other Stuff ::
https://github.com/maxwihlborg
http://maxwihlborg.com/
Tweets by epicwihlborg
Original source
28 responses to “Pong – HTML5 Game Programming Tutorial [javascript]”
You go toooooooo fast! SLOW DOWN
I made it all of the way through this video using pause and rewind – it does move really fast and covers a ton of material, including some trigonometry for ball angles and velocity. Though a little difficult for absolute newbies, it does give a great introduction to creating a simple pong game in pure Javascript (i.e., no frameworks). The finished game unfortunately doesn't have a scoring system, but the ball moves a lot like the "real" thing. The follow-up video he mentions at the end apparently didn't happen. Oh well.
This seems like a great tutorial, however the audio quality is extremely poor. The words are rapidly spoken and flanged-out, and cannot be distinguished over the very loud clicking of the keyboard.
Didn't work 🙂
I Recommend running this at 0.75 speed and pausing often … very often.
Actually it might be better to just move frame by frame haha.
Edit: And use plenty of comments in your own code.
your going to fast
can someone explain the use of "this." pls
Garbage "tutorial". Left me more questions than answers. Can't even hear the guy.
Probably not the best to learn basic game control theory with as he uses some very clever tricks to obscure some of the heavy lifting that you need to understand. Very nice compact code though.
How would one make this responsive, so it fits properly on different screen sizes like desktop, tablet, and smartphone? Thanks.
Not having the js in an independant file…
ABSOLUTE BARBARIC!
good video anyways ^^
lol, at four minutes, I couldn't figure out what was wrong but, I had the ATH in math capitalized in math, and that completely affected it.
did you have to do any planning for this code?
what is he using to code this?
just searched it, it means add
wait add child?
is he taking children and adding him to his house????
this is still dark!
append child?
does that mean take a child?
thats dark
So, at 4:28 it does it's first test where it shows the two paddles and a ball. When I do it, I get a blank screen. Nothing. I looked through the code and I can't find any difference from what he has. Are the files available for download?
Thanks youu!!!
I understand everything, but can not repeat yourself. (
Thanks for the video. You are really good
You lost me after a minute. I have no idea what those functions do.
please slow down i can't understand you
you go way to fast and you dont explain anything 🙁 please make a video for beginners
I need some help the player, ai and ball don't appear in the screen. Any help would be apreciated.
help!I just get a white screen
The only thing this "tutorial" does is to show how skilled you are. Change the title, buddy….
what IDE is this? is it available for linux?
the document what is it saved as?
the blocks dont show up either
<!doctype html>
<html lang="en">
<meta charset="UTF-8">
<title>pong</title>
</head>
<body>
<script>
var WIDTH=700, HEIGHT=600, pi=Math.PI;
var canvas, ctx, keystate;
var player, ai, ball;
player = {
x: null,
y: null,
width: 20,
height: 100,
update: function() {},
draw: function() {
ctx.fillRect(this.x, this.y, this.width, this.height);
}
};
ai = {
x: null,
y: null,
width: 20,
height: 100,
update: function() {},
draw: function() {
ctx.fillRect(this.x, this.y, this.width, this.height);
}
};
ball = {
x: null,
y: null,
side: 20,
update: function() {},
draw: function() {
ctx.fillRect(this.x, this.y, this.side, this.side);
}
};
function main() {
canvas = document.createElement("canvas");
canvas.width = WIDTH;
canvas.height = HEIGHT;
ctx = canvas.getContext("2d");
document.body.appendCHild(canvas);
init();
var loop = function () {
update();
draw();
window.requestAnimationFrame(loop, canvas);
};
window.requestAnimationFrame(loop, canvas);
}
function init() {
player.x = player.width;
player.y = (HEIGHT – player.height)/2;
ai.x = WIDTH – (player.width + ai.width);
ai.y = (HEIGHT – ai.height)/2;
ball.x = (WIDTH – ball.side)/2;
ball.y = (HEIGHT – ball.side)/2;
}
function update() {
ball.update();
player.update();
ai.update();
}
function draw() {
ball.draw();
player.draw();
ai.draw();
}
main();
</script>
</body>
</htlm>