how to move the Snake..

Hi guys. I'm currently having a problem on how to move the body of the snake by means of "bending" the body. I just finished making an infinite loop for the snake to make the snake move by itself. How can I control or change the directions of the snake? Need your help here guys. Here's my code btw. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <windows.h>
#include <conio.h>

#define LEFT 75
#define RIGHT 77
#define UP 80
#define DOWN 72

     int x = 0;
     int y = 10; 
     char option;
     char keyPressed;
  
void gotoxy(int x, int y) 
{

	   //initialize coord
	   HANDLE hConsoleOutput;
	   COORD Cursor_Pos = {x, y};
		//Set the position
	 hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleCursorPosition(hConsoleOutput, Cursor_Pos);
}
// clear screen
void clrscr()
{    system("CLS"); 
}

void horizontal()
{
      int game = 0;
      
      
      while(game != 1)
      
      {             x++;
                    gotoxy(x,y);
                    printf("*");
                    gotoxy(x+1,y);
                    printf("*");
                    gotoxy(x+2,y);
                    printf("*");
                    
                    gotoxy(x+3,y);
                    printf("*");
                    sleep(50);
                                 clrscr();
                    
      
      }
     
     
     
     }


void vertical()
{
      int game = 0;
      
      x = 0;
      y = 0;
      
      while(game != 1)
      
      {          
                    y++;
                    gotoxy(x,y);
                    printf("*");
                    gotoxy(x,y+1);
                    printf("*");
                    gotoxy(x,y+2);
                    printf("*");
                     
                    gotoxy(x,y+3);
                    printf("*");
                    sleep(50);
                                 clrscr();
      
      }    
     
     
     }

main()
{

horizontal();

getchar();
}
instead , you can use SDL to load and blit image . Each image can have a bend and non bend. another alternative situation is to write each loaded image as a function.
Topic archived. No new replies allowed.