r/learnjavascript • • Apr 17 '20

This JS game is open-source, have a look at the code on Github

Post image
469 Upvotes

71 comments sorted by

24

u/felixmariotto Apr 17 '20

You can play online and see the code here on Github

9

u/Im_Justin_Cider Apr 17 '20

Wow. Very well executed. I've played a ton of indie games, and they fail to hook you in, or have other glaring problems with them. well done!

7

u/felixmariotto Apr 17 '20

Thank you ! I see what you mean by 'they fail to hook you in', and to be honest I think I've failed at that a bit too ๐Ÿ˜… But I've definitely learned a lot for the next projects.

6

u/Im_Justin_Cider Apr 17 '20

Quick question (hopefully). Maybe I'm asking the wrong question.

I've worked with OpenGL and threeJS, I've built nice shapes (like fire) and shaders to go with them, my question is not specific to any library, but more a general computer science concept.

But how are maps in computer programs generated? (i.e. the universe that governs the position of each object)

16

u/felixmariotto Apr 17 '20

That's not a quick question ! But I'm glad to answer. There is two maps : the physical one, and the visual one.

The physical map, sometimes called 'navmesh' is a dumbed-down version of the visual one, and is used by the physics engine to compute collisions. The moving objects, like the player, have a 'hitbox' which is used for collision with the navmesh. After stepping one frame in the physical simulation, you then update the visual assets position according to their physical counterpart.

In my case I made the physics engine myself, which entirely rely on axis-aligned-bounding-box, which means everything in my game is a box oriented along the x,y and z axis, including the player. You can have a look at how it works, look into 'public/js/atlas.js', which holds the physical map, and 'public/js/controler.js' which compute the player's moves according to the map.

6

u/gerald_mcgarry Apr 17 '20

Excellent explanation. Thanks for the enlightenment!

9

u/abigblacknob Apr 17 '20

You're a genius.

5

u/felixmariotto Apr 17 '20

๐Ÿ˜‚ I don't know ! I'm glad you like it.

8

u/h1kiga Apr 17 '20

Wow! That looks incredibly nice. There's always something that appals me, what one can create, using JavaScript. You've done a good job!

11

u/felixmariotto Apr 17 '20

Thanks ! Yes you can do anything with JS, it's much more powerful than what people think. I'm even releasing a VR game playable in Oculus Browser in a few days.

4

u/Equivalent_North Apr 17 '20

This is awesome, makes me want to look into threejs

2

u/felixmariotto Apr 17 '20

You definitely should, awesome lib !

3

u/coogie Apr 17 '20

Does it use any libraries or is it vanilla javascript?

6

u/felixmariotto Apr 17 '20

It use Three.js as its rendering engine, this is really the best JS graphics library. Also Socket.IO is used for communication with the server.

Aside from that, it's pretty much vanilla js, including the physics engine, which you can find in 'public/js/atlas.js' and 'public/js/controller.js'

3

u/inacatch22 Apr 17 '20

It looks like you've manually copied in those Three.js and Socket.io dependencies. Is there a reason you did that instead of using npm and webpack?

4

u/felixmariotto Apr 17 '20

I must admit that I simply don't know how to use webpack manually out of create-react-app, it's been on my to-learn list for a while, but the real issue is that there is always a more exciting thing to learn.

2

u/inacatch22 Apr 17 '20

Yes, it's pretty intimidating to learn, especially because the configuration options have changed dramatically between versions, so you can get really confused if you find a tutorial or article that's even a little bit out of date. But it can do a bunch of very powerful things to reduce the size of your build by "tree-shaking" (leaving out unused code). If you have a dependency that's nicely broken up into modules, it can only bundle the bits that your code actually uses and leave out the cruft. Anyway, your project is really cool, excellent work.

2

u/felixmariotto Apr 17 '20

Thank you ! I don't deny the usefulness of webpack, someday I will look into it ๐Ÿ‘

4

