Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Options for collision detection with Snake Game?

    Comments & Feedback
    2
    3
    205
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Tratax
      Tratax F last edited by Tratax

      Hi All, First post here

      I'll be creating a Snake clone as my first F4NS project and am stuck on the best approach for collision detection

      I have done this previously in QBasic by creating the Snake as a 2D array then mapping each trailing x,y position as the snake position updates then compare the "head of the snake" against all other positions in the array to check for collision.

      Overly engineered? Is there an easier way to do this? I've been wondering if there is a getcolor function as it will be black n white to start with

      Thanks

      1 Reply Last reply Reply Quote 0
      • N
        Nisse5 F last edited by Nisse5

        FUZE4Switch is fast enough to work with quite well your current method. The snake will only move a couple of times each second.

        If you want a method that doesn't get "slower" when the snake gets longer, I would suggest a boolean grid for all the cells on the screen. The the head enters a new cell, the value in the boolean grid is set. When the tail leave a cell, the value is set to false. Checking against that boolean grid would result in an equal performance in the algorithm, regardless of the length of the snake.

        (EDIT: Booleans are integers in FUZE4Switch.)

        1 Reply Last reply Reply Quote 1
        • Tratax
          Tratax F last edited by

          Hey Nisse5, Thanks, that's a great idea.. I'll give it a go

          1 Reply Last reply Reply Quote 0
          • First post
            Last post