Show HN: Looptap – A minimal game to waste your time
161–170 of 183 posts
Re: Show HN: Looptap – A minimal game to waste your time
#162Earlier quoted context omitted.
Thank you! I didn't peek and ended up with the same solution as you, so for an extra bit of fun I tried to golf it to be as short as possible. There's probably room for much improvement: (94 chars) setInterval("l=loopTapApp;b=l.getBallAngle();a=l.arc;b+6>a[0]&b-6<a[1]&&l.tap(new Event(1))")
This entire comment thread is hilarious
Re: Show HN: Looptap – A minimal game to waste your time
#163One of my favorite things to do with these neat little games is to build something that plays them for me by just pasting stuff into the browser JS console. https://pastebin.com/aTYuaNVS At a score of 1,619 the ball is moving so fast it no longer works! I switched to a new tab (hoping that the event loop would be sent to the background/context switch/whatever) and ta-da - it misclicked. High score of 1,637.
You beat me to it, haha, This is what I just did: function intersectRect(rectA, rectB) { return !( rectB.left >= rectA.right || rectB.right = rectA.bottom || rectB.bottom const arc = document.getElementById("arc"); const ball = document.getElementById("ball"); setInterval(() => { if (intersectRect(arc.getBoundingClientRect(), ball.getBoundingClientRect())) { window.dispatchEvent(new KeyboardEvent('keypress', { keyCod…
Re: Show HN: Looptap – A minimal game to waste your time
#164Re: Show HN: Looptap – A minimal game to waste your time
#165Re: Show HN: Looptap – A minimal game to waste your time
#166Re: Show HN: Looptap – A minimal game to waste your time
#167Re: Show HN: Looptap – A minimal game to waste your time
#168Re: Show HN: Looptap – A minimal game to waste your time
#169There might be a bug. I “died” but the ball appears in the live zone https://i.imgur.com/XJdKgDL.png . Happened to my partner too.
Re: Show HN: Looptap – A minimal game to waste your time
#170Earlier quoted context omitted.
Oh neat! You did the Harder version and didn't use the game's own code to check it. I find that with JS games it's better to imitate the game's exact logic and call it's functions to make sure the state is working/updates correctly. Of course, for how delightfully simple this one is, your approach is definitely faster/better!
Definitely seems like alfon's solution is faster/better, as it's more accurate when the game speeds up. However, it's also more resource intensive! getBoundingClientRect (used to at least, long time I go I did browser performance stuff) forces a new layout calculation each time it's called, which is one of the most expensive things you can do in the DOM, and can lead to jank in the website. Some more information here…
So calling it 100 times in a loop should be fast, but calling it 100 times in a loot that also updates the DOM should be cripplingly slow.