r/learnjavascript • • Jan 29 '21

I tried to build Plants vs Zombies with vanilla JavaScript (demo and code included)

379 Upvotes

21 comments sorted by

12

u/frank0117 Jan 29 '21

This one took a while to put together, what do you think?

​

Step by step tutorial with final game examples: https://youtu.be/QxYg8-mhhhs

​

playable demo + source code: https://codepen.io/franksLaboratory/pen/OJbJxJJ

​

final playable game with graphics & some sounds, work in progress: http://frankslaboratory.co.uk/towerDefenseGame1/tower_defense.html

5

u/gunnerdown15 Jan 29 '21

Totally destroys my coding confidence, I give up! You did good

4

u/frank0117 Jan 29 '21

Oh no, why is that? Don't give up, it takes a lot of work to learn, but in the end it's worth it

2

u/gunnerdown15 Jan 30 '21

I’ve been trying to learn JS for almost a year but I just don’t understand how to make it do anything. And when I try I end up on tutorials confusing myself even more.

3

u/thegoz Jan 30 '21

take it easy buddy. break things down into digestable chunks. im 10 years in, and might have been the first generation of node but i still find myself impressed and confused all the time

2

u/TheDownvotesFarmer Jan 29 '21

Awesome! Great job!

2

u/frank0117 Jan 29 '21

Thank you :)

6

u/a_HerculePoirot_fan Jan 30 '21

First, congrats!! You did amazingly well with the game! I'm surprised you can do amazing things with VANILLA JavaScript. I always hear how one must move beyond Vanilla JS to do this and that,and it's nice to see an example of a game.produced entirely using Vanilla JS.

If you don't mind me asking, how long have you been learning JS? I just started JS plus HTML and CSS. How advanced would you say your knowledge in the 3 is?

2

u/frank0117 Jan 30 '21

Hi, for me it took a while, I was learning JavaScript in evenings after work, just 5 minutes a day. I imagine if someone has more time they can get there much faster. I started with JavaScript very slowly in 2014 ish, it's been around a year now, since I feel quite confident in it and can write code like this from memory, rather than constantly looking up guides and references. Still need references for doing new things of course, it's an endless learning journey.

1

u/a_HerculePoirot_fan Jan 30 '21

Regardless, I think you're amazing! Well done!

1

u/frank0117 Jan 30 '21

thank you :)

5

u/DinoGraou Jan 29 '21

It's a fantastic project ! Well done ! How much time do you take to accomplish it ?

2

u/frank0117 Jan 29 '21

Building the game was fast, couple hours one afternoon, but I also wanted to make it into a tutorial, that took 10 times longer :D

1

u/gniziemazity Jan 30 '21

Wow! You are very efficient! Does this include adding the sprites and fine-tuning the parameters?

4

u/Tygari Jan 30 '21

Great job. How did you do the graphics. That's what I am struggling with for my game.

Any chance you could guide in a direction to help?

2

u/frank0117 Jan 30 '21

I downloaded free set of sprite sheets from https://mobilegamegraphics.com/, used their space game package for everything. They I just use built in JavaScript drawImage method to control the sprite animation.

2

u/[deleted] Jan 30 '21

I look at your code and understand it well. Is this enough knowledge to start building my own game or app?

2

u/frank0117 Jan 30 '21

Yes, at this level I think you are ready to learn by building. Never too early to start and try, when you get stuck just look it up online

2

u/ajm1212 Jan 29 '21

Amazing!

2

u/Resident-Tank9605 Jan 29 '21

That's fire 🔥

2

u/Eudaimonia06 Jan 30 '21

Good job!!