Search code examples
carraysavr

Reading sprite x/y location from array 3 steps ago C


I'm implementing a snake game in C. The snake array is made up of 3x3 sprites. The head of the sprite moves in increments of 1. I'm wondering how I would go about storing the location of the head 3 steps previously so I can then set the next sprite in the array equal to that location and so forth down the length of the snake


Solution

  • move()
        back3 = back2
        back2 = back1
        back1 = current
        current = ??
    

    You could also try a circular buffer with moving pointers. That way you won't have to do all that copying. It's a little harder to implement and debug, though.