Logic for Cobrinha game

Asked

Viewed 1,009 times

1

Hello I’m wanting to make a game of the C cover using the curses library, I started, but I’m not finding a logic to draw the Snake on the screen when the user presses the arrows, I want to know what would be a logic to draw-It was on the screen according to the keystrokes pressed. I don’t know if my doubts are too clear.

1 answer

2

With a brief search, I found some tutorials on the net.

Brief explanation:

You hold all snake units on a list.

There is head and tail, which are the first and last elements of the list. So it’s really a queue.

At each moment, determine the direction in which you must move. For example, if the direction is left, then coordinates of the next head will be in (-1.0) relative to the current head. Insert new unit in the list at head position with coordinates previously determined.

Remove the tail unit from the list (on the screen). That will organize the movement. If you find a food in the head position, start a growth counter. At each instant, countergrowth > 0, decrease it and ignore the tail unit removal. Thus, only the head will move until it grows.

references: https://stackoverflow.com/questions/28471293/moving-snake-logic-in-processing

https://gamedev.stackexchange.com/questions/33786/snake-game-logic

http://www.codeincodeblock.com/2011/06/mini-projet-snake-game-in-c.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.