Ring Documentation, Release 1.5.1
al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0)
al_flip_display()
ok
callgc()
end
al_destroy_timer(timer)
al_destroy_allegro_event(ev)
al_destroy_allegro_timeout(timeout)
al_destroy_event_queue(event_queue)
al_destroy_bitmap(bouncer)
al_destroy_bitmap(image)
al_destroy_display(display)
Note: 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.
Program Output:
At first the program display a messagebox
Then we see two rectangles are moving on the screen
50.1. Drawing, Animation and Input 415
Ring Documentation, Release 1.5.1
Then we see an image displayed on the screen
50.1. Drawing, Animation and Input 416
Ring Documentation, Release 1.5.1
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 Keyborad
50.1. Drawing, Animation and Input 417
Ring Documentation, Release 1.5.1
50.2 Using TrueType Fonts
In this example we will see how to use TrueType Fonts *.ttf in our Games using Allegro
Load "gamelib.ring"
al_init()
al_init_font_addon()
al_init_ttf_addon()
display = al_create_display(800,600)
al_clear_to_color(al_map_rgb(0,0,255))
font = al_load_ttf_font("pirulen.ttf",14,0 )
al_draw_text(font, al_map_rgb(255,255,255), 10, 10,ALLEGRO_ALIGN_LEFT,
"Welcome to the Ring programming language")
al_flip_display()
al_rest(2)
al_destroy_display(display)
Screen Shot:
50.2. Using TrueType Fonts 418
Ring Documentation, Release 1.5.1
50.3 Playing Sound Files
The next example play a sound file
Load "gamelib.ring"
al_init()
al_install_audio()
al_init_acodec_addon()
al_reserve_samples(1)
sample = al_load_sample( "footstep.wav" )
sampleid = al_new_allegro_sample_id()
al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,sampleid)
display = al_create_display(640,480)
al_clear_to_color(al_map_rgb(0,0,255))
al_flip_display()
al_rest(10)
al_destroy_allegro_sample_id(sampleid)
50.3. Playing Sound Files 419
Ring Documentation, Release 1.5.1
al_destroy_sample(sample)
al_destroy_display(display)
al_exit()
50.4 Scaling and Rotating Images
The next example display and rotate an image
Load "gamelib.ring"
al_init()
al_init_image_addon()
display = al_create_display(640,480)
al_set_target_bitmap(al_get_backbuffer(display))
al_clear_to_color(al_map_rgb(255,255,255))
image = al_load_bitmap("man2.jpg")
al_draw_rotated_bitmap(image,0,0,250,250,150,0)
al_draw_scaled_bitmap(image,0,0,250,250,20,20,400,400,0)
al_flip_display()
al_rest(2)
al_destroy_bitmap(image)
al_destroy_display(display)
Screen Shot:
50.4. Scaling and Rotating Images 420
Ring Documentation, Release 1.5.1
50.5 Display Transparent Image
The next example display image with white background on another image
Load "gamelib.ring"
al_init()
al_init_image_addon()
display = al_create_display(640,480)
imageback = al_load_bitmap("palace.jpg")
al_draw_bitmap(imageback,0,0,0)
image = al_load_bitmap("man4.png")
al_convert_mask_to_alpha(image,al_map_rgb(255,255,255))
al_draw_bitmap(image,0,0,0)
al_flip_display()
al_rest(10)
al_destroy_bitmap(image)
al_destroy_display(display)
50.5. Display Transparent Image 421
Ring Documentation, Release 1.5.1
Screen Shot:
50.6 Using Threads
In this example we will learn how to use threads from the Allegro library
Load "gamelib.ring"
o1 = new mythreads
Func Main
al_init()
for k = 1 to 5
al_create_thread("o1.thread1()")
al_create_thread("o1.thread2()")
al_create_thread("o1.thread3()")
next
al_rest(2)
Class Mythreads
cAppName = "Threads Application"
50.6. Using Threads 422
Ring Documentation, Release 1.5.1
Func Thread1
for x = 1 to 5
see x + nl
next
See 'Thread(1) : Application Name : ' + cAppName + nl
Func Thread2
for x = 1 to 5
see '*****' + x + nl
next
See 'Thread(2) : Application Name : ' + cAppName + nl
Func Thread3
for x = 1 to 5
see '!!!!' + x + nl
next
See 'Thread(3) : Application Name : ' + cAppName + nl
Output:
1
2
3
4
5
Thread(1) : Application Name : Threads Application
*****1
*****2
*****3
*****4
*****5
Thread(2) : Application Name : Threads Application
!!!!1
!!!!2
!!!!3
!!!!4
!!!!5
Thread(3) : Application Name : Threads Application
1
2
3
4
5
Thread(1) : Application Name : Threads Application
!!!!1
!!!!2
!!!!3
!!!!4
!!!!5
Thread(3) : Application Name : Threads Application
*****1
*****2
*****3
*****4
*****5
Thread(2) : Application Name : Threads Application
*****1
*****2
50.6. Using Threads 423
Ring Documentation, Release 1.5.1
*****3
*****4
*****5
Thread(2) : Application Name : Threads Application
!!!!1
!!!!2
!!!!3
!!!!4
!!!!5
Thread(3) : Application Name : Threads Application
1
2
3
4
5
Thread(1) : Application Name : Threads Application
*****1
*****2
*****3
*****1
*****4
*****2
!!!!1
*****5
*****3
1
!!!!2
Thread(2) : Application Name : Threads Application
1
*****4
!!!!1
2
!!!!3
!!!!4
*****5
!!!!2
3
2
!!!!5
Thread(2) : Application Name : Threads Application
!!!!3
4
3
Thread(3) : Application Name : Threads Application
!!!!4
5
4
!!!!5
Thread(1) : Application Name : Threads Application
5
Thread(3) : Application Name : Threads Application
Thread(1) : Application Name : Threads Application
50.6. Using Threads 424

