From de266e50b47d93822356b7c3bbb71c5b49b4f700 Mon Sep 17 00:00:00 2001 From: roy rocket Date: Thu, 11 Aug 2011 06:23:43 +0200 Subject: [PATCH] user added l0dable snake --- firmware/l0dable/snake.c | 194 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 firmware/l0dable/snake.c diff --git a/firmware/l0dable/snake.c b/firmware/l0dable/snake.c new file mode 100644 index 0000000..9422712 --- /dev/null +++ b/firmware/l0dable/snake.c @@ -0,0 +1,194 @@ +#include +#include "basic/basic.h" +#include "basic/config.h" + +#include "lcd/lcd.h" +#include "lcd/print.h" +#include "usetable.h" + +struct elem +{ + int x,y; +}; + +void reset(struct elem snake[],size_t *snake_size,int *dirc, +int*speed, int*points,int*point_s); +void o_rectangle (int x0, int y0, int width, int height); +struct elem rnd(void); + +#define MAX_SNAKE_LEN (40) +#define SNAKE_DEM (3) +#define MIN_SPEED (25) +#define MAX_SPEED (3) +#define SIZE_X (RESX) +#define SIZE_Y (RESY) + +void ram(void) +{ + int inpt,dirc,c,grows = 0,dx,dy,points,point_s=1; + size_t n = 0, snake_size = 5, speed=MIN_SPEED; + struct elem snake[MAX_SNAKE_LEN], food; + char test[512]; /* scratch space */ + o_init (test, sizeof(test)); + + reset(snake,&snake_size,&dirc,&speed,&points,&point_s); + + food = rnd(); + + while (1) + { + head: + if(!(++c % speed)) + { + + +inpt = getInputRaw(); + +dx=DoString(0,0,IntToStrX(points,2)); + dx=(SIZE_X-dx)/2; + if(dx<0) + dx=0; + dy=(SIZE_Y-getFontHeight())/2; + + lcdFill(255); + o_rectangle(1,0,SIZE_X-2,SIZE_Y-2); + o_set_gray (0); + o_fill (); + + //o_identity (); /* reset tranforms */ + + o_set_gray (50); + + setExtFont("UBUNTU29"); + + lcdSetPixel(1,1,1); + DoString(dx,dy,IntToStrX(points,2)); + + o_set_gray (255); + + + for(n=0;n SIZE_Y/SNAKE_DEM-1 || +t.x > SIZE_X/SNAKE_DEM) + { + reset(snake,&snake_size,&dirc,&speed,&points,&point_s); + goto head; + } + + for(n=0;n MAX_SPEED) --speed; + food = rnd(); + } + } + + if(!grows) + { + for(n=0;n