The first step in writing Flapybird Linux ncurses

Source: Internet
Author: User
Tags assert

/* * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.