More Related Content

PDF
The Ring programming language version 1.7 book - Part 50 of 196
PDF
The Ring programming language version 1.9 book - Part 56 of 210
PDF
The Ring programming language version 1.5.4 book - Part 47 of 185
PDF
Home Automation with Android Things and the Google Assistant
PPTX
Internet of Things Magic Show
PDF
The Ring programming language version 1.10 book - Part 71 of 212
KEY
Introduction to Game Programming Tutorial
PDF
Using Android Things to Detect & Exterminate Reptilians
The Ring programming language version 1.7 book - Part 50 of 196
The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.5.4 book - Part 47 of 185
Home Automation with Android Things and the Google Assistant
Internet of Things Magic Show
The Ring programming language version 1.10 book - Part 71 of 212
Introduction to Game Programming Tutorial
Using Android Things to Detect & Exterminate Reptilians

What's hot (20)

PDF
The Ring programming language version 1.9 book - Part 60 of 210
PDF
The Ring programming language version 1.7 book - Part 54 of 196
PPTX
Raspberry Pi with Java (JJUG)
PPTX
Cross-scene references: A shock to the system - Unite Copenhagen 2019
PDF
The Ring programming language version 1.3 book - Part 49 of 88
PDF
The Ring programming language version 1.8 book - Part 56 of 202
KEY
Intro to Game Programming
PDF
The Ring programming language version 1.5.1 book - Part 48 of 180
PDF
Pygame presentation
PPTX
Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...
PPT
iOS Training Session-3
PDF
Kotlin Coroutines - the new async
PDF
The Ring programming language version 1.2 book - Part 37 of 84
PPTX
API Python Chess: Distribution of Chess Wins based on random moves
PDF
The Ring programming language version 1.5.4 book - Part 50 of 185
PDF
DomCode 2015 - Abusing phones to make the internet of things
PDF
The Ring programming language version 1.6 book - Part 52 of 189
PDF
The Ring programming language version 1.5.2 book - Part 52 of 181
PPTX
Java 8 Puzzlers [as presented at OSCON 2016]
The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.7 book - Part 54 of 196
Raspberry Pi with Java (JJUG)
Cross-scene references: A shock to the system - Unite Copenhagen 2019
The Ring programming language version 1.3 book - Part 49 of 88
The Ring programming language version 1.8 book - Part 56 of 202
Intro to Game Programming
The Ring programming language version 1.5.1 book - Part 48 of 180
Pygame presentation
Homemade GoTo mount for Telescopes using Nylon wheels, GT2 belts and 100:1 ge...
iOS Training Session-3
Kotlin Coroutines - the new async
The Ring programming language version 1.2 book - Part 37 of 84
API Python Chess: Distribution of Chess Wins based on random moves
The Ring programming language version 1.5.4 book - Part 50 of 185
DomCode 2015 - Abusing phones to make the internet of things
The Ring programming language version 1.6 book - Part 52 of 189
The Ring programming language version 1.5.2 book - Part 52 of 181
Java 8 Puzzlers [as presented at OSCON 2016]
Ad

Similar to The Ring programming language version 1.5.1 book - Part 45 of 180 (20)

