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.
My understanding was that the accelerometer was there to stop the drive in case of a fall. You wouldn't need that with an SSD, though perhaps if it still had an optical drive?
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.
What would one feasibly do with this data? I guess an app could tell if someone is holding their phone in their had, and maybe put together a pedometer bases on gyroscope input. Maybe a concern if a app has access to gyro input over a period of days.
But as long as it's only for actively open apps and web pages I don't really see much harm.
With sufficiently high-frequency gyroscope data, it is possible to infer what a user types in with moderate precision. In some cases, it has even been shown to be possible to recover coarse audio data from the surrounding environment.
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.
Facebook has a patent for using gyroscope data in conjunction with location to know who you are facing with other people around to enhance friend suggestions.
You can also determine things like health and other physical characteristics, similar to gait detection.
...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?
Maybe the compass gives you noisy absolute information which is ok, but combined with accurate relative information from the gyroscope and accelerometer is better?
The gyroscope is a datapoint that can be used for fingerprinting. Plus it gives quite a bit of information about you: whether you are lying down, sitting, walking, etc.
doesn't this assume the user is walking around with the page open, the front tab, and the phone unlocked for a reasonably long period? which websites do I spend enough time on for that to be true? I don't generally walk and read
If the mouse cursor is outside the browser window, sure. Gyroscope data is relatively personal and not easy to modify, so it serves as a much better tracking tool than the mouse cursor.
GP meant that Safari doesn’t ask for permission to use the accelerometer. In that sense, it can’t have worked just fine for you since Safari doesn’t have that as a privacy option.
My thought exactly. Totally surprised me. I thought the only inputs a web site could get from me from hardware without asking permission is key presses and cursor movement.
Good call. I'm impressed they implemented it that way. It's hard at first, but once I got used to the sensitivity, I found the mobile version of this game a lot easier to use than the desktop one.
Yeah, that was super cool. I'm a little annoyed that you can't lose (red block goes away under 10 points), but it was way more fun on my phone.
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.
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.
Nitpick: It's not just the gyroscope. DeviceOrientation (at least on the iPhone) uses blends both the accelerometer and gyroscope (and if specified, the compass too)
The APIs powering this are in the process of being heavily restricted or removed altogether -- if you think games like this should exist, you should voice your concern here: https://github.com/w3c/deviceorientation/issues/57.
That comment does not say the APIs are in the process of being removed.
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.
Since it's GitHub, just add a thumbs up or whatever to the comment in question, don't just add me too comments. That's the way I've seen voting work best in GitHub.
It seems to me that gyroscope data is merely input, rather than personal data. In other words, I'm not sure asking permission before accessing gyroscope data makes any more sense than asking permission before accepting touch screen input. Or for desktop applications, asking permission before accepting keyboard/mouse input.
And it's also more concerning from a privacy perspective since it's the position of something outside of the app (the phone) instead of inside of the app. Mouse coordinates work this way (only get cursor updates within your browser tab content area), so it makes sense to require permission from the user before accessing it.
Look at the code guys [1]. I love it. This is simple. There is not a single line of bullshit. I hope he gonna become a great programmer and continue to make beautiful code like that.
Agreed. There are so many JS projects these days composed of a dozen abstraction layers and barely-used libraries all mixed together and spread out across multiple files with an insanely complex "build system" on top, that it's very refreshing to see simple, self-contained JS.
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.
To be fair, in my experience rewrites always take longer regardless of technology choices. You are often reverse engineering requirements which is really consuming both in time and energy. That said, I agree with the point you're trying to make though (I strongly prefer software with less dependencies/frameworks)
Yes one should assume most frameworks will be dead 2 years from now. Dependencies problems suck. And create security holes. When development starts going into the cloud get ready for a lot of pain the world has never seen before.
It depends on your needs... Are you building a complex application with several developers. You probably want a build system and module based JS. I prefer react + redux + material-ui. Some of the new stuff around hooks and context could displace redux for smaller apps easily.
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.
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 (IIFE) pattern [1]. Another would be to take advantage of ES6 modules[2] (<script type="module">) to limit variable scope.
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.
This advice is incorrect. Experimenting in the console in both Firefox and Chrome shows that there's not a significant speed difference between the two, even if you make sure you only call a given function with integers <10000.
On my laptop it is about 30% slower (tested with Firefox 64).
However I agree, this was not very good advice for someone who just started programming with JS...
Definitely great job. Reminds me of when I taught my physicist friend C and he wrote a raytracer and a game to demo it the next day. I had never witnessed so many trig functions used on a global context.
It's still a thing. On gamedev forums and subreddits you still have people assembling a team. Of course he can't do any programming, he's only an idea guy and needs 5 programmers, 3 writers, 7 artists etc.
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 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.
I’m not at all saying they should be an expert after a week. But learning those things is part of being a software developer/programmer and I don’t think, “Well the language sucks” is a valid argument.
As far as logic goes, I totally agree, but personal preference nit pick, from a code writer and reader perspective, I think all subproperty access (`hero.acceleration.x`) could be cached to a variable, or just operate on plain variables and assign property access after mutations and only manipulate objects as needed.
It makes the code easier to write and read, IMHO, and I believe older engines had infinitesimal changes in performance with updating objects, so it's more of a habit and code clarity thing for me.
Of course, that's far less important than the fact that the logic is clear and concise, especially after learning JS in a week :)
Sure, with a duplicate distance function and one 100-line function? For me that in itself is horrible lol. But as a new programmer he should still be commended but bro, give credit only to where its due. And here its the fact that he's new, not that the code is "beautiful". (You're making me doubt what you think of beautiful code, but i guess since he's your brother you're definitely biased.)
This is... really impressive actually. Such a simple mechanic, but well executed. I like how the red block concept is introduced to you after the first few points are scored. The details of the implementation are really impressive for a first project, or even for a game project in general tbh.
Anyone noticed that you can click the game board to go full screen. This kid is doing more with less than many developers do with years of training. I think he's got a career in programming ahead.
That it?
Presume I use the arrow keys
OK, I pick up the other blocks..
Oh, I do like the inertia
and the smaller points give me more points
wakes up screaming at 3am as the red terminator block endlessly hunts me down
I found as the speed to the red block increased that sticking to the edge of the screen worked quite well to lure the red block away from where I wanted to be.
The red block reminds me of the monster in the film "It Follows". It very slowly but relentlessly heads straight for you wherever you are. Surprisingly unnerving.
Wow... Thought I was going to play for 10 maybe 15 seconds... I've never played a game for that long... This is seriously good. If you released this game without "little brother" I would think this was one of those amazing minimalist games. Thank you so much for making this!!
I don't understand, am I missing something? You just pick up blue and teal blocks while a red block slowly chases you? Why are people so excited about this? I feel like I'm missing something.
For those of us who appreciate simple little distractions, this is a really fun and easy way to blow away a few minutes. It isn't that easy to build such intuitive but fun mechanics into a game, so it's impressive that a newcomer nailed it so well. Some people tend to require something more engaging or rewarding, and you might fall into that category. Definitely a different strokes thing.
I appreciate the minimalism of the game. It has the concept of progression down well. More captured blocks increases the speed of the red block, making the game more challenging as you progress. The friction of the movement makes the controls just the right amount of challenging.
The red block gets faster and faster, introduction of smaller squares worth ten points, it became quite a challenge for me to keep a score above 100 on PC with arrow keys.
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 ("maskros").
What I want to say is that it is very common to mix english and ones native language.
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 :)
It can also go the other way, of course (variables in native language, or just single-letter variables, and comments in English). I seem to remember that Linus Torvalds commented all of his code in English without ever thinking about it.
Even in a professional context it's reasonable to use the language your customer (business expert) is using. Beware of mapping technical terminology into another language! And if that means you write Swedish code, that's perfectly valid.
I've definitively had the case of having all the codebase in English (not our native language), since all concepts mapped easily, and then a new concept appears and damned if I know how to translate it! So now we're stuck with a single non-English term in the codebase, which is a blot on the whole work :(
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.
> One issue I noticed is that the red blocks can spawn right in front of your block, making it nearly impossible to avoid.
...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.
I stopped after about 60 points, but the fact that new block colors had shown up every dozen points or so made me want to get going for a while to see if there were any more mechanics.
I was actually going to ask what the rationale behind this was. I found that because of this, the best strategy was usually to wrap around to distract the block. I personally felt like the game would have worked better without that, although hard to know without trying it.
Could simply be that ignoring the wraparound is the naïve way to provide a direction for the red dot. Navigating a wraparound world is also unintuitive, so the player would be at a disadvantage if the enemy could take advantage.
I thought it was a really clever way to "teach" you about the game without having an actual tutorial (which I personally always hate).
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.
Nice game, shortly after I started it dawned on me... Because it allows wrap-around you can just hold down the up arrow key and it becomes more of a 1-D game and seemed easier to play. Then the red thing showed up and started getting in the way and I found it easier to use all the arrows again.
So fun. I like the AI logic, if he wants a fun addition he should add more enemies as the score increases and implement something like the pac-man ghost logic so that they all behave differently: http://gameinternals.com/post/2072558330/understanding-pac-m...
Very nice. I had fun with it. Maybe a little description of the goals on the page underneath the play area would be good? Took me a while to realize picking up the red squares was actually reducing my score. I initially thought they were just meant to be more challenging to pick up since they moved.
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.
Finally, one of these stories that didn't make me feel like an utterly talentless moron. This feels like what someone might be able to learn how to do in a week, but so often it seems like what you see here are 10 year olds writing real time ray tracing engines that use deep learning for some reason, and have source code that just happens to be a radiation hardened quine.
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).
Right click and view source is probably the best thing about the web. You can learn so much. The source code for this game is simple and straight forward. I find it hard to come up with any critique - it looks like it's written by a pro! I like that he use objects instead of "classes". The game should adopt to window resize and aspect ratio.
Very cool. Nice trick you guys did there with the lighter colored block, and the red enemy not being able to follow across the boundary. A lot of game developers I respect and whose games I've enjoyed started programming at a young age with simple tools which allowed getting their hands dirty. While javascript is a great language to do this, you might want to consider Game Maker Studio as well.
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.
Impressive, I wanted to make an RPG type of engine in Processing[0] and did similar, just made blocks that could move around based on keyboard input. Didn't continue on with it though.
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.
Wow I really enjoyed that! When I was still trying to "win" my eyes were watering like crazy because you just can't blink once the score gets high. Am I the only one who at some point got suicidal? You're like OMG I need a break and the only way is to start chasing the red dot. When I got back below 10 and the red dot disappeared I was like holy shit there is no way out! Felt like a great twisted ending to some intense psycho thriller. Also my right (arrows) hand is now aching.
A great reflection on both the quality of the teacher and the promise of the student. And I really liked all the subtleties captured in such simple code. Refreshing!
That's impressive. Can you provide more info such as how old he is, did he have any kind of programming experience prior, and how did you go about teaching him?
Of course I can. My brother is 15, he is smart and he had programmed before, but only on his calculator (in TI-BASIC, I think). He already knew the basics of programming. He got his first real computer for Christmas. I was with him at my parents house, behind his shoulder as we created the skeleton of the game together over a weekend. After that I left, and he kept adding features on his own.
Nice job, just an FYI it looks like movement speed is tied to refresh rate. I was having a difficult time at 144hz but lowering to 60hz made it way more manageable.
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.
You should show him nibbles - this was something I made in C when I was 17 or 18 - could be the next step in his production of this game! https://classicreload.com/qbasic-nibbles.html
Nice but damn long code block.
Maybe ask if he can break it up into smaller functions. Better to get him thinking about quality and reuse. Like that comments though, better than most code out there.
this is awesome, and very similar to what got me into dev.
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
there is a bug if you try to change direction by rolling over left and right at the same time or up and down at the same time. hitting uo/down together and left/right together when changing direction has a weird pause effect.
Il est en première. Do not underestimate the french education system ;) What you need for such a game are Pythagorean and Thales's theorems. I gave him hints so that he poses the problem correctly, but he came up with the formula for moving the red square on his own!
I think I got to around 65 points before the red square began catching up to me and taking away my points.
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.
Managed to get over 120. Because the red terminator can't cross the edges, but you can, the key is to use the edges as much as possible and to avoid going through the center unless you are lined up to get the food.
i was 7 when i programmed on a commodore 64... and walked to school in 1 foot of snow... (kidding on the last one) sorry but he's not little but nice game.