ls-cam-smith / snake Goto Github PK
View Code? Open in Web Editor NEWClone of the classic game Snake, written in Ruby with Gosu
Clone of the classic game Snake, written in Ruby with Gosu
Recently changed to use event system, and tri-state game state variable.
Worked earlier, may have broken with subsequent tweaking of something...
just like fruit, but worth more points and they move randomly every 3 or 4 ticks
put a movement handler on the player, and have main game call that instead of directly setting the facing attribute.
use sqlite maybe?
Either as a gem, or perhaps as a bundled application including a Ruby interpreter.
1, 2, 3, have a thing to show the current speed.
Could make an enum of common events like fruit generated
fruit picked up
snake collision detected
etc.
Then write an event dispatcher which methods/functions can assign themselves to as a listener eg
def play_pickup_sound(event_context)
@sound.play
end
# think notation for passing reference to function is different, &play_pickup_sound ?
EventHandler.register(Events::FRUIT_PICKED_UP, play_pickup_sound)
The register method would add the method reference to a list, and when the event is fired, all handlers called one by one with the event context (a hash of details, e.g. x,y coords (this means in the future it would be easy to extend the sound handler to pan the sound left and right in response to gameplay!))
Where I see this being useful:
In order to solve #4 I put in a basic flag to prevent fast players turning to an allowed direction, then to the opposite facing before the end of the tick.
The flag blocks input until the next movement tick is completed.
However I think a better solution is to keep track of the facing from the last movement, i.e last_moved_facing
and prevent switching to the opposite of that.
This is because I am using sleeps in a single-threaded application, instead of checking a timer in the update
method of the game object.
just to make debugging, reading, and tracing easier.
make like tron basically
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.