PDF
The Ring programming language version 1.10 book - Part 57 of 212
PDF
The Ring programming language version 1.5.2 book - Part 46 of 181
PDF
The Ring programming language version 1.6 book - Part 49 of 189
PDF
The Ring programming language version 1.7 book - Part 51 of 196
PDF
The Ring programming language version 1.5.3 book - Part 57 of 184
PDF
The Ring programming language version 1.5.3 book - Part 47 of 184
PDF
The Ring programming language version 1.5.3 book - Part 56 of 184
PDF
The Ring programming language version 1.5.3 book - Part 46 of 184
PDF
The Ring programming language version 1.3 book - Part 37 of 88
PDF
The Ring programming language version 1.2 book - Part 35 of 84
PDF
The Ring programming language version 1.3 book - Part 36 of 88
PDF
The Ring programming language version 1.9 book - Part 58 of 210
PDF
The Ring programming language version 1.2 book - Part 34 of 84
PDF
The Ring programming language version 1.4 book - Part 14 of 30
PDF
The Ring programming language version 1.5.2 book - Part 10 of 181
PDF
The Ring programming language version 1.4.1 book - Part 14 of 31
PDF
The Ring programming language version 1.7 book - Part 53 of 196
PDF
The Ring programming language version 1.10 book - Part 59 of 212
PDF
The Ring programming language version 1.3 book - Part 8 of 88
PDF
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.10 book - Part 57 of 212
The Ring programming language version 1.5.2 book - Part 46 of 181
The Ring programming language version 1.6 book - Part 49 of 189
The Ring programming language version 1.7 book - Part 51 of 196
The Ring programming language version 1.5.3 book - Part 57 of 184
The Ring programming language version 1.5.3 book - Part 47 of 184
The Ring programming language version 1.5.3 book - Part 56 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.3 book - Part 37 of 88
The Ring programming language version 1.2 book - Part 35 of 84
The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.2 book - Part 34 of 84
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.5.2 book - Part 10 of 181
The Ring programming language version 1.4.1 book - Part 14 of 31
The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.10 book - Part 59 of 212
The Ring programming language version 1.3 book - Part 8 of 88
The Ring programming language version 1.5.4 book - Part 48 of 185
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PDF
Optimizing bioinformatics applications: a novel approach with human protein d...
PDF
Be ready for tomorrow’s needs with a longer-lasting, higher-performing PC
PDF
Human Computer Interaction Miterm Lesson
PPTX
CRM(Customer Relationship Managmnet) Presentation
PDF
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
PPTX
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
PDF
TicketRoot: Event Tech Solutions Deck 2025
PDF
Secure Java Applications against Quantum Threats
PPT
Overviiew on Intellectual property right
PDF
Advancements in abstractive text summarization: a deep learning approach
PPTX
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
PDF
The Basics of Artificial Intelligence - Understanding the Key Concepts and Te...
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PPTX
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
PDF
Peak of Data & AI Encore: Scalable Design & Infrastructure
PPTX
Report in SIP_Distance_Learning_Technology_Impact.pptx
PDF
Decision Optimization - From Theory to Practice
PPTX
Blending method and technology for hydrogen.pptx
PDF
Gestión Unificada de los Riegos Externos
PDF
TrustArc Webinar - Data Minimization in Practice_ Reducing Risk, Enhancing Co...
Optimizing bioinformatics applications: a novel approach with human protein d...
Be ready for tomorrow’s needs with a longer-lasting, higher-performing PC
Human Computer Interaction Miterm Lesson
CRM(Customer Relationship Managmnet) Presentation
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
TicketRoot: Event Tech Solutions Deck 2025
Secure Java Applications against Quantum Threats
Overviiew on Intellectual property right
Advancements in abstractive text summarization: a deep learning approach
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
The Basics of Artificial Intelligence - Understanding the Key Concepts and Te...
Ebook - The Future of AI A Comprehensive Guide.pdf
Slides World Game (s) Great Redesign Eco Economic Epochs.pptx
Peak of Data & AI Encore: Scalable Design & Infrastructure
Report in SIP_Distance_Learning_Technology_Impact.pptx
Decision Optimization - From Theory to Practice
Blending method and technology for hydrogen.pptx
Gestión Unificada de los Riegos Externos
TrustArc Webinar - Data Minimization in Practice_ Reducing Risk, Enhancing Co...

