Skip to content

Commit e070e50

Browse files
committed
primera version ya medio completa, aun falta el perder
1 parent 9928a59 commit e070e50

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

bin/snasket.exe

0 Bytes
Binary file not shown.

src/main.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <stdlib.h>
55
typedef struct Nodo_t{
66
struct Nodo_t *sig;
7-
struct Nodo_t *ant;
87
float x;
98
float y;
109
float last_x;
@@ -35,7 +34,6 @@ int main(void){
3534
SetTargetFPS(60);
3635

3736
Nodo_t* cabeza = malloc(sizeof(Nodo_t));
38-
Nodo_t* cola = malloc(sizeof(Nodo_t));
3937
cabeza->sig = NULL;
4038

4139

@@ -68,14 +66,32 @@ void setup_snake(Nodo_t *cabeza){
6866
nodos_cantidad = 0;
6967
comida_x = GetRandomValue(0 + 10, GetScreenWidth() - 10);
7068
comida_y = GetRandomValue(0 + 10, GetScreenHeight() - 10);
71-
69+
if(cabeza->sig != NULL){
70+
Nodo_t *tmp = cabeza->sig;
71+
Nodo_t *tmp_borrar;
72+
cabeza->sig = NULL;
73+
while(1){
74+
tmp_borrar = tmp;
75+
if(tmp->sig == NULL){
76+
tmp = NULL;
77+
free(tmp_borrar);
78+
break;
79+
}else {
80+
tmp = tmp->sig;
81+
free(tmp_borrar);
82+
}
83+
}
84+
85+
86+
}
7287
}
7388

7489
void update_snake(Nodo_t *cabeza){
75-
if(IsKeyDown(KEY_D)) dir = dir == 1 ? 1:0;
76-
if(IsKeyDown(KEY_A)) dir = dir == 0 ? 0:1;
77-
if(IsKeyDown(KEY_W)) dir = dir == 3 ? 3:2;
78-
if(IsKeyDown(KEY_S)) dir = dir == 2 ? 2:3;
90+
if(IsKeyDown(KEY_I)) setup_snake(cabeza);
91+
if(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) dir = dir == 1 ? 1:0;
92+
if(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) dir = dir == 0 ? 0:1;
93+
if(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP)) dir = dir == 3 ? 3:2;
94+
if(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN)) dir = dir == 2 ? 2:3;
7995
cabeza->last_x = cabeza->x;
8096
cabeza->last_y = cabeza->y;
8197
if(cabeza->sig != NULL){

0 commit comments

Comments
 (0)