In this episode I write a Pong game in JavaScript from scratch.
Some key technologies we will look at are
* Object Oriented Programming
* ES6 class with getter and setter
* Canvas
* requestAnimationFrame()
* Handling user input
Since we are writing ES6 this code might not run on all browsers yet. I was running Chrome 52 when I wrote this and if you wish to follow I recommend you do too.
The initial HTML file can be found here:
https://github.com/meth-meth-method/pong/blob/5e20bf1512e1579f16d794d7ce2e49ad32f57b37/src/index.html
Try it:
https://meth-meth-method.github.io/pong/
Source code:
https://github.com/meth-meth-method/pong
Music:
Demoscene Time Machine
http://demoscenetimemachine.com
Original source
32 responses to “Writing a Pong game in JavaScript”
That shirt is an instant classic.
Great stuff! Just subscribed!
Heyy Meth Meth Method,
Great videos you make!
But I got one question, how can I make this pong game beatable?
Thank you for that video.When will make Arkanoid game???
Damn, your videos are great. Please, make new content, feed your motivation as many people really appreciate it! Good work, mate!
Is doing simple games easier with p5?
Will this work on a smartphone? I see you're moving the paddle with the mouse. Thanks.
Amazing! more Content!
Never trust someone who uses classes in JavaScript.
Please have a patreon account so we can throw money at you!
the original game was unbeatable?
Hey guys, is observable from the video that ball don't touch left and upper corner. In order to fix this use: get left(){ return this.position.x; } and get top(){return this.position.y; } . Happy Coding! 🙂
can you link javascript
Great content!
which it is EcmaScript ? =ОО Does the browser eat it without transpiler?
Make more videos!
Ukraine is watching you
You should make snake 😛
I know you probably do this later in the video, but I went ahead and added this after you made the 2nd paddle AI, to keep paddles within the screen:
this.players.forEach(player => {
if (player.pos.y – player.size.y / 2 < 0) {
player.pos.y = player.size.y / 2;
} else if (player.pos.y + player.size.y / 2 > this._canvas.height) {
player.pos.y = this._canvas.height – player.size.y / 2;
}
});
finally someone that writes elegant javascript code
How does he mark multiple things at once? Like at 12.20?
1590th subscriber! nice videos
HELP
my left player disappears when I move pointer into game picture
You make it look so simple and I didn't fall asleep 🙂 Thank you so much for creating these videos.
at 14:00 the arrowfunction does not work for me…
This channel is amazing! Please continue!!
rip my ears
How do you can call Keywords like "class" or "constructor" in JavaScript?
Hi! I wanna implement this code, and have a small problem. Ball don't collide with my rect, because rect coordinates don't updates timely. If I fast move mouse, sometimes it collide. Can you help me?
Fantastic presentation, thanks for posting. Entertaining and informative.
Would love to see the old school games such as Donkey Kong and or Super Mario.
love the name XD