/* * Flapybird.h * * Created on:2016 September 15 ** *<curses.h><unistd.h>< stdlib.h><time.h><malloc.h><assert.h>#define Left_wall 1#define right_wall (COLS-2)int * * Screenarray; // virtual screen with array rendering 1 for wall 0 is empty
/** FLAPYBIRD.C * * Created on:2016 September 15 * Author:jon*/#include"flapybird.h"//#define DEBUG 1voidInit_tcs (void) {INITSCR (); Curs_set (0); Attrset (a_reverse); #ifdef DEBUG MVPRINTW (0, cols/2- -,"height:%d,width:%d", Lines,cols);//lines Y-axis cols X-axis 0 points on the leftMVADDCH (0,0,' '); Refresh ();#endifInit_virtual_screen (); Refresh (); Sleep (Ten);}voidInit_virtual_screen (void) {Screenarray= (int**)malloc(sizeof(int*)*COLS); for(inti =0; i < COLS; i++) {Screenarray[i]= (int*)malloc(sizeof(int)*LINES); } #ifdef DEBUG Screenarray[cols-1][lines-1]=1; ASSERT (Screenarray[cols-1][lines-1]);#endifSrand ((unsigned) time (NULL)); intWall; intMiniwall; intFreeSpace; Miniwall= LINES/3; for(inti =0; i < COLS; i+=5){//draw a wall by separating one lineWall = rand ()%5+ Miniwall;//Upper Half WallFreeSpace =rand ()%8+4;//Draw free space to pass for(intj =0; J < wall;j++) {Screenarray[i][j]=1;//draw the top half of the wall } for(intj = Freespace+wall; J < LINES; J + +) {////Draw the lower half of the wallscreenarray[i][j]=1; } } //Display Wall for(inti =0; i < COLS; i++) for(intj =0; J < lines;j++) { if(Screenarray[i][j] = =1) mvaddch (J,i,' '); }}intMainintAGRC,Char*agrv[]) {Init_tcs (); Nocbreak (); return 0; }
Take the first step. Automatically generate a static wall based on the window size, the next step is to let the wall move, game development after the completion of the adjustment of automatically generated parameters, is expected to refactor
The first step in writing Flapybird Linux ncurses