-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathallegro.html
762 lines (598 loc) · 60.4 KB
/
allegro.html
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Graphics and 2D Games programming using RingAllegro — Ring 1.14 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Demo Project - Game Engine for 2D Games" href="gameengine.html" />
<link rel="prev" title="Deploying Web Applications in the Cloud" href="deployincloud.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html">
<img src="_static/ringdoclogo.jpg" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="ringapps.html">Applications developed in a few hours</a></li>
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringnotepad.html">Using Ring Notepad</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started - First Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started2.html">Getting Started - Second Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started3.html">Getting Started - Third Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="variables.html">Variables</a></li>
<li class="toctree-l1"><a class="reference internal" href="operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="controlstructures.html">Control Structures - First Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="controlstructures2.html">Control Structures - Second Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="controlstructures3.html">Control Structures - Third Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="getinput.html">Getting Input</a></li>
<li class="toctree-l1"><a class="reference internal" href="functions.html">Functions - First Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="functions2.html">Functions - Second Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="functions3.html">Functions - Third Style</a></li>
<li class="toctree-l1"><a class="reference internal" href="programstructure.html">Program Structure</a></li>
<li class="toctree-l1"><a class="reference internal" href="lists.html">Lists</a></li>
<li class="toctree-l1"><a class="reference internal" href="strings.html">Strings</a></li>
<li class="toctree-l1"><a class="reference internal" href="dateandtime.html">Date and Time</a></li>
<li class="toctree-l1"><a class="reference internal" href="checkandconvert.html">Check Data Type and Conversion</a></li>
<li class="toctree-l1"><a class="reference internal" href="mathfunc.html">Mathematical Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="files.html">Files</a></li>
<li class="toctree-l1"><a class="reference internal" href="systemfunc.html">System Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="evaldebug.html">Eval() and Debugging</a></li>
<li class="toctree-l1"><a class="reference internal" href="demo.html">Demo Programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="odbc.html">ODBC Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="mysql.html">MySQL Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="sqlite.html">SQLite Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="postgresql.html">PostgreSQL Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="secfunc.html">Security and Internet Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="oop.html">Object Oriented Programming (OOP)</a></li>
<li class="toctree-l1"><a class="reference internal" href="fp.html">Functional Programming (FP)</a></li>
<li class="toctree-l1"><a class="reference internal" href="metaprog.html">Reflection and Meta-programming</a></li>
<li class="toctree-l1"><a class="reference internal" href="declarative.html">Declarative Programming using Nested Structures</a></li>
<li class="toctree-l1"><a class="reference internal" href="natural.html">Natural language programming</a></li>
<li class="toctree-l1"><a class="reference internal" href="naturallibrary.html">Using the Natural Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="scope.html">Scope Rules for Variables and Attributes</a></li>
<li class="toctree-l1"><a class="reference internal" href="scope2.html">Scope Rules for Functions and Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="syntaxflexibility.html">Syntax Flexibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="typehints.html">The Type Hints Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="debug.html">The Trace Library and the Interactive Debugger</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringemb.html">Embedding Ring Language in Ring Programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="stdlib.html">Stdlib Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="stdlibclasses.html">Stdlib Classes</a></li>
<li class="toctree-l1"><a class="reference internal" href="qt.html">Desktop, WebAssembly and Mobile development using RingQt</a></li>
<li class="toctree-l1"><a class="reference internal" href="formdesigner.html">Using the Form Designer</a></li>
<li class="toctree-l1"><a class="reference internal" href="qt3d.html">Graphics Programming using RingQt3D</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringqtobjects.html">Objects Library for RingQt Application</a></li>
<li class="toctree-l1"><a class="reference internal" href="multilanguage.html">Multi-language Applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="qtmobile.html">Building RingQt Applications for Mobile</a></li>
<li class="toctree-l1"><a class="reference internal" href="qtwebassembly.html">Building RingQt Applications for WebAssembly</a></li>
<li class="toctree-l1"><a class="reference internal" href="web.html">Web Development (CGI Library)</a></li>
<li class="toctree-l1"><a class="reference internal" href="deployincloud.html">Deploying Web Applications in the Cloud</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Graphics and 2D Games programming using RingAllegro</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#drawing-animation-and-input">Drawing, Animation and Input</a></li>
<li class="toctree-l2"><a class="reference internal" href="#using-truetype-fonts">Using TrueType Fonts</a></li>
<li class="toctree-l2"><a class="reference internal" href="#playing-sound-files">Playing Sound Files</a></li>
<li class="toctree-l2"><a class="reference internal" href="#scaling-and-rotating-images">Scaling and Rotating Images</a></li>
<li class="toctree-l2"><a class="reference internal" href="#display-transparent-image">Display Transparent Image</a></li>
<li class="toctree-l2"><a class="reference internal" href="#using-threads">Using Threads</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="gameengine.html">Demo Project - Game Engine for 2D Games</a></li>
<li class="toctree-l1"><a class="reference internal" href="gameengineandorid.html">Building Games For Android</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringraylib.html">Developing Games using RingRayLib</a></li>
<li class="toctree-l1"><a class="reference internal" href="usingopengl.html">Using RingOpenGL and RingFreeGLUT for 3D Graphics</a></li>
<li class="toctree-l1"><a class="reference internal" href="usingopengl2.html">Using RingOpenGL and RingAllegro for 3D Graphics</a></li>
<li class="toctree-l1"><a class="reference internal" href="goldmagic800.html">Demo Project - The Gold Magic 800 Game</a></li>
<li class="toctree-l1"><a class="reference internal" href="tilengine.html">Using RingTilengine</a></li>
<li class="toctree-l1"><a class="reference internal" href="performancetips.html">Performance Tips</a></li>
<li class="toctree-l1"><a class="reference internal" href="compiler.html">Command Line Options</a></li>
<li class="toctree-l1"><a class="reference internal" href="distribute.html">Distributing Ring Applications (Manual)</a></li>
<li class="toctree-l1"><a class="reference internal" href="distribute_ring2exe.html">Distributing Ring Applications using Ring2EXE</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringpm.html">The Ring Package Manager (RingPM)</a></li>
<li class="toctree-l1"><a class="reference internal" href="zerolib.html">ZeroLib Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="foxringfuncsdoc.html">FoxRing Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="bignumber.html">BigNumber Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="libcurl.html">Using RingLibCurl</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibcurlfuncsdoc.html">RingLibCurl Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="socket.html">Using RingSockets</a></li>
<li class="toctree-l1"><a class="reference internal" href="threads.html">Using RingThreads</a></li>
<li class="toctree-l1"><a class="reference internal" href="libui.html">Using RingLibui</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringzip.html">Using RingZip</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibzipfuncsdoc.html">RingLibZip Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringmurmurhashfuncsdoc.html">RingMurmurHash Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringconsolecolorsfuncsdoc.html">RingConsoleColors Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringallegrofuncsdoc.html">RingAllegro Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="libsdl.html">Using RingLibSDL</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibsdlfuncsdoc.html">RingLibSDL Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="libuv.html">Using Ringlibuv</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringlibuvfuncsdoc.html">RingLibuv Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringfreeglutfuncsdoc.html">RingFreeGLUT Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringstbimage.html">RingStbImage Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringopengl32funcsdoc.html">RingOpenGL (OpenGL 3.2) Functions Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="qtclassesdoc.html">RingQt Classes and Methods Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="lowlevel.html">Low Level Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="extension_tutorial.html">Tutorial: Ring Extensions in C/C++</a></li>
<li class="toctree-l1"><a class="reference internal" href="extension.html">Extension using the C/C++ languages</a></li>
<li class="toctree-l1"><a class="reference internal" href="embedding.html">Embedding Ring Language in C/C++ Programs</a></li>
<li class="toctree-l1"><a class="reference internal" href="codegenerator.html">Code Generator for wrapping C/C++ Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="ringbeep.html">Create your first extension using the Code Generator</a></li>
<li class="toctree-l1"><a class="reference internal" href="languagedesign.html">Release Notes: Version 1.0</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew.html">Release Notes: Version 1.1</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew2.html">Release Notes: Version 1.2</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew3.html">Release Notes: Version 1.3</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew4.html">Release Notes: Version 1.4</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew5.html">Release Notes: Version 1.5</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew6.html">Release Notes: Version 1.6</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew7.html">Release Notes: Version 1.7</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew8.html">Release Notes: Version 1.8</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew9.html">Release Notes: Version 1.9</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew10.html">Release Notes: Version 1.10</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew11.html">Release Notes: Version 1.11</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew12.html">Release Notes: Version 1.12</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew13.html">Release Notes: Version 1.13</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatisnew14.html">Release Notes: Version 1.14</a></li>
<li class="toctree-l1"><a class="reference internal" href="codeeditors.html">Using Other Code Editors</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions (FAQ)</a></li>
<li class="toctree-l1"><a class="reference internal" href="sourcecode.html">How to Compile Ring From Source Code?</a></li>
<li class="toctree-l1"><a class="reference internal" href="contribute.html">How to contribute?</a></li>
<li class="toctree-l1"><a class="reference internal" href="reference.html">Language Specification</a></li>
<li class="toctree-l1"><a class="reference internal" href="resources.html">Resources</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Ring</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home"></a> »</li>
<li>Graphics and 2D Games programming using RingAllegro</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="graphics-and-2d-games-programming-using-ringallegro">
<span id="index-0"></span><h1>Graphics and 2D Games programming using RingAllegro<a class="headerlink" href="#graphics-and-2d-games-programming-using-ringallegro" title="Permalink to this headline">¶</a></h1>
<p>In this chapter we will learn how to use the allegro game programming library
in our Ring applications.</p>
<p>We have the file gamelib.ring that load the DLL library that contains wrappers for the Allegro functions</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">Load</span> <span class="s">"allegro.rh"</span>
<span class="k">if</span> <span class="n">iswindows</span><span class="p">()</span>
<span class="n">LoadLib</span><span class="p">(</span><span class="s">"ring_allegro.dll"</span><span class="p">)</span>
<span class="k">but</span> <span class="n">ismacosx</span><span class="p">()</span>
<span class="n">LoadLib</span><span class="p">(</span><span class="s">"libringallegro.dylib"</span><span class="p">)</span>
<span class="k">else</span>
<span class="n">LoadLib</span><span class="p">(</span><span class="s">"libringallegro.so"</span><span class="p">)</span>
<span class="k">ok</span>
</pre></div>
</div>
<p>The file gamelib.ring uses the Load instruction to execute the file allegro.rh which is a ring source
code file contains constants to be used in our programs.
Then using the function LoadLib() we can load the DLL library “ring_allegro.dll”.</p>
<p>To write portable code we can change the gamelib.ring to check the platform before
loading the DLL/So file.</p>
<div class="section" id="drawing-animation-and-input">
<span id="index-1"></span><h2>Drawing, Animation and Input<a class="headerlink" href="#drawing-animation-and-input" title="Permalink to this headline">¶</a></h2>
<p>The next example uses the Allegro library for drawing, moving objects on the screen and getting
input from the keyboard and the mouse.</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">Load</span> <span class="s">"gamelib.ring"</span>
<span class="n">al_init</span><span class="p">()</span>
<span class="n">al_init_image_addon</span><span class="p">()</span>
<span class="n">display</span> <span class="o">=</span> <span class="n">al_create_display</span><span class="p">(</span><span class="mi">640</span><span class="p">,</span><span class="mi">480</span><span class="p">)</span>
<span class="n">al_show_native_message_box</span><span class="p">(</span><span class="n">display</span><span class="p">,</span> <span class="s">"Hello"</span><span class="p">,</span> <span class="s">"Welcome"</span><span class="p">,</span>
<span class="s">"Using Allegro from the Ring programming language"</span><span class="p">,</span>
<span class="s">""</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>
<span class="n">BOUNCER_SIZE</span> <span class="o">=</span> <span class="mi">40</span>
<span class="n">bouncer_x</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">bouncer_y</span> <span class="o">=</span> <span class="mi">20</span>
<span class="n">bouncer</span> <span class="o">=</span> <span class="n">al_create_bitmap</span><span class="p">(</span><span class="n">BOUNCER_SIZE</span><span class="p">,</span> <span class="n">BOUNCER_SIZE</span><span class="p">)</span>
<span class="n">al_set_target_bitmap</span><span class="p">(</span><span class="n">bouncer</span><span class="p">)</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>
<span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">30</span>
<span class="n">bouncer_x</span> <span class="o">+=</span> <span class="n">x</span>
<span class="n">bouncer_y</span> <span class="o">+=</span> <span class="n">x</span>
<span class="n">al_set_target_bitmap</span><span class="p">(</span><span class="n">al_get_backbuffer</span><span class="p">(</span><span class="n">display</span><span class="p">))</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>
<span class="n">al_draw_bitmap</span><span class="p">(</span><span class="n">bouncer</span><span class="p">,</span> <span class="n">bouncer_x</span><span class="p">,</span> <span class="n">bouncer_y</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">al_draw_bitmap</span><span class="p">(</span><span class="n">bouncer</span><span class="p">,</span> <span class="mi">200</span><span class="o">+</span><span class="n">bouncer_x</span><span class="p">,</span><span class="mi">200</span><span class="o">+</span> <span class="n">bouncer_y</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">al_flip_display</span><span class="p">()</span>
<span class="n">al_rest</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
<span class="k">next</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>
<span class="n">image</span> <span class="o">=</span> <span class="n">al_load_bitmap</span><span class="p">(</span><span class="s">"man2.jpg"</span><span class="p">)</span>
<span class="n">al_draw_bitmap</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="mi">200</span><span class="p">,</span><span class="mi">200</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">al_flip_display</span><span class="p">()</span>
<span class="n">al_rest</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">event_queue</span> <span class="o">=</span> <span class="n">al_create_event_queue</span><span class="p">()</span>
<span class="n">al_register_event_source</span><span class="p">(</span><span class="n">event_queue</span><span class="p">,</span> <span class="n">al_get_display_event_source</span><span class="p">(</span><span class="n">display</span><span class="p">))</span>
<span class="n">ev</span> <span class="o">=</span> <span class="n">al_new_allegro_event</span><span class="p">()</span>
<span class="n">timeout</span> <span class="o">=</span> <span class="n">al_new_allegro_timeout</span><span class="p">()</span>
<span class="n">al_init_timeout</span><span class="p">(</span><span class="n">timeout</span><span class="p">,</span> <span class="mf">0.06</span><span class="p">)</span>
<span class="n">FPS</span> <span class="o">=</span> <span class="mi">60</span>
<span class="n">timer</span> <span class="o">=</span> <span class="n">al_create_timer</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">/</span> <span class="n">FPS</span><span class="p">)</span>
<span class="n">al_register_event_source</span><span class="p">(</span><span class="n">event_queue</span><span class="p">,</span> <span class="n">al_get_timer_event_source</span><span class="p">(</span><span class="n">timer</span><span class="p">))</span>
<span class="n">al_start_timer</span><span class="p">(</span><span class="n">timer</span><span class="p">)</span>
<span class="n">redraw</span> <span class="o">=</span> <span class="kp">true</span>
<span class="n">SCREEN_W</span> <span class="o">=</span> <span class="mi">640</span>
<span class="n">SCREEN_H</span> <span class="o">=</span> <span class="mi">480</span>
<span class="n">BOUNCER_SIZE</span> <span class="o">=</span> <span class="mi">32</span>
<span class="n">bouncer_x</span> <span class="o">=</span> <span class="n">SCREEN_W</span> <span class="o">/</span> <span class="mf">2.0</span> <span class="o">-</span> <span class="n">BOUNCER_SIZE</span> <span class="o">/</span> <span class="mf">2.0</span>
<span class="n">bouncer_y</span> <span class="o">=</span> <span class="n">SCREEN_H</span> <span class="o">/</span> <span class="mf">2.0</span> <span class="o">-</span> <span class="n">BOUNCER_SIZE</span> <span class="o">/</span> <span class="mf">2.0</span>
<span class="n">bouncer_dx</span> <span class="o">=</span> <span class="o">-</span><span class="mf">4.0</span>
<span class="n">bouncer_dy</span> <span class="o">=</span> <span class="mf">4.0</span>
<span class="n">al_install_mouse</span><span class="p">()</span>
<span class="n">al_register_event_source</span><span class="p">(</span><span class="n">event_queue</span><span class="p">,</span> <span class="n">al_get_mouse_event_source</span><span class="p">())</span>
<span class="n">al_install_keyboard</span><span class="p">()</span>
<span class="n">al_register_event_source</span><span class="p">(</span><span class="n">event_queue</span><span class="p">,</span> <span class="n">al_get_keyboard_event_source</span><span class="p">())</span>
<span class="n">KEY_UP</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">KEY_DOWN</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">KEY_LEFT</span> <span class="o">=</span> <span class="mi">3</span>
<span class="n">KEY_RIGHT</span> <span class="o">=</span> <span class="mi">4</span>
<span class="n">Key</span> <span class="o">=</span> <span class="o">[</span><span class="kp">false</span><span class="p">,</span><span class="kp">false</span><span class="p">,</span><span class="kp">false</span><span class="p">,</span><span class="kp">false</span><span class="o">]</span>
<span class="k">while</span> <span class="kp">true</span>
<span class="n">al_init_timeout</span><span class="p">(</span><span class="n">timeout</span><span class="p">,</span> <span class="mf">0.06</span><span class="p">)</span>
<span class="n">al_wait_for_event_until</span><span class="p">(</span><span class="n">event_queue</span><span class="p">,</span> <span class="n">ev</span><span class="p">,</span> <span class="n">timeout</span><span class="p">)</span>
<span class="k">switch</span> <span class="n">al_get_allegro_event_type</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="k">on</span> <span class="n">ALLEGRO_EVENT_DISPLAY_CLOSE</span>
<span class="k">exit</span>
<span class="k">on</span> <span class="n">ALLEGRO_EVENT_TIMER</span>
<span class="c"># Animation</span>
<span class="k">if</span> <span class="n">bouncer_x</span> <span class="o"><</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">bouncer_x</span> <span class="o">></span> <span class="n">SCREEN_W</span> <span class="o">-</span> <span class="n">BOUNCER_SIZE</span>
<span class="n">bouncer_dx</span> <span class="o">=</span> <span class="o">-</span><span class="n">bouncer_dx</span>
<span class="k">ok</span>
<span class="k">if</span> <span class="n">bouncer_y</span> <span class="o"><</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">bouncer_y</span> <span class="o">></span> <span class="n">SCREEN_H</span> <span class="o">-</span> <span class="n">BOUNCER_SIZE</span>
<span class="n">bouncer_dy</span> <span class="o">=</span> <span class="o">-</span><span class="n">bouncer_dy</span>
<span class="k">ok</span>
<span class="n">bouncer_x</span> <span class="o">+=</span> <span class="n">bouncer_dx</span>
<span class="n">bouncer_y</span> <span class="o">+=</span> <span class="n">bouncer_dy</span>
<span class="c"># Keyboard</span>
<span class="k">if</span> <span class="n">key</span><span class="o">[</span><span class="n">KEY_UP</span><span class="o">]</span> <span class="ow">and</span> <span class="n">bouncer_y</span> <span class="o">>=</span> <span class="mf">4.0</span>
<span class="n">bouncer_y</span> <span class="o">-=</span> <span class="mf">4.0</span>
<span class="k">ok</span>
<span class="k">if</span> <span class="n">key</span><span class="o">[</span><span class="n">KEY_DOWN</span><span class="o">]</span> <span class="ow">and</span> <span class="n">bouncer_y</span> <span class="o"><=</span> <span class="n">SCREEN_H</span> <span class="o">-</span> <span class="n">BOUNCER_SIZE</span> <span class="o">-</span> <span class="mf">4.0</span>
<span class="n">bouncer_y</span> <span class="o">+=</span> <span class="mf">4.0</span>
<span class="k">ok</span>
<span class="k">if</span> <span class="n">key</span><span class="o">[</span><span class="n">KEY_LEFT</span><span class="o">]</span> <span class="ow">and</span> <span class="n">bouncer_x</span> <span class="o">>=</span> <span class="mf">4.0</span>
<span class="n">bouncer_x</span> <span class="o">-=</span> <span class="mf">4.0</span>
<span class="k">ok</span>
<span class="k">if</span> <span class="n">key</span><span class="o">[</span><span class="n">KEY_RIGHT</span><span class="o">]</span> <span class="ow">and</span> <span class="n">bouncer_x</span> <span class="o"><=</span> <span class="n">SCREEN_W</span> <span class="o">-</span> <span class="n">BOUNCER_SIZE</span> <span class="o">-</span> <span class="mf">4.0</span>
<span class="n">bouncer_x</span> <span class="o">+=</span> <span class="mf">4.0</span>
<span class="k">ok</span>
<span class="n">redraw</span> <span class="o">=</span> <span class="kp">true</span>
<span class="k">on</span> <span class="n">ALLEGRO_EVENT_MOUSE_AXES</span>
<span class="n">bouncer_x</span> <span class="o">=</span> <span class="n">al_get_allegro_event_mouse_x</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="n">bouncer_y</span> <span class="o">=</span> <span class="n">al_get_allegro_event_mouse_y</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="k">on</span> <span class="n">ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY</span>
<span class="n">bouncer_x</span> <span class="o">=</span> <span class="n">al_get_allegro_event_mouse_x</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="n">bouncer_y</span> <span class="o">=</span> <span class="n">al_get_allegro_event_mouse_y</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="k">on</span> <span class="n">ALLEGRO_EVENT_MOUSE_BUTTON_UP</span>
<span class="k">exit</span>
<span class="k">on</span> <span class="n">ALLEGRO_EVENT_KEY_DOWN</span>
<span class="k">switch</span> <span class="n">al_get_allegro_event_keyboard_keycode</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_UP</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_UP</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_DOWN</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_DOWN</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_LEFT</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_LEFT</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_RIGHT</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_RIGHT</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span>
<span class="k">off</span>
<span class="k">on</span> <span class="n">ALLEGRO_EVENT_KEY_UP</span>
<span class="k">switch</span> <span class="n">al_get_allegro_event_keyboard_keycode</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_UP</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_UP</span><span class="o">]</span> <span class="o">=</span> <span class="kp">false</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_DOWN</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_DOWN</span><span class="o">]</span> <span class="o">=</span> <span class="kp">false</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_LEFT</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_LEFT</span><span class="o">]</span> <span class="o">=</span> <span class="kp">false</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_RIGHT</span>
<span class="n">key</span><span class="o">[</span><span class="n">KEY_RIGHT</span><span class="o">]</span> <span class="o">=</span> <span class="kp">false</span>
<span class="k">on</span> <span class="n">ALLEGRO_KEY_ESCAPE</span>
<span class="k">exit</span>
<span class="k">off</span>
<span class="k">off</span>
<span class="k">if</span> <span class="n">redraw</span> <span class="ow">and</span> <span class="n">al_is_event_queue_empty</span><span class="p">(</span><span class="n">event_queue</span><span class="p">)</span>
<span class="n">redraw</span> <span class="o">=</span> <span class="kp">false</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>
<span class="n">al_draw_bitmap</span><span class="p">(</span><span class="n">bouncer</span><span class="p">,</span> <span class="n">bouncer_x</span><span class="p">,</span> <span class="n">bouncer_y</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">al_flip_display</span><span class="p">()</span>
<span class="k">ok</span>
<span class="n">callgc</span><span class="p">()</span>
<span class="k">end</span>
<span class="n">al_destroy_timer</span><span class="p">(</span><span class="n">timer</span><span class="p">)</span>
<span class="n">al_destroy_allegro_event</span><span class="p">(</span><span class="n">ev</span><span class="p">)</span>
<span class="n">al_destroy_allegro_timeout</span><span class="p">(</span><span class="n">timeout</span><span class="p">)</span>
<span class="n">al_destroy_event_queue</span><span class="p">(</span><span class="n">event_queue</span><span class="p">)</span>
<span class="n">al_destroy_bitmap</span><span class="p">(</span><span class="n">bouncer</span><span class="p">)</span>
<span class="n">al_destroy_bitmap</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>
<span class="n">al_destroy_display</span><span class="p">(</span><span class="n">display</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>In the previous example we used the function callgc() which is a Ring function to force calling the Garbage collector inside the While/End loop.</p>
</div>
<p>Program Output:</p>
<p>At first the program display a messagebox</p>
<img alt="Displaying a messagebox from our program" src="_images/ringalleg_shot1.jpg" />
<p>Then we see two rectangles are moving on the screen</p>
<img alt="Animation - Moving two rectangles in the screen" src="_images/ringalleg_shot2.jpg" />
<p>Then we see an image displayed on the screen</p>
<img alt="Displaying an image on the screen" src="_images/ringalleg_shot3.jpg" />
<p>Finally we have one rectangle, and we see it moving all of the time on
the screen but we can control it using the Mouse and/or the Keyboard</p>
<img alt="Animation and Getting Input from keyboard and the mouse to move the object" src="_images/ringalleg_shot4.jpg" />
</div>
<div class="section" id="using-truetype-fonts">
<span id="index-2"></span><h2>Using TrueType Fonts<a class="headerlink" href="#using-truetype-fonts" title="Permalink to this headline">¶</a></h2>
<p>In this example we will see how to use TrueType Fonts <a href="#id1"><span class="problematic" id="id2">*</span></a>.ttf in our Games using Allegro</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">Load</span> <span class="s">"gamelib.ring"</span>
<span class="n">al_init</span><span class="p">()</span>
<span class="n">al_init_font_addon</span><span class="p">()</span>
<span class="n">al_init_ttf_addon</span><span class="p">()</span>
<span class="n">display</span> <span class="o">=</span> <span class="n">al_create_display</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span><span class="mi">600</span><span class="p">)</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>
<span class="n">font</span> <span class="o">=</span> <span class="n">al_load_ttf_font</span><span class="p">(</span><span class="s">"pirulen.ttf"</span><span class="p">,</span><span class="mi">14</span><span class="p">,</span><span class="mi">0</span> <span class="p">)</span>
<span class="n">al_draw_text</span><span class="p">(</span><span class="n">font</span><span class="p">,</span> <span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">),</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span><span class="n">ALLEGRO_ALIGN_LEFT</span><span class="p">,</span>
<span class="s">"Welcome to the Ring programming language"</span><span class="p">)</span>
<span class="n">al_flip_display</span><span class="p">()</span>
<span class="n">al_rest</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">al_destroy_display</span><span class="p">(</span><span class="n">display</span><span class="p">)</span>
</pre></div>
</div>
<p>Screen Shot:</p>
<img alt="Using TrueType Fonts" src="_images/ringalleg_shot5.jpg" />
</div>
<div class="section" id="playing-sound-files">
<span id="index-3"></span><h2>Playing Sound Files<a class="headerlink" href="#playing-sound-files" title="Permalink to this headline">¶</a></h2>
<p>The next example play a sound file</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">Load</span> <span class="s">"gamelib.ring"</span>
<span class="n">al_init</span><span class="p">()</span>
<span class="n">al_install_audio</span><span class="p">()</span>
<span class="n">al_init_acodec_addon</span><span class="p">()</span>
<span class="n">al_reserve_samples</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">al_load_sample</span><span class="p">(</span> <span class="s">"footstep.wav"</span> <span class="p">)</span>
<span class="n">sampleid</span> <span class="o">=</span> <span class="n">al_new_allegro_sample_id</span><span class="p">()</span>
<span class="n">al_play_sample</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span><span class="mf">1.0</span><span class="p">,</span><span class="n">ALLEGRO_PLAYMODE_LOOP</span><span class="p">,</span><span class="n">sampleid</span><span class="p">)</span>
<span class="n">display</span> <span class="o">=</span> <span class="n">al_create_display</span><span class="p">(</span><span class="mi">640</span><span class="p">,</span><span class="mi">480</span><span class="p">)</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>
<span class="n">al_flip_display</span><span class="p">()</span>
<span class="n">al_rest</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">al_destroy_allegro_sample_id</span><span class="p">(</span><span class="n">sampleid</span><span class="p">)</span>
<span class="n">al_destroy_sample</span><span class="p">(</span><span class="n">sample</span><span class="p">)</span>
<span class="n">al_destroy_display</span><span class="p">(</span><span class="n">display</span><span class="p">)</span>
<span class="n">al_exit</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="scaling-and-rotating-images">
<span id="index-4"></span><h2>Scaling and Rotating Images<a class="headerlink" href="#scaling-and-rotating-images" title="Permalink to this headline">¶</a></h2>
<p>The next example display and rotate an image</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">Load</span> <span class="s">"gamelib.ring"</span>
<span class="n">al_init</span><span class="p">()</span>
<span class="n">al_init_image_addon</span><span class="p">()</span>
<span class="n">display</span> <span class="o">=</span> <span class="n">al_create_display</span><span class="p">(</span><span class="mi">640</span><span class="p">,</span><span class="mi">480</span><span class="p">)</span>
<span class="n">al_set_target_bitmap</span><span class="p">(</span><span class="n">al_get_backbuffer</span><span class="p">(</span><span class="n">display</span><span class="p">))</span>
<span class="n">al_clear_to_color</span><span class="p">(</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>
<span class="n">image</span> <span class="o">=</span> <span class="n">al_load_bitmap</span><span class="p">(</span><span class="s">"man2.jpg"</span><span class="p">)</span>
<span class="n">al_draw_rotated_bitmap</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">250</span><span class="p">,</span><span class="mi">250</span><span class="p">,</span><span class="mi">150</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">al_draw_scaled_bitmap</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">250</span><span class="p">,</span><span class="mi">250</span><span class="p">,</span><span class="mi">20</span><span class="p">,</span><span class="mi">20</span><span class="p">,</span><span class="mi">400</span><span class="p">,</span><span class="mi">400</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">al_flip_display</span><span class="p">()</span>
<span class="n">al_rest</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">al_destroy_bitmap</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>
<span class="n">al_destroy_display</span><span class="p">(</span><span class="n">display</span><span class="p">)</span>
</pre></div>
</div>
<p>Screen Shot:</p>
<img alt="Scaling and Rotating Images" src="_images/ringalleg_shot6.jpg" />
</div>
<div class="section" id="display-transparent-image">
<span id="index-5"></span><h2>Display Transparent Image<a class="headerlink" href="#display-transparent-image" title="Permalink to this headline">¶</a></h2>
<p>The next example display image with white background on another image</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">Load</span> <span class="s">"gamelib.ring"</span>
<span class="n">al_init</span><span class="p">()</span>
<span class="n">al_init_image_addon</span><span class="p">()</span>
<span class="n">display</span> <span class="o">=</span> <span class="n">al_create_display</span><span class="p">(</span><span class="mi">640</span><span class="p">,</span><span class="mi">480</span><span class="p">)</span>
<span class="n">imageback</span> <span class="o">=</span> <span class="n">al_load_bitmap</span><span class="p">(</span><span class="s">"palace.jpg"</span><span class="p">)</span>
<span class="n">al_draw_bitmap</span><span class="p">(</span><span class="n">imageback</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">image</span> <span class="o">=</span> <span class="n">al_load_bitmap</span><span class="p">(</span><span class="s">"man4.png"</span><span class="p">)</span>
<span class="n">al_convert_mask_to_alpha</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="n">al_map_rgb</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">,</span><span class="mi">255</span><span class="p">))</span>
<span class="n">al_draw_bitmap</span><span class="p">(</span><span class="n">image</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="n">al_flip_display</span><span class="p">()</span>
<span class="n">al_rest</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">al_destroy_bitmap</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>
<span class="n">al_destroy_display</span><span class="p">(</span><span class="n">display</span><span class="p">)</span>
</pre></div>
</div>
<p>Screen Shot:</p>
<img alt="Transparent Image" src="_images/ringalleg_shot7.jpg" />
</div>
<div class="section" id="using-threads">
<span id="index-6"></span><h2>Using Threads<a class="headerlink" href="#using-threads" title="Permalink to this headline">¶</a></h2>
<p>In this example we will learn how to use threads from the Allegro library</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="k">Load</span> <span class="s">"gamelib.ring"</span>
<span class="n">o1</span> <span class="o">=</span> <span class="k">new</span> <span class="n">mythreads</span>
<span class="k">Func</span> <span class="n">Main</span>
<span class="n">al_init</span><span class="p">()</span>
<span class="k">for</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">5</span>
<span class="n">al_create_thread</span><span class="p">(</span><span class="s">"o1.thread1()"</span><span class="p">)</span>
<span class="n">al_create_thread</span><span class="p">(</span><span class="s">"o1.thread2()"</span><span class="p">)</span>
<span class="n">al_create_thread</span><span class="p">(</span><span class="s">"o1.thread3()"</span><span class="p">)</span>
<span class="k">next</span>
<span class="n">al_rest</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="k">Class</span> <span class="n">Mythreads</span>
<span class="n">cAppName</span> <span class="o">=</span> <span class="s">"Threads Application"</span>
<span class="k">Func</span> <span class="n">Thread1</span>
<span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">5</span>
<span class="k">see</span> <span class="n">x</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">next</span>
<span class="k">See</span> <span class="sc">'Thread(1) : Application Name : '</span> <span class="o">+</span> <span class="n">cAppName</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">Func</span> <span class="n">Thread2</span>
<span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">5</span>
<span class="k">see</span> <span class="sc">'*****'</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">next</span>
<span class="k">See</span> <span class="sc">'Thread(2) : Application Name : '</span> <span class="o">+</span> <span class="n">cAppName</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">Func</span> <span class="n">Thread3</span>
<span class="k">for</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">to</span> <span class="mi">5</span>
<span class="k">see</span> <span class="sc">'!!!!'</span> <span class="o">+</span> <span class="n">x</span> <span class="o">+</span> <span class="n">nl</span>
<span class="k">next</span>
<span class="k">See</span> <span class="sc">'Thread(3) : Application Name : '</span> <span class="o">+</span> <span class="n">cAppName</span> <span class="o">+</span> <span class="n">nl</span>
</pre></div>
</div>
<p>Output:</p>
<div class="highlight-ring notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span>
<span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">*****</span><span class="mi">1</span>
<span class="o">*****</span><span class="mi">2</span>
<span class="o">*****</span><span class="mi">3</span>
<span class="o">*****</span><span class="mi">4</span>
<span class="o">*****</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">!!!!</span><span class="mi">1</span>
<span class="o">!!!!</span><span class="mi">2</span>
<span class="o">!!!!</span><span class="mi">3</span>
<span class="o">!!!!</span><span class="mi">4</span>
<span class="o">!!!!</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="mi">1</span>
<span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">!!!!</span><span class="mi">1</span>
<span class="o">!!!!</span><span class="mi">2</span>
<span class="o">!!!!</span><span class="mi">3</span>
<span class="o">!!!!</span><span class="mi">4</span>
<span class="o">!!!!</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">*****</span><span class="mi">1</span>
<span class="o">*****</span><span class="mi">2</span>
<span class="o">*****</span><span class="mi">3</span>
<span class="o">*****</span><span class="mi">4</span>
<span class="o">*****</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">*****</span><span class="mi">1</span>
<span class="o">*****</span><span class="mi">2</span>
<span class="o">*****</span><span class="mi">3</span>
<span class="o">*****</span><span class="mi">4</span>
<span class="o">*****</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">!!!!</span><span class="mi">1</span>
<span class="o">!!!!</span><span class="mi">2</span>
<span class="o">!!!!</span><span class="mi">3</span>
<span class="o">!!!!</span><span class="mi">4</span>
<span class="o">!!!!</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="mi">1</span>
<span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">*****</span><span class="mi">1</span>
<span class="o">*****</span><span class="mi">2</span>
<span class="o">*****</span><span class="mi">3</span>
<span class="o">*****</span><span class="mi">1</span>
<span class="o">*****</span><span class="mi">4</span>
<span class="o">*****</span><span class="mi">2</span>
<span class="o">!!!!</span><span class="mi">1</span>
<span class="o">*****</span><span class="mi">5</span>
<span class="o">*****</span><span class="mi">3</span>
<span class="mi">1</span>
<span class="o">!!!!</span><span class="mi">2</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="mi">1</span>
<span class="o">*****</span><span class="mi">4</span>
<span class="o">!!!!</span><span class="mi">1</span>
<span class="mi">2</span>
<span class="o">!!!!</span><span class="mi">3</span>
<span class="o">!!!!</span><span class="mi">4</span>
<span class="o">*****</span><span class="mi">5</span>
<span class="o">!!!!</span><span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">2</span>
<span class="o">!!!!</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">!!!!</span><span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">3</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="o">!!!!</span><span class="mi">4</span>
<span class="mi">5</span>
<span class="mi">4</span>
<span class="o">!!!!</span><span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="mi">5</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
<span class="n">Thread</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">:</span> <span class="n">Application</span> <span class="n">Name</span> <span class="p">:</span> <span class="n">Threads</span> <span class="n">Application</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="gameengine.html" class="btn btn-neutral float-right" title="Demo Project - Game Engine for 2D Games" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="deployincloud.html" class="btn btn-neutral float-left" title="Deploying Web Applications in the Cloud" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2016-2021, Ring Team
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(false);
});
</script>
</body>
</html>