diff options
| author | Aleksa Vučković <aleksav013@gmail.com> | 2022-06-01 17:02:08 +0200 |
|---|---|---|
| committer | Aleksa Vučković <aleksav013@gmail.com> | 2022-06-01 17:02:08 +0200 |
| commit | dd038cfb10cae6dba5afabc786a129224da5ef8c (patch) | |
| tree | e9d94f187db87f880a52be2c4e7c8e276477c9ab /src/c/shell | |
| parent | 602037ec658da6ab2f04f1c806bfccdcd8125f27 (diff) | |
simple snake game
Diffstat (limited to 'src/c/shell')
| -rw-r--r-- | src/c/shell/game.c | 135 | ||||
| -rw-r--r-- | src/c/shell/neofetch.c | 40 | ||||
| -rw-r--r-- | src/c/shell/uptime.c | 10 |
3 files changed, 185 insertions, 0 deletions
diff --git a/src/c/shell/game.c b/src/c/shell/game.c new file mode 100644 index 0000000..e7c5d1e --- /dev/null +++ b/src/c/shell/game.c @@ -0,0 +1,135 @@ +#include<source/shell/game.h> +#include<types.h> +#include<source/vga.h> +#include<source/tty.h> +#include<source/timer.h> +#include<source/stdio.h> + +extern uint16_t* terminal_buffer; +extern uint8_t terminal_color; +extern uint8_t process_id; + +#define N 1000 + +uint16_t x; +uint16_t y; +uint16_t rep[N]; + +uint32_t game_time; +uint32_t game_tick; +uint8_t gameover; +uint8_t duzina; +uint8_t smer; + +uint16_t jabuka; +uint16_t x_jabuke; +uint16_t y_jabuke; + +void game_keyboard_handler(uint16_t keycode) +{ + switch(keycode) + { + // space(); + case 0x39: + process_id = PROCESS_TTY_ID; + clear(); + prompt(); + break; + // keyup(); + case 72: + smer = 1; + break; + // keydown(); + case 80: + smer = 2; + break; + // keyleft(); + case 75: + smer = 3; + break; + // keyright(); + case 77: + smer = 4; + break; + } +} + +void game_init(void) +{ + x=VGA_WIDTH/2; + y=VGA_HEIGHT/2; + game_time=0; + game_tick=0; + duzina=1; + gameover=0; + smer=0; + + x_jabuke=5; + y_jabuke=5; + + process_id = PROCESS_GAME_ID; + clear(); +} + +void game_timer_handler() +{ + game_tick++; + if (game_tick == TICKS_PER_SECOND/8 && !gameover) + { + switch(smer) + { + case 1: + if(y>0) y--; + else y=VGA_HEIGHT-1; + break; + case 2: + if(y<VGA_HEIGHT) y++; + else y=0; + break; + case 3: + if(x>0) x--; + else x=VGA_WIDTH-1; + break; + case 4: + if(x<VGA_WIDTH) x++; + else x=0; + break; + default: + break; + } + game_tick=0; + game_time+=1; + + for(uint8_t i = duzina; i > 0; i--) rep[i]=rep[i-1]; + rep[0]=(uint16_t)(y*80+x); + + if (rep[0] == y_jabuke*80+x_jabuke) + { + duzina++; + + uint8_t ind; + do { + ind = 1; + x_jabuke = (uint16_t)((game_time*game_time)%80); + y_jabuke = (uint16_t)((game_time*game_time)%25); + jabuka = (uint16_t)(y_jabuke*80+x_jabuke); + for(uint8_t i = 0; i < duzina; i++) if(rep[i] == jabuka) ind=0; + game_time++; + } while(!ind); + + terminal_buffer[jabuka]=(uint16_t)(terminal_color<<8|'J'); + } + terminal_buffer[rep[duzina]]=(uint16_t)(terminal_color<<8|' '); + terminal_buffer[rep[0]]=(uint16_t)(terminal_color<<8|'#'); + + set_color(VGA_COLOR_RED,VGA_COLOR_BLACK); + terminal_buffer[y_jabuke*80+x_jabuke]=(uint16_t)(terminal_color<<8|'J'); + set_color(VGA_COLOR_LIGHT_GREY,VGA_COLOR_BLACK); + + for(uint8_t i = 1; i < duzina; i++) if(rep[0] == rep[i]) + { + printf("GAME OVER\nPress <Space> to return to shell\n"); + gameover=1; + } + } +} diff --git a/src/c/shell/neofetch.c b/src/c/shell/neofetch.c new file mode 100644 index 0000000..e770428 --- /dev/null +++ b/src/c/shell/neofetch.c @@ -0,0 +1,40 @@ +#include<source/shell/neofetch.h> +#include<source/shell/uptime.h> +#include<source/vga.h> +#include<source/stdio.h> +#include<source/timer.h> + +void neofetch(void) +{ + set_color(VGA_COLOR_WHITE,VGA_COLOR_BLACK); + printf(" . "); printf("Dobrodosli u moj \n"); + printf(" J:L (\"\"\") "); printf("operativni sistem :) \n"); + printf(" |:| III "); printf("Uzivajte! \n"); + printf(" |:| III "); printf(" \n"); + printf(" |:| III "); printf("Welcome to my \n"); + printf(" |:| __III__ "); printf("operating system :) \n"); + printf(" |:| /:-.___,-:\\ "); printf("Enjoy your stay! \n"); + printf(" |:| \\] |:| [/ "); printf(" \n"); + printf(" |:| |:| "); printf(" \n"); + printf(" |:| |:| "); printf(" \n"); + printf(" |:| |:| "); printf(" \n"); + printf(" /] |:| [\\ |:| "); printf(" \n"); + printf(" \\:-'\"\"\"`-:/ |:| "); printf(" \n"); + printf(" \"\"III\"\" |:| "); printf(" \n"); + printf(" III |:| "); printf(" \n"); + printf(" III |:| "); printf(" \n"); + printf(" III |:| "); printf("napravio/made by: \n"); + printf(" (___) J:F "); printf("Aleksa Vuckovic \n"); + printf(" \" "); printf(" \n"); + + for(size_t i=0;i<16;i++) + { + set_color(0,i); + printf(" ",i); + } + printf("\n"); + + + set_color(VGA_COLOR_LIGHT_GREY,VGA_COLOR_BLACK); + uptime(); +} diff --git a/src/c/shell/uptime.c b/src/c/shell/uptime.c new file mode 100644 index 0000000..fc78579 --- /dev/null +++ b/src/c/shell/uptime.c @@ -0,0 +1,10 @@ +#include<source/shell/uptime.h> +#include<source/stdio.h> +#include<types.h> + +extern uint32_t time; + +void uptime(void) +{ + printf("System uptime is: %d seconds\n",time); +} |
