Giter VIP home page Giter VIP logo

snake's People

Contributors

comradesmith avatar ls-cam-smith avatar

Stargazers

 avatar  avatar

Watchers

 avatar

snake's Issues

Pause is broken

Recently changed to use event system, and tri-state game state variable.

Worked earlier, may have broken with subsequent tweaking of something...

Mice objective

just like fruit, but worth more points and they move randomly every 3 or 4 ticks

Package

Either as a gem, or perhaps as a bundled application including a Ruby interpreter.

To consider: Event based architecture

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:

  • scoreboard
  • regenerating fruit
  • sounds
  • game reset / initialisation

Fast players may have some keypresses dropped.

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.

Moving windows is sluggish

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.