File size: 1,669 Bytes
806d4b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129



        <1>/* Graphics Not Rendered in HTML */












        <2>/* Graphics Not Rendered in HTML */


        <3>/* Graphics Not Rendered in HTML */















#define BIRD_X 100
F64 dy,y,scroll_x;
Bool game_over;

#define PIPES_NUM       16
#define GAP             100

class Pipe
{
  I64 x,y;
} pipes[PIPES_NUM];

U0 DrawIt(CTask *task, CDC *dc)
{
  I64 i;
  Pipe *p;
  for (i=0;i<PIPES_NUM;i++) {
    p=&pipes[i];
    Sprite3(dc,p->x-scroll_x,p->y+task->pix_height>>1+GAP>>1,0,<3>);
    Sprite3(dc,p->x-scroll_x,p->y+task->pix_height>>1-GAP>>1,0,<2>);
  }

  dc->collision_cnt=0;
  dc->color=ROP_COLLISION;
  dc->bkcolor=WHITE;
  Sprite3ZB(dc,BIRD_X,y,0,<1>,-0.2*dy);
  if (dc->collision_cnt)
    game_over=TRUE;

  dc->color=ROP_EQU;
  Sprite3ZB(dc,BIRD_X,y,0,<1>,-0.2*dy);
}

U0 Init()
{
  I64 i;
  Pipe *p;
  for (i=0;i<PIPES_NUM;i++) {
    p=&pipes[i];
    p->x=i*125+200;
    p->y=80*Sin(i);
  }
  scroll_x=0;
  y=Fs->pix_height>>1;
  dy=0;
  game_over=FALSE;
}

U0 AnimateTask(I64)
{
  while (TRUE) {
    if (!game_over) {
      scroll_x++;
      y=y-dy+1;
      dy*=0.5;
    }
    Sleep(25);
  }
}

U0 Flappy()
{
  SettingsPush; //See SettingsPush
  AutoComplete;
  WinBorder;
  WinMax;
  DocClear;
  Refresh(2);
  Init;
  Fs->draw_it=&DrawIt;
  Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",,Fs);
  try {
    while (TRUE) {
      switch (GetChar(,FALSE)) {
        case CH_ESC:
        case CH_SHIFT_ESC:
          goto fp_done;
        case '\n':
          Init;
          break;
        case CH_SPACE:
          Noise(20,74,86);
          dy+=20;
          break;
      }
    }
fp_done:
  } catch
    PutExcept;
  SettingsPop;
}

Flappy;