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

201–210 of 285 posts

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

#201

Earlier quoted context omitted.

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?

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

#202

Earlier quoted context omitted.

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.

Maybe the compass gives you noisy absolute information which is ok, but combined with accurate relative information from the gyroscope and accelerometer is better?

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

#203

Snowcrash mode :) (In console): setInterval(function() { hero.x = powerUp.x; hero.y = powerUp.y; }, 50); setInterval(function() { hero.x = reward.x; hero.y = reward.y; }, 100);

I... definitely did not just watch this play itself for like five straight minutes...

I think I need to get more fresh air or something.

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

#204

Earlier quoted context omitted.

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.

My brain hurts just imagining this.

Mine too

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

#205
post #77

I love that the red block doesn't understand the concept of wrapping. It reminds me of playing with my dog.

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.

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

#206
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.

> 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.

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

#207

Earlier quoted context omitted.

My only complaint is the global scope pollution with the top-level variables and lack of ‘var’ for those. But other than that, I agree.

That's a complaint about the JS language itself, that variables are global unless otherwise specified.

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.

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

#208

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!

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)

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

#210

Snowcrash mode :) (In console): setInterval(function() { hero.x = powerUp.x; hero.y = powerUp.y; }, 50); setInterval(function() { hero.x = reward.x; hero.y = reward.y; }, 100);

I did the same, but played around a bit more and made an "AI" mode:

  maxScore = 0;
  setInterval( function() {
  	if (score > maxScore) {
  		maxScore = score;
  	}
  	if (distance(hero.y, hero.x, ennemi.y, ennemi.x)  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

Post reply on HN