Code Monkey home page Code Monkey logo

sf-snake's People

Contributors

fishies avatar

Watchers

 avatar

sf-snake's Issues

Vertex arrays

Would it be better to draw using sf::VertexArray?

(Maybe data representation might also only keep vertices of the snake rather than every block... but computation would not be as consistent; a player who changes directions more often would have a more computationally expensive game. Not sure if this second idea would be better in every scenario. For which scenarios do I want to optimize?)

Music and sound

The game currently lacks music and sound. Such critical components of any properly polished game should not be neglected.

Configurable settings

Allow the player to customize game options such as keybinds, size of level, speed of game. This may require a menu screen.

Rewrite PlayerPiece logic to make gameplay smoother

Currently when the player selects a direction to turn, input is locked until the next frame. Therefore at times the game's controls will feel unresponsive. The proposed solution is to replace input locking with a Direction variable that always accepts input deciding what direction the snake will turn in the next step (so actual direction change is not processed until the start of the next frame).

Use C++11 RNG

Currently sf-snake uses cstdlib's rand function, even though this is supposed to be a C++11 project. The C RNG in this code should be replaced with C++11 library function(s).

Reduce space complexity of tail

Currently the game's collision checking logic is O(1) due to use of a hash set. However, the hash set is used alongside a queue for O(1) tail growth/movement. Therefore the space complexity is O(2n) -- still linear, but is it good enough?

We can eliminate the need for a queue with some changes to what we put into the hash set; we want to track the "age" (that is, the game tick number on which the tail block was generated) of each tail block and pop off the oldest one with each step.

So we want to:

  • Keep O(1) collision.
  • Track "age" of tail blocks.
  • Be able to check for "oldest" block in O(1) time.
  • Account for overflow in "age" variable.

Proposed solutions:

  • Perhaps we can change unordered_set to unordered_map with coordinates being the key and age being the value? Would run into problems when checking for oldest.
  • Hash a single value containing data of age and location? Would run into problems checking for collision.

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.