-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPG.EX
339 lines (317 loc) · 7.1 KB
/
RPG.EX
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
include graphics.e
include image.e
include font.e
include misc.e
include get.e
include file.e
include wildcard.e
include database.e
sequence image_player, map, item_list, image
atom key, line, row, screen_pos1, screen_pos2, player_line, player_row
object bitmap
bitmap=read_bitmap("player.bmp")
image_player=bitmap[2]
line=4
row=4
player_line=4
player_row=4
screen_pos1=1
screen_pos2=1
item_list={}
image={}
if db_open("map", DB_LOCK_NO) != DB_OK then
if db_create("map", DB_LOCK_NO) != DB_OK then
puts(1,"err")
end if
if db_create_table("file") != DB_OK then
puts(1,"err")
end if
if db_create_table("image") != DB_OK then
puts(1,"err")
end if
end if
if db_select_table("image") != DB_OK then
puts(1,"err")
end if
for rec=1 to db_table_size() do
image=append(image,db_record_data(rec))
end for
if db_select_table("file") != DB_OK then
puts(1,"err")
end if
function remove_line(sequence string, atom line)
sequence temp
temp={}
for i=1 to length(string) do
if i=line then
else
temp=append(temp,string[i])
end if
end for
return temp
end function
function transparent(sequence image, atom color)
for i=1 to length(image) do
for j=1 to length(image[i]) do
if image[i][j]= color then
image[i][j]=-1
end if
end for
end for
return image
end function
image_player=transparent(image_player,7)
if db_open("map", DB_LOCK_NO) != DB_OK then
if db_create("map", DB_LOCK_NO) != DB_OK then
puts(1,"err")
end if
if db_create_table("file") != DB_OK then
puts(1,"err")
end if
end if
if db_select_table("file") != DB_OK then
puts(1,"err")
end if
procedure read_map(sequence key)
atom f
f = db_find_key(key)
if f >= 1 then
map=db_record_data(f)
end if
end procedure
read_map("gaz")--prompt_string("Enter Map? "))
procedure rectangle(atom x,atom y,atom xx,atom yy,atom color,atom sel)
polygon(color, sel, {{x, y}, {xx, y}, {xx, yy},{x,yy}})
end procedure
if graphics_mode(13) then
end if
procedure draw()
for i=screen_pos2 to 9+screen_pos2 do
for j=screen_pos1 to 15+screen_pos1 do
if map[i][j][1]=0 then
display_image({(20*(j-screen_pos1+1))-20,(20*(i-screen_pos2+1))-20},image[1])
end if
if map[i][j][1]=1 then
display_image({(20*(j-screen_pos1+1))-20,(20*(i-screen_pos2+1))-20},image[2])
end if
if map[i][j][1]=2 then
display_image({(20*(j-screen_pos1+1))-20,(20*(i-screen_pos2+1))-20},image[3])
end if
if map[i][j][1]=3 then
display_image({(20*(j-screen_pos1+1))-20,(20*(i-screen_pos2+1))-20},image[4])
end if
if map[i][j][2]>0 then
-- draw_text({(20*(j-screen_pos1+1))-20,(20*(i-screen_pos2+1))-20},sprint(map[i][j][2]),RED,-1,0)
end if
end for
end for
end procedure
procedure draw_player()
for i=1 to length(image_player) do
for j=1 to length(image_player[i]) do
if image_player[i][j]=-1 then
else
pixel(image_player[i][j],{20*(player_row-screen_pos1+1)+j-20,20*(player_line-screen_pos2+1)+i-20})
end if
end for
end for
end procedure
procedure draw_pos()
draw()
rectangle((20*(row-screen_pos1+1))-20,(20*(line-screen_pos2+1))-20,(20*(row-screen_pos1+1)),(20*(line-screen_pos2+1)),0,0)
draw_player()
end procedure
draw_pos()
draw_player()
procedure add_item(sequence item)
item_list=append(item_list,item)
end procedure
procedure delete_item(sequence name)
for i=1 to length(item_list) do
if compare(item_list[i][1],name)=0 then
item_list=remove_line(item_list,i)
end if
end for
end procedure
function item_exsits(sequence name)
for i=1 to length(item_list) do
if compare(item_list[i][1],name)=0 then
return 1
end if
end for
return 0
end function
procedure show_msg(sequence msg)
atom len, number, number2
number=1
number2=0
len=length(msg)
if len>4 then
number2=len-4
end if
key=-1
rectangle(50,50,270,130,14,1)
rectangle(55,55,265,125,15,1)
if number2>0 then
for j=1 to number2+1 do
rectangle(55,55,265,125,15,1)
for i=number to len-number2 do
draw_text({60,46+16*(i-number+1)},msg[i],1,15,0)
end for
number+=1
number2-=1
while 1 do
key=get_key()
if key!=-1 then
if key=13 then
exit
end if
end if
end while
end for
else
rectangle(55,55,265,125,15,1)
for i=number to len-number2 do
draw_text({60,46+16*(i-number+1)},msg[i],1,15,0)
end for
key=wait_key()
end if
draw_pos()
key=-1
end procedure
procedure event()
atom id
id=map[line][row][2]
if id=1 then
show_msg({"This is my house i have ",
"bin in my house for days ",
"iam going out for some ",
"air i think it migth be ",
"a good ider to take a ",
"walk to maze i could see",
"that ghost there our not",
"ok lets go to the maze ",
""})
end if
if id=2 then
if item_exsits("blue key")=1 then
show_msg({"you open the door and",
"you see a frog on the ",
"floor thats all",
""})
else
show_msg({"the door is locked you",
"need a blue key to open",
"the door"})
end if
end if
if id=3 then
add_item({"blue key",0})
show_msg({"you have found a blue",
"key you pick it up"})
end if
end procedure
procedure move_player()
--grass
if map[line][row][1]=0 then
player_line=line
player_row=row
draw_pos()
if map[line][row][2]>0 then
event()
end if
--tree
elsif map[line][row][1]=1 then
--house
elsif map[line][row][1]=2 then
player_line=line
player_row=row
draw_pos()
if map[line][row][2]>0 then
event()
end if
--water
elsif map[line][row][1]=1 then
end if
end procedure
while 1 do
key=get_key()
if key != -1 then
if key=27 then
exit
end if
if key=331 then
if row>1 and row<player_row+2 and row>player_row-1 then
if row-screen_pos1=1 then
if screen_pos1>1 then
screen_pos1-=1
end if
row-=1
draw_pos()
else
row-=1
draw_pos()
end if
end if
end if
if key=333 then
if row<length(map[line]) and row<player_row+1 and row>player_row-2 then
if row-screen_pos1=15 then
screen_pos1+=1
row+=1
draw_pos()
else
row+=1
draw_pos()
end if
end if
end if
if key=328 then
if line>1 and line<player_line+2 and line>player_line-1 then
if line-screen_pos2=1 then
if screen_pos2>1 then
screen_pos2-=1
end if
line-=1
draw_pos()
else
line-=1
draw_pos()
end if
end if
end if
if key=336 and line<player_line+1 and line>player_line-2 then
if line<length(map) then
if line-screen_pos2=9 then
screen_pos2+=1
line+=1
draw_pos()
else
line+=1
draw_pos()
end if
end if
end if
if key=13 then
if row=player_row-1 and line=player_line-1 then
move_player()
elsif row=player_row and line=player_line-1 then
move_player()
elsif row=player_row+1 and line=player_line-1 then
move_player()
elsif row=player_row-1 and line=player_line then
move_player()
elsif row=player_row+1 and line=player_line then
move_player()
elsif row=player_row-1 and line=player_line+1 then
move_player()
elsif row=player_row and line=player_line+1 then
move_player()
elsif row=player_row+1 and line=player_line+1 then
move_player()
end if
end if
end if
end while
if graphics_mode(18) then
end if