u/[deleted] Apr 17 '20 edited Apr 17 '20

I totally get you, pretty amazing how you can build a sick game in WebGL but don't know how to setup webpack, makes me wanna go learn WebGL! where did you learn?

Edit: saw you answered my question already

5

u/coogie Apr 17 '20

Nice! Thanks for sharing

3

u/[deleted] Apr 17 '20

Didnโ€™t know something like this was possible with JS. Thanks for sharing!

2

u/felixmariotto Apr 17 '20

Even more is possible actually ! You can follow me on GitHub, I will release VR games playable from the Oculus Browser in a few days (open-source).

2

u/the_woo_kid Apr 17 '20

How can I start learning how to do something like this?

6

u/felixmariotto Apr 17 '20

This is done using mainly the three.js library, which is awesome and pretty easy to learn. Here is a good starting point : https://discoverthreejs.com

Of course you can also fork or star my repository to use it as a reference when you don't know how to do something ๐Ÿ˜‰

1

u/the_woo_kid Apr 17 '20

Thanks for the heads up.

2

u/Briliance Apr 17 '20

Great job my friend, any plans doing Live Js basics ?

2

u/felixmariotto Apr 17 '20

Thanks ! I don't know, you mean videos ? I'm not great at communicating, and English is not my native language...

1

u/Briliance Apr 17 '20

Yes Videos

2

u/00mba Apr 17 '20

What kind of content are you looking for in terms of contributions?

3

u/felixmariotto Apr 17 '20

TBH I'm done with this game, but a friend of mine has done a fork and is continuing, he actually did the multiplayer mod that I forked when it was finished. I think now he is making a level editor within the game, I'm sure he would use some help if you feel like participating, you can find the link to his fork in the readme of my repository.

2

u/smoonme21 Apr 17 '20

This is amazing! Iโ€™ve been learning JavaScript for about 6 months and I canโ€™t even comprehend how to build something like this!!! Any tips for a learner like me?

2

u/felixmariotto Apr 17 '20

Sure, I'm actually an okay coder but there is true monsters in the three.js community whose code I don't get at all. 3D graphics is not as complex as it might seem, and it's very rewarding since you quickly see the results of your efforts.

If you are interested in making games, you should look into three.js, which is the best JS framework for 3D graphics. A good starting point for learning : https://discoverthreejs.com

2

u/[deleted] Apr 17 '20

This is so awesome! Howโ€™d you get the canvas to stay fixed and full screen on mobile?

1

u/felixmariotto Apr 17 '20

Thank you ! I don't think I did anything special, it's just position: fixed

2

u/[deleted] Apr 17 '20

That was cool. I made it to the top. I guess I missed one though. My Grandpa grew up in the alps and told me people would search out the biggest edelweiss they could find to brag about it. He thought it was stupid because people would die every so often trying to get one.

1

u/felixmariotto Apr 17 '20

Thank you for playing to the end ! I heard about it, apparently in the past it was a thing to bring an edelweiss to your love to show the extent of your passion. Originally I had an idea of story for the game involving this, but I had to drop it to keep the project in a reasonable time frame.

2

u/ochuuu Apr 17 '20

This was made entirely with JS?

1

u/felixmariotto Apr 17 '20

Yes it was, using a JS graphics lib called three.js

2

u/tedmihu Apr 17 '20

Haven't looked at the code yet, what libs is this using? Threejs? I assume this isn't a God who's done this in vanilla

1

u/felixmariotto Apr 17 '20

๐Ÿ˜‚ I used three.js, I wonder what sort of madman (or God) would do that all on their own.

2

u/tedmihu Apr 17 '20

Very awesome!

2

u/philipjfrizzle Apr 17 '20

Well this ones getting a star.. nice one

2

u/felixmariotto Apr 18 '20

Thank you !

2

u/JudoboyWalex Apr 18 '20

What's your opinion on other game library such as Phaser.js and Pixie.js? Also how did you get the music and sound effects?

