1 %{
2 #include <stdio.h>
3 #include "glSDL.h"
4 #include <string.h>
5 #include "PuyoCommander.h"
6 #include "IosImgProcess.h"
7 #include "PuyoStory.h"
8 #include "SDL_prim.h"
9 #include "sofont.h"
10
11 int yylex(void);
12 void yyerror(char *);
13 extern int linenum;
14
15 static IIM_Surface *first_layer = 0;
16 static IIM_Surface *back_layer = 0;
17
18 float dec_vectorx;
19 float dec_vectory;
20
21 static float decx,decy;
22 static int txt_x,txt_y,txt_w,txt_h,txt_r;
23 static char txt[1024];
24
25 extern PuyoStory *theStory;
26
loop_scenar(int time)27 void loop_scenar(int time)
28 {
29 Uint32 start = SDL_GetTicks();
30 while (start + time * 1000 > SDL_GetTicks()) {
31 SDL_Event e;
32
33 while (SDL_PollEvent (&e)) {
34 switch (e.type) {
35 case SDL_QUIT:
36 goto mml_fin;
37 case SDL_KEYDOWN:
38 if (e.key.keysym.sym == SDLK_RETURN) {
39 goto mml_fin;
40 }
41 if (e.key.keysym.sym == SDLK_ESCAPE) {
42 goto mml_fin;
43 }
44 break;
45 }
46 }
47
48 decx += dec_vectorx;
49 decy += dec_vectory;
50
51 if (decx < 0) decx += back_layer->w;
52 if (decy < 0) decy += back_layer->h;
53 if (decx >= back_layer->w) decx -= back_layer->w;
54 if (decy >= back_layer->h) decy -= back_layer->h;
55
56 theCommander->updateAll(theStory);
57 }
58 mml_fin:
59 return;
60 }
61
draw_scenar()62 void draw_scenar()
63 {
64 SDL_Rect drect;
65 // 1- Afficher le back layer
66 if (back_layer) {
67 drect.x = (short)decx - back_layer->w;
68 drect.y = (short)decy;
69 drect.w = back_layer->w;
70 drect.h = back_layer->h;
71 SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
72 drect.x = (short)decx;
73 drect.y = (short)decy - back_layer->h;
74 drect.w = back_layer->w;
75 drect.h = back_layer->h;
76 SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
77 drect.x = (short)decx - back_layer->w;
78 drect.y = (short)decy - back_layer->h;
79 drect.w = back_layer->w;
80 drect.h = back_layer->h;
81 SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
82 drect.x = (short)decx;
83 drect.y = (short)decy;
84 drect.w = back_layer->w;
85 drect.h = back_layer->h;
86 SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
87 }
88 if (first_layer) {
89 drect.x = 0;
90 drect.y = display->h - first_layer->h;
91 drect.w = first_layer->w;
92 drect.h = first_layer->h;
93 SDL_BlitSurface(first_layer->surf,NULL,display,&drect);
94 }
95 if (txt_w>0) {
96 SDL_fillCircle(display, txt_x, txt_y+txt_r, txt_r, 0xffffffff);
97 SDL_fillCircle(display, txt_x, txt_y+txt_h-txt_r, txt_r, 0xffffffff);
98 SDL_fillCircle(display, txt_x+txt_w, txt_y+txt_r, txt_r, 0xffffffff);
99 SDL_fillCircle(display, txt_x+txt_w, txt_y+txt_h-txt_r, txt_r, 0xffffffff);
100 drect.x = txt_x;
101 drect.y = txt_y;
102 drect.w = txt_w;
103 drect.h = txt_h+1;
104 SDL_FillRect(display,&drect,0xffffffff);
105 drect.x = txt_x-txt_r;
106 drect.y = txt_y+txt_r;
107 drect.w = txt_w+2*txt_r+1;
108 drect.h = txt_h-2*txt_r;
109 SDL_FillRect(display,&drect,0xffffffff);
110 SoFont_PutString(theStory->commander->darkFont,display,txt_x,txt_y+10,txt,NULL);
111 }
112 }
113
114 %}
115
116 %union {
117 int i;
118 char str[1024];
119 }
120
121 %token INTEGER STRING
122 %token BACKGROUND VECTOR
123 %token FOREGROUND
124 %token MUSIC
125 %token WAIT SEC LOOP
126 %token TEXTAREA NOTEXTAREA
127 %token COMMA
128 %token SAY
129
130 %type <str> STRING
131 %type <i> INTEGER
132
133 %%
134
135 scenar: prologue instructions epilogue;
136
137 prologue: {
138 first_layer = back_layer = 0;
139 decx = decy = 0;
140 dec_vectorx = 0;
141 dec_vectory = 0;
142 txt_w=txt_h=0;
143 linenum=1;
144 };
145 epilogue: {
146 if(first_layer) { IIM_Free(first_layer); first_layer=0; }
147 if(back_layer) { IIM_Free(back_layer); back_layer=0; }
148 };
149
150 instructions: instructions instruction
151 |;
152
153 instruction:
154 FOREGROUND STRING {
155 if(first_layer) { IIM_Free(first_layer); first_layer=0; }
156 first_layer = IIM_Load_DisplayFormatAlpha($2);
157 }
158 |BACKGROUND STRING {
159 if(back_layer) { IIM_Free(back_layer); back_layer=0; }
160 back_layer = IIM_Load_DisplayFormatAlpha($2);
161 }
162 |VECTOR INTEGER COMMA INTEGER {
163 dec_vectorx = 0.01f * $2;
164 dec_vectory = 0.01f * $4;
165 }
166 |WAIT INTEGER SEC {
167 loop_scenar($2);
168 }
169 |LOOP {
170 loop_scenar(36000);
171 }
172 |TEXTAREA INTEGER COMMA INTEGER COMMA INTEGER COMMA INTEGER COMMA INTEGER {
173 txt_x = $2;
174 txt_y = $4;
175 txt_w = $6;
176 txt_h = $8;
177 txt_r = $10;
178 }
179 |NOTEXTAREA {
180 txt_w = txt_h = 0;
181 }
182 |SAY STRING {
183 strcpy(txt,$2);
184 }
185 ;
186
187 %%
188
189 #include <stdlib.h>
190
191 void yyerror(char *s) {
192 fprintf(stderr, "ERROR LINE %d: %s\n", linenum, s);
193 exit(1);
194 }
195
196 extern int yyrestart(FILE*f);
197
launch_scenar(const char * f)198 void launch_scenar(const char *f)
199 {
200 FILE *yyin = fopen(f,"r");
201 if (yyin==NULL) return;
202 yyrestart(yyin);
203 yyparse();
204 fclose(yyin);
205 }
206
207