Show HN: I taught my little brother JS, and he made this videogame in a week
s-poony.github.io
s-poony.github.io
This is awosome on mobile!
And asking people to comment on the issue to say that they shouldn't be removed would not be helping the discussion, because that point has already been made in the thread by at least three people that I count.
I think it needs some sort of prompt about the tilting. Also the mechanism might need some calibration, I tested it with my SO and the tilting was too sensitive for her to control it accurately.
But as long as it's only for actively open apps and web pages I don't really see much harm.
That's how I spend 10-ish% of my time on Hacker News
https://bugs.chromium.org/p/chromium/issues/detail?id=421691
Browsers have added rate limiting to mitigate this threat. (Prior to that, my former team in Google Ads added our own rate limiting to the gyroscope API we provided for ads.) The risk now seems pretty minor, but I wouldn't be shocked if someone clever still managed to find some way to abuse it.
Whaaaa?
Know what you are typing: https://www.newscientist.com/article/mg21128255-200-smartpho...
You can also determine things like health and other physical characteristics, similar to gait detection.
If you do have some source of absolute orientation, like a compass, surely you just use that and don't need the gyro.
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?
EDIT: I should add that both the HDD Macs I owned (a 2009 Macbook Pro and a 2004 or 03 Macbook) had accelerometers and I found a cool app for oldest that made a lightsaber noise. This was pre smartphones, so it was novel. My Late 2013 Macbook Pro does not seem to have one.
In fact, I didn't realize that the gyro worked in both dimensions! I thought it was just a fast downward fall and it was actually hard to hit the red block since it kept moving. Then I found out you could lay the phone flat and slow the green block down and it was way more fun!
I like the concept and could see a more complete game making a ton of sense.
[1] https://github.com/S-poony/Ultra-Square-Catcher-USC-/blob/ma...
Don't want to be the killjoy here but isn't line 77-79 the same as 85-87? With the rest I can agree.
Our company needed an internal tool, and they wanted remote access to it, but it was basically just a tool to generate a file based on a few inputs. We already had a command line program for it, so I wrapped it up in a web server and had it take input as a form input without any JS. It worked great for years, and then someone got tasked with updating it (mostly just combining it with other tools). He couldn't figure out how it worked, so he rewrote it to use a ton of JS, using Angular and other stuff. And guess what? He took longer to rewrite it than I spent the first time and made no functional changes besides some CSS and a ton of JS.
With all these fancy new frameworks and browser features, it seems that many developers have forgotten (or never learned) how to do things simply. Frameworks and browser features have their place (I built an interactive HTML5 app as my first project at that company), but they're often completely unnecessary.
If you need a one-off page that does a little dynamic stuff? Drop in jquery+bootstrap and a little wiring js and be done with it. Not a huge fan of the size of jquery + bootstrap, but it's a fast path to done depending on your one-off needs.
Another example would be memory allocation/freeing in a non-GC language. Sure, it’s a pain that I have to deal with it, but it’s still on me to make sure my application works in the language I’ve chosen and doesn’t leak memory all over the place.
This person has been programming for a week. I think we can let this slide
I don't get to write crap code at my work if I'm inexperienced, I have to learn to write good code.
I was more thinking of Assassin's Creed and Far Cry when I wrote that comment.
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 (IIFE) pattern [1]. Another would be to take advantage of ES6 modules[2] (<script type="module">) to limit variable scope.
[1] https://developer.mozilla.org/en-US/docs/Glossary/IIFE
[2] https://www.contentful.com/blog/2017/04/04/es6-modules-suppo...
Still a very good job for just a week of coding though.
Modern JS engines optimize hot functions at runtime - advice like this won't affect actual performance.
That's not actually the impressive part of the code though so it remove nothing from him.
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...
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 ("maskros").
What I want to say is that it is very common to mix english and ones native language.
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 :)
To me it smells like karmafarming. How is everyone buying this? Where's your reasonable doubt?
...I'm having a strange amount of trouble describing what I'm doing, but there's a strategy to avoid this that I got the hang of after a few rounds. Basically, you can't move too fast at the moment you're collecting the green squares.
The red block turning up later was AMAZING.
This really is a fantastic little game.
By the way, if you're interested in making your own tile based RPG game, I'm developing some tutorials to help you learn how: https://codeorc.com/learn-web-development-by-programming-a-r...
Watch out for the red block ... took me some time to realize it's a 'bad' block which subtracts from your score when touched.
I especially like how it lets you build up enough of a score before introducing the red block so that if you hit it a few times you are still in the game and the only setback was some time!
I think with some additional effects on the score (like some red flashing and showing it remove the score) when hitting a red one and it would be a lot easier to understand very quickly that it's bad.
Maybe learn arrays if he wants to enter the realm of Robotron enemy count... :)
It felt fun to explore and learn what it is
Move arrow keys or tilt your phone. When I pulled this is on my phone, I thought it wasn't working until I saw that someone mentioned that tilting it worked.
I'm super impressed, despite (and because of?) how simple it looks.
How old is your brother? Has he programmed before? The code doesn't look like what someone with no programming experience could do in a week (unless perhaps working from a similar example as a starting point).
Like most everyone else, I was impressed. Way more interesting than I first thought possible with such a minimal game. The little red guy made the difference.
Only criticism I would say is to add some directions if possible, even though for most people it's common sense it took me a little while to figure out I needed to use my keyboard :P.
Great job!
I think I need to get more fresh air or something.
maxScore = 0;
setInterval( function() {
if (score > maxScore) {
maxScore = score;
}
if (distance(hero.y, hero.x, ennemi.y, ennemi.x) < (vitesseEnnemi * 15 + 30)) {
hero.y += (hero.y - ennemi.y) * speedLimit / distance(hero.y, hero.x, ennemi.y, ennemi.x);
hero.x += (hero.x - ennemi.x) * speedLimit / distance(hero.y, hero.x, ennemi.y, ennemi.x);
}
if (spawn > PowerUpspawnRate) {
hero.y += (powerUp.y - hero.y) * speedLimit / distance(hero.y, hero.x, powerUp.y, powerUp.x);
hero.x += (powerUp.x - hero.x) * speedLimit/ distance(hero.y, hero.x, powerUp.y, powerUp.x);
} else {
hero.y += (reward.y - hero.y) * speedLimit / distance(hero.y, hero.x, reward.y, reward.x);
hero.x += (reward.x - hero.x) * speedLimit/ distance(hero.y, hero.x, reward.y, reward.x);
}
}, 25);
It's oddly fun to watch the little green guy pull off some sick dekes.If you want your green guy to flat-out avoid the enemy, just wrap the second set of conditions there in an else block.
edit: Formatting for readability/copy+paste
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.
This demo reminded me of this tutorial livestreamed a few weeks ago: https://youtu.be/Z3OnwkPOfY4
While your brother's demo adds more advanced input and gameplay elements, I'm just curious whether it helped inspire him.
PS: J'espere qu'il gardera cette curiosite et cette envie de creer!
I hope to inspire in my own kids something you have shared with your little brother. A true gift!
Thank you for sharing.
If you hold an arrow key and then hold brake, the square will slow down but then speed up briefly and finally slow down for good.
Seems pretty basic enough in the beginning, but then turns into a serious predator/prey challenge and involves a lot of hand/eye coordination.
when I was 11 an online friend showed me a "game" he was working on using VB6. There was a little star you moved across the screen by clicking buttons for u/d/l/r. His end goal was a top-down RPG.
Seeing projects like this always hold a special place in my heart. Best of luck to your brother. I hope his passion grows and he does amazing things
The mechanics in this are really well thought out! Great job!
Are you guys from Québec or Europe? I noticed the french comments in the source code hehe
Also notice the GH repo, it has 43 commits.
Bien joué Noé :)
It's definitly a fun little game, I love the simplicity of the code with regards to dependencies. If you look through the code, you can also find that the shift key acts as a brake, definitly not something that is very discoverable.
I wish there were more ways to control the green square, the arrows keys on my touch bar macbook pro are pretty bad and my hand began to cramp a little bit.
maybe dumb question - where's the link to the source code? adding that to the actual page would be great.
It’s canvas based. Interesting choice as a starting point of a learning path.
He is 15. I should have written younger brother and not little brother; english is not my native language.
How did you teach your little brother?
Doesn't work on current Firefox.