-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenar.y
206 lines (180 loc) · 4.8 KB
/
scenar.y
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
%{
#include <stdio.h>
#include "glSDL.h"
#include <string.h>
#include "PuyoCommander.h"
#include "IosImgProcess.h"
#include "PuyoStory.h"
#include "SDL_prim.h"
#include "sofont.h"
int yylex(void);
void yyerror(char *);
extern int linenum;
static IIM_Surface *first_layer = 0;
static IIM_Surface *back_layer = 0;
float dec_vectorx;
float dec_vectory;
static float decx,decy;
static int txt_x,txt_y,txt_w,txt_h,txt_r;
static char txt[1024];
extern PuyoStory *theStory;
void loop_scenar(int time)
{
Uint32 start = SDL_GetTicks();
while (start + time * 1000 > SDL_GetTicks()) {
SDL_Event e;
while (SDL_PollEvent (&e)) {
switch (e.type) {
case SDL_QUIT:
goto mml_fin;
case SDL_KEYDOWN:
if (e.key.keysym.sym == SDLK_RETURN) {
goto mml_fin;
}
if (e.key.keysym.sym == SDLK_ESCAPE) {
goto mml_fin;
}
break;
}
}
decx += dec_vectorx;
decy += dec_vectory;
if (decx < 0) decx += back_layer->w;
if (decy < 0) decy += back_layer->h;
if (decx >= back_layer->w) decx -= back_layer->w;
if (decy >= back_layer->h) decy -= back_layer->h;
theCommander->updateAll(theStory);
}
mml_fin:
return;
}
void draw_scenar()
{
SDL_Rect drect;
// 1- Afficher le back layer
if (back_layer) {
drect.x = (short)decx - back_layer->w;
drect.y = (short)decy;
drect.w = back_layer->w;
drect.h = back_layer->h;
SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
drect.x = (short)decx;
drect.y = (short)decy - back_layer->h;
drect.w = back_layer->w;
drect.h = back_layer->h;
SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
drect.x = (short)decx - back_layer->w;
drect.y = (short)decy - back_layer->h;
drect.w = back_layer->w;
drect.h = back_layer->h;
SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
drect.x = (short)decx;
drect.y = (short)decy;
drect.w = back_layer->w;
drect.h = back_layer->h;
SDL_BlitSurface(back_layer->surf,NULL,display,&drect);
}
if (first_layer) {
drect.x = 0;
drect.y = display->h - first_layer->h;
drect.w = first_layer->w;
drect.h = first_layer->h;
SDL_BlitSurface(first_layer->surf,NULL,display,&drect);
}
if (txt_w>0) {
SDL_fillCircle(display, txt_x, txt_y+txt_r, txt_r, 0xffffffff);
SDL_fillCircle(display, txt_x, txt_y+txt_h-txt_r, txt_r, 0xffffffff);
SDL_fillCircle(display, txt_x+txt_w, txt_y+txt_r, txt_r, 0xffffffff);
SDL_fillCircle(display, txt_x+txt_w, txt_y+txt_h-txt_r, txt_r, 0xffffffff);
drect.x = txt_x;
drect.y = txt_y;
drect.w = txt_w;
drect.h = txt_h+1;
SDL_FillRect(display,&drect,0xffffffff);
drect.x = txt_x-txt_r;
drect.y = txt_y+txt_r;
drect.w = txt_w+2*txt_r+1;
drect.h = txt_h-2*txt_r;
SDL_FillRect(display,&drect,0xffffffff);
SoFont_PutString(theStory->commander->darkFont,display,txt_x,txt_y+10,txt,NULL);
}
}
%}
%union {
int i;
char str[1024];
}
%token INTEGER STRING
%token BACKGROUND VECTOR
%token FOREGROUND
%token MUSIC
%token WAIT SEC LOOP
%token TEXTAREA NOTEXTAREA
%token COMMA
%token SAY
%type <str> STRING
%type <i> INTEGER
%%
scenar: prologue instructions epilogue;
prologue: {
first_layer = back_layer = 0;
decx = decy = 0;
dec_vectorx = 0;
dec_vectory = 0;
txt_w=txt_h=0;
linenum=1;
};
epilogue: {
if(first_layer) { IIM_Free(first_layer); first_layer=0; }
if(back_layer) { IIM_Free(back_layer); back_layer=0; }
};
instructions: instructions instruction
|;
instruction:
FOREGROUND STRING {
if(first_layer) { IIM_Free(first_layer); first_layer=0; }
first_layer = IIM_Load_DisplayFormatAlpha($2);
}
|BACKGROUND STRING {
if(back_layer) { IIM_Free(back_layer); back_layer=0; }
back_layer = IIM_Load_DisplayFormatAlpha($2);
}
|VECTOR INTEGER COMMA INTEGER {
dec_vectorx = 0.01f * $2;
dec_vectory = 0.01f * $4;
}
|WAIT INTEGER SEC {
loop_scenar($2);
}
|LOOP {
loop_scenar(36000);
}
|TEXTAREA INTEGER COMMA INTEGER COMMA INTEGER COMMA INTEGER COMMA INTEGER {
txt_x = $2;
txt_y = $4;
txt_w = $6;
txt_h = $8;
txt_r = $10;
}
|NOTEXTAREA {
txt_w = txt_h = 0;
}
|SAY STRING {
strcpy(txt,$2);
}
;
%%
#include <stdlib.h>
void yyerror(char *s) {
fprintf(stderr, "ERROR LINE %d: %s\n", linenum, s);
exit(1);
}
extern int yyrestart(FILE*f);
void launch_scenar(const char *f)
{
FILE *yyin = fopen(f,"r");
if (yyin==NULL) return;
yyrestart(yyin);
yyparse();
fclose(yyin);
}