graue / dumbbell Goto Github PK
View Code? Open in Web Editor NEW"Snake"-like game with a twist
Home Page: http://toxicsli.me/dumbbell/
"Snake"-like game with a twist
Home Page: http://toxicsli.me/dumbbell/
Killing yourself by turning 180ยฐ is supposed to be prevented, but you can still do it. Assume you're going left. Quickly press down or up followed by right. If game logic hasn't run in between the two key-presses, you don't move vertically and so run into your tail right away.
To fix this, we should save the direction that was last advanced in (by a pixel or more after flooring), and disallow turning in the opposite of that direction.
This would be a good feature for Dumbbell or really most games. Nice to have in a framework.
requestAnimationFrame isn't guaranteed to call our callback every 1/60th of a second. We should measure how many complete frames have passed and advance the game state accordingly, so dropped frames don't make the game slow down.
With the new ticker logic that fixed #1 and #3, I introduced a new bug: if we run multiple ticks at the time, and in one of those ticks you get a game over, we cause multiple game over dialogs or other buggy behavior. This happens because the ticker logic doesn't account for @snake-speed
(which determines how many ticks have passed!) changing midway through processing ticks.
If I don't plan to ever change the snake's speed, I can make it a constant and add a proper game-over flag instead of the hack of setting snake speed to 0 when you die. Otherwise, the proper fix is probably something like a loop, recalculating number of ticks to process after each tick runs.
I can trigger this multi-game-over-dialog bug in Firefox by switching to another tab, waiting 5 or 10 seconds, then switching back. Having the tab inactive apparently suspends requestAnimationFrame callbacks, so when we switch back, a whole bunch of ticks are run at once. (Which also causes a bit of lag, maybe a problem in its own right. A fix for that would be to detect when the tab becomes inactive and pause the game. In fact, I'll file issue #5 about that after this.)
Add scores to the game and display them somewhere. Probably something like 1 point for every pixel you advance, 100 points when you get a dumbbell.
With a ClojureScript version bump I now get this:
WARNING: cljs.core/-, all arguments must be numbers, got [js/Date nil] instead. at line 129 src-cljs/dumbbell/main.cljs
In reference to (- new-time last-time)
in ticker
. I think the nil
part of that error may be a ClojureScript bug as it just does not know the value of last-time
(but does know new-time
has to be a js/Date
). But is it correct that I shouldn't rely on subtracting Date objects? Maybe an explicit call to .valueOf()
is the way to go here.
Turning on advanced optimizations breaks incremental recompiling. ๐ But the advanced optimizations are kind of crucial for "deploying" to http://toxicsli.me/dumbbell/ because they make the JS file (currently) 124KB instead of 800 some. I've been going in and changing the project.clj, building, then changing it back but I think lein-cljsbuild has a feature to specify multiple builds. I should use that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.