Live data from Hacker News

Show HN: I taught my little brother JS, and he made this videogame in a week

s-poony.github.io

251–260 of 285 posts

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#251
post #218

Earlier quoted context omitted.

Really well done and I like the brevity. Here are some ideas for revising the code: 1. There are two functions called "distance" and they're identical. Only the outermost appears to be needed. 2. As written, the game places variable and function names into the global scope. It doesn't matter for this game, but will be a problem for larger games. One idea would be to use the Immediately Invoked Function Expression (II…

Also never use Math.pow for squaring numbers (used in the distance function) because it is significantly slower as it is designed for abitrary real exponents, not just integer ones. Cannot be learned soon enough IMO :) Still a very good job for just a week of coding though.

Does the JS JIT not handle this? Seems like it would be incredibly trivial...

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#252
post #218

Earlier quoted context omitted.

Really well done and I like the brevity. Here are some ideas for revising the code: 1. There are two functions called "distance" and they're identical. Only the outermost appears to be needed. 2. As written, the game places variable and function names into the global scope. It doesn't matter for this game, but will be a problem for larger games. One idea would be to use the Immediately Invoked Function Expression (II…

Also never use Math.pow for squaring numbers (used in the distance function) because it is significantly slower as it is designed for abitrary real exponents, not just integer ones. Cannot be learned soon enough IMO :) Still a very good job for just a week of coding though.

> Also never use Math.pow for squaring numbers (used in the distance function) because it is significantly slower...

Modern JS engines optimize hot functions at runtime - advice like this won't affect actual performance.

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#254
post #9

That's cool, also similar idea to a game I made some time ago for a lisp game jam https://orbaruk.github.io/ https://github.com/OrBaruk/squares-lgj

Your game is faster paced, I like it. One issue I noticed is that the red blocks can spawn right in front of your block, making it nearly impossible to avoid. Rage quit inevitable.

Yea, that was an issue that I skipped over and never got around implementing a fair enemy spawn

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#255
post #128

Nicely executed game. But looking at the source, the weird part is that it is half English, half French. It definitely doesn't look like the work of a single person. I also looked at the commit history and I liked the teaching comments. Clearly, there is a story behind that code. I suspect you did the first part together (moving square, ...) and that your brother played with it by himself later, adding the enemy, etc…

My code when i was kid was half english and half swedish, heck even today when i write simple "run once"-code they often have some swedish named variable. Funny story from ~2005, a company developed a jvm for a special cpu and was aquired by a bigger company. After the aquasition 2 developers had to search the code base for two weeks after swedish swear words, they replaced them with the word of dandelion in swedish…

Yes, I've done it too (I am a french native). Especially common is writing code in English and commenting in ones native language. There are other cases, like when the english word is not known or to stay consistent with a data source.

I've also seen the native word to avoid conflicts, like adding "2" at the end of a variable. That's bad, don't do it kids ;)

But here, the "hero" has a "speed" while the "ennemi" (french for "enemy") has a "vitesse" (french for "speed"). That's why I thought that the enemy is more likely to be a later, less supervised addition.

And BTW, I didn't notice any french swear word in that code. That kid is more mature than I was :)

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#256

Earlier quoted context omitted.

...wait, how do you get orientation relative to things around you (rather than just your own previous orientation and gravity) from just gyro/accelerometer data + location? If you do have some source of absolute orientation, like a compass, surely you just use that and don't need the gyro.

That's a good question. I suppose it may be possible to use GPS data to estimate the phone's absolute heading. I just took a quick look at https://developer.mozilla.org/en-US/docs/Web/API/Detecting_d... , and it seems to provide orientation, and not angular velocities. So it could also be that browser implementations fuse magnetometer and inertial sensors to produce the orientation estimate. Is there another gyro API…

[deleted]

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#257

Hasn’t been mentioned before: try this on a phone. It uses the gyroscope for control and it quickly becomes second nature to balance/guide the square around the screen. Also a very nice and rewarding discovery process, as it starts out with squares speeding by, until you realize it’s the tilt of your phone that is causing it. Congrats, super fun!

Or your Macbook Pro if it originally came with an HDD. Apparently the device orientation API can utilize the triaxial accelerometer that Apple used for drop detection. Really neat experience tilting my laptop around like a mad man.

Can confirm that HP Probooks had the same accelerometer in 2011-2014. Win8 used it for screen orientation OOTB.

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#258
Simple game design really is a beautiful thing. You find a mechanic that is fun to noodle with (like the slippery control logic), throw in a hook to get people ("oh look! a green square!") and then you can refine and refactor into a billion different permutations.

My favorite part about this was how the red square would get faster in bursts. It was like the baddie was getting increasingly exasperated about his whole damn situation.

Re: Show HN: I taught my little brother JS, and he made this videogame in a week

#259
post #221

Earlier quoted context omitted.

I do agree it’s a complaint about the language. However, I think it does ultimately fall on the developer to know how to work with the language including the bad/ugly/awful parts. I also think not polluting the global scope is a pretty foundational thing to know or be aware of. It’s really easy to shoot yourself in the foot or have naming collisions/overwrites happen if you aren’t careful. Another example would be me…

> However, I think it does ultimately fall on the developer to know... This person has been programming for a week. I think we can let this slide

Well, no - not if everyone's raving on about how great the code is. Code quality is objective, not dependant on experience.

I don't get to write crap code at my work if I'm inexperienced, I have to learn to write good code.

Post reply on HN