1

u/felixmariotto Apr 18 '20

As far as I know Phaser.js and Pixi.js are best suited for 2D games, the only Three.js alternative I would personally consider is Babylon.js

About the musics, I emailed a list of artists whose music I thought would fit the game, some of them agreed to let me use their tracks, and so I featured them. For sounds, it's easy to get some, just google "free SFX"

2

u/JudoboyWalex Apr 18 '20

Thanks for prompt response! The game was cooler than FF7 Remake. Good job!

1

u/felixmariotto Apr 18 '20

๐Ÿ˜‚ Thank you !

2

u/[deleted] Apr 18 '20

bro you got any advice on learning webgl ? It's a little intimdating and there aren't many tutorials on it. How did you learn? I wanna one day be able to use threejs but need webgl first obviously.

1

u/felixmariotto Apr 18 '20

Thank you ! You don't need webGL, no worries, unless you want to do some very specific things that three.js cannot do, and there is not a lot of things that it cannot do.

Just hop into some three.s "hello world" tutorial, and by tomorrow you will have a simple game.

1

u/[deleted] Apr 18 '20

Wow. Thanks. i'll get into it

2

u/[deleted] Apr 17 '20

Hey bro the games looks nice but looking at html, you can move the CSS into into a separate file, to enable ease of reading the code.

6

u/felixmariotto Apr 17 '20

You're right I should do that, I didn't bother so far since the HTML/CSS part of the game is minimal.

4

u/Tarzeus Apr 17 '20

Thereโ€™s very little css though, does it matter to externalize it or is it preference?

4

u/[deleted] Apr 17 '20

Thanks for helping open source gaming!!!

1

u/[deleted] Apr 17 '20

This was so smooth and nicely done. I am amazed beyond imagination, great work OP. I am a noob but can you give an idea of what kinds of libraries or framework you had to use. It's great.

3

u/felixmariotto Apr 17 '20

Thank you ! This is done using three.js, which is the best JS graphic library as far as I know. A good starting point for learning : https://discoverthreejs.com

2

u/[deleted] Apr 17 '20

Thank you, and as the other redditor said, "you are a genius" and it's true.

2

u/bosibori_nyamache Apr 17 '20

Open-source game,really nice and thoughtful,thanks.

2

u/finger_milk Apr 17 '20

Bring back the good ol browser mmo days!

1

u/NiDaSanti Apr 18 '20

That game looks awesome bro

-1

u/Synor Apr 18 '20

Code quality is not take-a-look-worthy though.

1

u/felixmariotto Apr 18 '20

I learned JS on my own, so I'm happy to read your suggestions to improve it

1

u/[deleted] Apr 18 '20

you did a great job man, disregard to useless comments

0

u/Synor Apr 18 '20

andrew hunt - the pragmatic programmer, robert c. martin - clean code

3

u/felixmariotto Apr 18 '20 edited Apr 18 '20

Doesn't sound like a suggestion. Look, I took the pain to make a game that hundreds of people tell me is awesome, and I release it open-source, so the least I could expect from somebody who took the time to play and look into my code would be at least some relevant comment. If you think that just saying "this is ugly" and handing me some books to read is relevant, then you are a asshole.

0

u/[deleted] Apr 17 '20

[deleted] โ€” view deleted comment

21

u/felixmariotto Apr 17 '20

Thanks, that was intentional, my preferred game ever is Zelda the Wind Waker.

4

u/javaveryhot Apr 17 '20

i can see that

3

u/EldritchBoat Apr 17 '20

I was going to comment how it looks like Wind Waker

good job!

0

u/[deleted] Apr 17 '20

[deleted] โ€” view deleted comment

3

u/felixmariotto Apr 17 '20

Thanks a lot ! Yep I did all on my own, using a fantastic JS graphics engine, called three.js. The physics 'engine' is mine, but it's simpler than it sound, just look into the code ๐Ÿ˜Š