commit 7500e749f891a5d99568078f7c46968ae4398a73 Author: Logen Kain Date: Fri Aug 5 19:51:39 2016 -0700 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d242ec --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +cartridge diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6fc6cc8 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +PREFIX=/usr + +#OBJS specifies which files to compile as part of the project +OBJS = main.c + +#CC specifies which compiler to use +CC = clang + +#COMPILER_FLAGS specifies the additional compilation options we're using +# -w suppress all warnings +COMPILER_FLAGS = -Wall + +#LINKER_FLAGS specifies the libraries we're linking against +LINKER_FLAGS = -lncurses + +#OBJ_NAME specifies the name of our executable +OBJ_NAME=cartridge + +#This is the target that compiles our executable +all : $(OBJS) + $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME) +install : + mkdir -p ${PREFIX}/share/tuxc + cp tuxc ${PREFIX}/share/tuxc/ + cp -R package_managers ${PREFIX}/share/tuxc/ + ln -si ${PREFIX}/share/tuxc/tuxc ${PREFIX}/bin/tux +uninstall : + rm ${PREFIX}/bin/tux + rm -r ${PREFIX}/share/tuxc/package_managers + rm ${PREFIX}/share/tuxc/tuxc + rm -r ${PREFIX}/share/tuxc +clean : + rm tuxc + diff --git a/main.c b/main.c new file mode 100644 index 0000000..1f5c3a0 --- /dev/null +++ b/main.c @@ -0,0 +1,202 @@ +#include +#include +#include +#include +#define SCREENWIDTH 15 +#define SCREENHEIGHT 15 + +typedef struct +{ + int row, col; + int symbol; +}Character; + +Character new_character(int row, int col, char symbol) +{ + Character a; + a.row = row; + a.col = col; + a.symbol = symbol; + + return a; + +} + +static inline bool check_screen(); +static inline void init(); +static inline void boot(); +static inline void game_loop(Character main_char, int ch); +void move_char (int y, int x); +void draw_borders(WINDOW *screen); + + +int main(int argc, char *argv[]){ + int err = 0; + + initscr(); + + if (!check_screen()) { + fprintf(stderr, "Needs bigger terminal!!!\n"); + err = 1; + } + + else{ + init(); + boot(); + } + + endwin(); + + return err; +} + + +static inline bool check_screen(){ + return LINES >= SCREENHEIGHT && COLS >= SCREENWIDTH; +} + +static inline void init(){ + + // Don't show cursor + curs_set(false); + + // Read arrow keys + keypad(stdscr, true); + + // Read chars directly but allow interrupts + cbreak(); + + // Don't echo + noecho(); + +} + +void draw_borders(WINDOW *screen) { + int x, y, i; + + getmaxyx(screen, y, x); + + // 4 corners + mvwprintw(screen, 0, 0, "+"); + mvwprintw(screen, y - 1, 0, "+"); + mvwprintw(screen, 0, x - 1, "+"); + mvwprintw(screen, y - 1, x - 1, "+"); + + // sides + for (i = 1; i < (y - 1); i++) { + mvwprintw(screen, i, 0, "|"); + mvwprintw(screen, i, x - 1, "|"); + } + + // top and bottom + for (i = 1; i < (x - 1); i++) { + mvwprintw(screen, 0, i, "-"); + mvwprintw(screen, y - 1, i, "-"); + } +} + +// Main boot loop; keep at bottom + +static inline void boot(){ + Character main_char = new_character(10,10,'@'); +// char main_char = '@'; + + printw("Welcome to fucktastic games lotto.\nPress \"q\" to quit or any other key to continue\n"); + + int ch = getch(); + + clear(); + + if(ch == 'q' || ch == 'Q') return; + + //add wall + //should probably be a function of sorts + int wall_row_start = 15; + int wall_col_start = 10; + int wall_col_end = wall_col_start + 20; + int i; + for (i=wall_col_start;i