The Ring programming language version 1.5.1 book - Part 45 of 180

  • 1. Ring Documentation, Release 1.5.1 al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0) al_flip_display() ok callgc() end al_destroy_timer(timer) al_destroy_allegro_event(ev) al_destroy_allegro_timeout(timeout) al_destroy_event_queue(event_queue) al_destroy_bitmap(bouncer) al_destroy_bitmap(image) al_destroy_display(display) Note: 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. Program Output: At first the program display a messagebox Then we see two rectangles are moving on the screen 50.1. Drawing, Animation and Input 415
  • 2. Ring Documentation, Release 1.5.1 Then we see an image displayed on the screen 50.1. Drawing, Animation and Input 416
  • 3. Ring Documentation, Release 1.5.1 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 Keyborad 50.1. Drawing, Animation and Input 417
  • 4. Ring Documentation, Release 1.5.1 50.2 Using TrueType Fonts In this example we will see how to use TrueType Fonts *.ttf in our Games using Allegro Load "gamelib.ring" al_init() al_init_font_addon() al_init_ttf_addon() display = al_create_display(800,600) al_clear_to_color(al_map_rgb(0,0,255)) font = al_load_ttf_font("pirulen.ttf",14,0 ) al_draw_text(font, al_map_rgb(255,255,255), 10, 10,ALLEGRO_ALIGN_LEFT, "Welcome to the Ring programming language") al_flip_display() al_rest(2) al_destroy_display(display) Screen Shot: 50.2. Using TrueType Fonts 418
  • 5. Ring Documentation, Release 1.5.1 50.3 Playing Sound Files The next example play a sound file Load "gamelib.ring" al_init() al_install_audio() al_init_acodec_addon() al_reserve_samples(1) sample = al_load_sample( "footstep.wav" ) sampleid = al_new_allegro_sample_id() al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,sampleid) display = al_create_display(640,480) al_clear_to_color(al_map_rgb(0,0,255)) al_flip_display() al_rest(10) al_destroy_allegro_sample_id(sampleid) 50.3. Playing Sound Files 419
  • 6. Ring Documentation, Release 1.5.1 al_destroy_sample(sample) al_destroy_display(display) al_exit() 50.4 Scaling and Rotating Images The next example display and rotate an image Load "gamelib.ring" al_init() al_init_image_addon() display = al_create_display(640,480) al_set_target_bitmap(al_get_backbuffer(display)) al_clear_to_color(al_map_rgb(255,255,255)) image = al_load_bitmap("man2.jpg") al_draw_rotated_bitmap(image,0,0,250,250,150,0) al_draw_scaled_bitmap(image,0,0,250,250,20,20,400,400,0) al_flip_display() al_rest(2) al_destroy_bitmap(image) al_destroy_display(display) Screen Shot: 50.4. Scaling and Rotating Images 420
  • 7. Ring Documentation, Release 1.5.1 50.5 Display Transparent Image The next example display image with white background on another image Load "gamelib.ring" al_init() al_init_image_addon() display = al_create_display(640,480) imageback = al_load_bitmap("palace.jpg") al_draw_bitmap(imageback,0,0,0) image = al_load_bitmap("man4.png") al_convert_mask_to_alpha(image,al_map_rgb(255,255,255)) al_draw_bitmap(image,0,0,0) al_flip_display() al_rest(10) al_destroy_bitmap(image) al_destroy_display(display) 50.5. Display Transparent Image 421
  • 8. Ring Documentation, Release 1.5.1 Screen Shot: 50.6 Using Threads In this example we will learn how to use threads from the Allegro library Load "gamelib.ring" o1 = new mythreads Func Main al_init() for k = 1 to 5 al_create_thread("o1.thread1()") al_create_thread("o1.thread2()") al_create_thread("o1.thread3()") next al_rest(2) Class Mythreads cAppName = "Threads Application" 50.6. Using Threads 422
  • 9. Ring Documentation, Release 1.5.1 Func Thread1 for x = 1 to 5 see x + nl next See 'Thread(1) : Application Name : ' + cAppName + nl Func Thread2 for x = 1 to 5 see '*****' + x + nl next See 'Thread(2) : Application Name : ' + cAppName + nl Func Thread3 for x = 1 to 5 see '!!!!' + x + nl next See 'Thread(3) : Application Name : ' + cAppName + nl Output: 1 2 3 4 5 Thread(1) : Application Name : Threads Application *****1 *****2 *****3 *****4 *****5 Thread(2) : Application Name : Threads Application !!!!1 !!!!2 !!!!3 !!!!4 !!!!5 Thread(3) : Application Name : Threads Application 1 2 3 4 5 Thread(1) : Application Name : Threads Application !!!!1 !!!!2 !!!!3 !!!!4 !!!!5 Thread(3) : Application Name : Threads Application *****1 *****2 *****3 *****4 *****5 Thread(2) : Application Name : Threads Application *****1 *****2 50.6. Using Threads 423
  • 10. Ring Documentation, Release 1.5.1 *****3 *****4 *****5 Thread(2) : Application Name : Threads Application !!!!1 !!!!2 !!!!3 !!!!4 !!!!5 Thread(3) : Application Name : Threads Application 1 2 3 4 5 Thread(1) : Application Name : Threads Application *****1 *****2 *****3 *****1 *****4 *****2 !!!!1 *****5 *****3 1 !!!!2 Thread(2) : Application Name : Threads Application 1 *****4 !!!!1 2 !!!!3 !!!!4 *****5 !!!!2 3 2 !!!!5 Thread(2) : Application Name : Threads Application !!!!3 4 3 Thread(3) : Application Name : Threads Application !!!!4 5 4 !!!!5 Thread(1) : Application Name : Threads Application 5 Thread(3) : Application Name : Threads Application Thread(1) : Application Name : Threads Application 50.6. Using Threads 424