Ring Documentation, Release 1.7
55.3 Interface to graphics library
In this layer we have gl_allegro.ring and gl_libsdl.ring
Each library provides the same functions to be used with interacting with the Graphics Library.
This layer hides the details and the difference between RingAllegro and RingLibSDL.
You have the same functions, Just use it and you can switch between Allegro and LibSDL at anytime.
Why ?
Allegro is very simple, we can use it to quickly create 2D games for Windows, Linux and MacOS X.
In Ring 1.0 we started by supporting Allegro.
Also LibSDL is very powerful and popular, very easy to use for Mobile Development.
Ring 1.1 comes with support for LibSDL so we can quickly create games for Mobile.
Note: We can use just one library for Desktop and Mobile development.
• gl_allegro.ring source code : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gl_allegro.ring
• gl_libsdl.ring source code : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gl_libsdl.ring
55.4 Game Engine Classes
The Engine comes with the next classes
• GameBase class
• Resources class
• Game class
• GameObject class
• Sprite class
• Text class
• Animate class
• Sound class
• Map class
• Source Code : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gameengine.ring
55.5 Games Layer
In this layer we create our games using the Game Engine classes
The classes are designed to be used through Declarative Programming.
In our games we will use the next classes
• Game class
• Sprite class
55.3. Interface to graphics library 492
Ring Documentation, Release 1.7
• Text class
• Animate class
• Sound class
• Map class
Note: Other classes in the engine are for internal use by the engine.
We will introduce some examples and three simple games :-
• Stars Fighter Game
• Flappy Bird 3000 Game
• Super Man 2016 Game
55.6 Game Class
The next table present the class attributes.
Attributes Description
FPS Number determines how many times the draw() method will be called per second.
FixedFPS Number determines how many times the animate() method will be called per second.
Title String determines the window title of the game.
aObjects List contains all objects in the game
shutdown True/False value to end the game loop
The next table present the class methods.
Method Description
refresh() Delete objects.
settitle(cTitle) Set the window title using a string parameter.
shutdown() Close the application.
The next table present a group of keywords defined by the class.
Keyword Description
sprite Create new Sprite object and add it to the game objects.
text Create new Text object and add it to the game objects.
animate Create new Animate object and add it to the game objects.
sound Create new Sound object and add it to the game objects.
map Create new Map object and add it ot the game objects.
55.7 GameObject Class
The next table present the class attributes.
55.6. Game Class 493
Ring Documentation, Release 1.7
Attributes Description
enabled True/False determine the state of the object (Active/Not Active)
x Number determine the x position of the object.
y Number determine the y position of the object.
width Number determine the width of the object.
height Number determine the height of the object.
nIndex Number determine the index of the object in objects list.
animate True/False to animate the object or not.
move True/False to move the object using the keyboard or not.
Scaled True/False to scale the object image or not.
draw Function to be called when drawing the object.
state Function to be called for object animation.
keypress Function to be called when a key is pressed.
mouse Function to be called when a mouse event happens.
The next table present the class methods.
Method Description
keyboard(oGame,nkey) Check Keyboard Events
mouse(oGame,nType,aMouseList) Check Mouse Events
rgb(r,g,b) Return new color using the RGB (Red, Green and Blue) Values.
55.8 Sprite Class
Parent Class : GameObject Class
The next table present the class attributes.
Attributes Description
image String determine the image file name.
point Number determine the limit of automatic movement of the object.
direction Number determine the direction of movement.
nstep Number determine the increment/decrement during movement.
type Number determine the object type in the game (Optional).
transparent True/False value determine if the image is transparent.
The next table present the class methods.
Method Description
Draw(oGame) Draw the object
55.9 Text Class
Parent Class : Sprite Class
The next table present the class attributes.
Attributes Description
size Number determine the font size
font String determine the font file name
text String determine the text to be displayed
color Number determine the color
The next table present the class methods.
55.8. Sprite Class 494
Ring Documentation, Release 1.7
Method Description
Draw(oGame) Draw the object
55.10 Animate Class
Parent Class : Sprite Class
The next table present the class attributes.
Attributes Description
frames Number determine the number of frames
frame Number determine the active frame
framewidth Number determine the frame width.
animate True/False determine using animate or not.
scaled True/False determine scaling image or not.
The next table present the class methods.
Method Description
Draw(oGame) Draw the object
55.11 Sound Class
Parent Class : GameObject Class
The next table present the class attributes.
Attributes Description
file String determine the sound file name.
once True/False determine to play the file one time or not (loop).
The next table present the class methods.
Method Description
playsound() Play the sound file
55.12 Map Class
Parent Class : Sprite Class
The next table present the class attributes.
Attributes Description
aMap List determine the map content using numbers.
aImages List determine the image used for each number in the map.
BlockWidth Number determine the block width (default = 32).
BlockHeight Number determine the block height (default = 32).
Animate True/False determine the animation status.
The next table present the class methods.
Method Description
getvalue(x,y) Return the item value in the Map according to the visible part
55.10. Animate Class 495
Ring Documentation, Release 1.7
55.13 Using the Game Engine - Creating the Game Window
Load "gameengine.ring" # Give Control to the Game Engine
func main # Called by the Game Engine
oGame = New Game # Create the Game Object
{
title = "My First Game"
} # Start the Events Loop
Note: if you want to define global variables, this must be before load “gameengine.ring” because this instruction will
give the control to the game engine.
Screen Shot:
55.14 Using the Game Engine - Drawing Text
Load "gameengine.ring" # Give Control to the Game Engine
func main # Called by the Game Engine
55.13. Using the Game Engine - Creating the Game Window 496
Ring Documentation, Release 1.7
oGame = New Game # Create the Game Object
{
title = "My First Game"
text {
x = 10 y=50
animate = false
size = 20
file = "fonts/pirulen.ttf"
text = "game development using ring is very fun!"
color = rgb(0,0,0)
}
} # Start the Events Loop
Screen Shot:
55.15 Using the Game Engine - Moving Text
Load "gameengine.ring" # Give Control to the Game Engine
func main # Called by the Game Engine
oGame = New Game # Create the Game Object
55.15. Using the Game Engine - Moving Text 497
Ring Documentation, Release 1.7
{
title = "My First Game"
text {
x = 10 y=50
animate = false
size = 20
file = "fonts/pirulen.ttf"
text = "game development using ring is very fun!"
color = rgb(0,0,0) # Color = black
}
text {
x = 10 y=150
# Animation Part =====================================
animate = true # Use Animation
direction = GE_DIRECTION_INCVERTICAL # Increase y
point = 400 # Continue until y=400
nStep = 3 # Each time y+= 3
#=====================================================
size = 20
file = "fonts/pirulen.ttf"
text = "welcome to the real world!"
color = rgb(0,0,255) # Color = Blue
}
} # Start the Events Loop
Screen Shot:
55.15. Using the Game Engine - Moving Text 498
Ring Documentation, Release 1.7
55.16 Using the Game Engine - Playing Sound
Load "gameengine.ring" # Give Control to the Game Engine
func main # Called by the Game Engine
oGame = New Game # Create the Game Object
{
title = "My First Game"
text {
x = 10 y=50
animate = false
size = 20
file = "fonts/pirulen.ttf"
text = "game development using ring is very fun!"
color = rgb(0,0,0) # Color = black
}
text {
x = 10 y=150
# Animation Part ======================================
animate = true # Use Animation
direction = GE_DIRECTION_INCVERTICAL # Increase y
55.16. Using the Game Engine - Playing Sound 499
Ring Documentation, Release 1.7
point = 400 # Continue until y=400
nStep = 3 # Each time y+= 3
#======================================================
size = 20
file = "fonts/pirulen.ttf"
text = "welcome to the real world!"
color = rgb(0,0,255) # Color = Blue
}
Sound { # Play Sound
file = "sound/music1.wav" # Sound File Name
}
} # Start the Events Loop
55.17 Using the Game Engine - Animation
Load "gameengine.ring" # Give Control to the Game Engine
func main # Called by the Game Engine
oGame = New Game # Create the Game Object
{
title = "My First Game"
animate {
file = "images/fire.png"
x = 100
y = 200
framewidth = 40
height = 42
nStep = 3 # Used for delay
transparent = true
state = func oGame,oSelf { # Called by engine each frame
oSelf {
nStep--
if nStep = 0
nStep = 3
if frame < 13 # we have 13 frames in animation
frame++ # move to next frame
else
oGame.remove(oself.nIndex) # remove object
ok
ok
}
}
}
} # Start the Events Loop
55.17. Using the Game Engine - Animation 500
Ring Documentation, Release 1.7
55.18 Using the Game Engine - Animation and Functions
Load "gameengine.ring" # Give Control to the Game Engine
func main # Called by the Game Engine
oGame = New Game # Create the Game Object
{
title = "My First Game"
for x = 70 to 700 step 50
for y = 70 to 500 step 50
showfire(oGame,x,y)
next
next
} # Start the Events Loop
func showfire oGame,nX,nY
oGame {
animate {
file = "images/fire.png"
x = nX
55.18. Using the Game Engine - Animation and Functions 501

More Related Content

PDF
The Ring programming language version 1.5.1 book - Part 47 of 180
PDF
The Ring programming language version 1.8 book - Part 55 of 202
PDF
The Ring programming language version 1.4 book - Part 14 of 30
PDF
The Ring programming language version 1.2 book - Part 36 of 84
PDF
The Ring programming language version 1.6 book - Part 51 of 189
PDF
The Ring programming language version 1.5.2 book - Part 48 of 181
PDF
The Ring programming language version 1.9 book - Part 59 of 210
PDF
The Ring programming language version 1.3 book - Part 39 of 88
The Ring programming language version 1.5.1 book - Part 47 of 180
The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.6 book - Part 51 of 189
The Ring programming language version 1.5.2 book - Part 48 of 181
The Ring programming language version 1.9 book - Part 59 of 210
The Ring programming language version 1.3 book - Part 39 of 88

What's hot (18)

PDF
The Ring programming language version 1.5.3 book - Part 49 of 184
PDF
Pygame presentation
PDF
The Ring programming language version 1.2 book - Part 37 of 84
PDF
The Ring programming language version 1.10 book - Part 60 of 212
PDF
The Ring programming language version 1.5.1 book - Part 48 of 180
PDF
The Ring programming language version 1.5.4 book - Part 49 of 185
PDF
The Ring programming language version 1.3 book - Part 38 of 88
PDF
Game Development with AndEngine
PDF
The Ring programming language version 1.10 book - Part 71 of 212
PDF
The Ring programming language version 1.5.3 book - Part 48 of 184
PDF
Código fuente del software educativo
PDF
Código fuente del software educativo
PDF
The Ring programming language version 1.6 book - Part 52 of 189
PDF
Make a match3
PDF
The Ring programming language version 1.5.2 book - Part 49 of 181
PPTX
Game Project / Working with Unity
PDF
enchant js workshop on Calpoly
PDF
Intro to programming games with clojure
The Ring programming language version 1.5.3 book - Part 49 of 184
Pygame presentation
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.10 book - Part 60 of 212
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.4 book - Part 49 of 185
The Ring programming language version 1.3 book - Part 38 of 88
Game Development with AndEngine
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.5.3 book - Part 48 of 184
Código fuente del software educativo
Código fuente del software educativo
The Ring programming language version 1.6 book - Part 52 of 189
Make a match3
The Ring programming language version 1.5.2 book - Part 49 of 181
Game Project / Working with Unity
enchant js workshop on Calpoly
Intro to programming games with clojure

Similar to The Ring programming language version 1.7 book - Part 53 of 196 (20)

PDF
The Ring programming language version 1.5.3 book - Part 58 of 184
PDF
The Ring programming language version 1.9 book - Part 58 of 210
PDF
The Ring programming language version 1.5.3 book - Part 59 of 184
PDF
The Ring programming language version 1.5.4 book - Part 48 of 185
PDF
The Ring programming language version 1.5.4 book - Part 50 of 185
PDF
The Ring programming language version 1.7 book - Part 54 of 196
PDF
The Ring programming language version 1.8 book - Part 56 of 202
PDF
The Ring programming language version 1.10 book - Part 61 of 212
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 36 of 88
PDF
The Ring programming language version 1.9 book - Part 60 of 210
PDF
The Ring programming language version 1.5.2 book - Part 47 of 181
PDF
The Ring programming language version 1.6 book - Part 50 of 189
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.4 book - Part 60 of 185
PDF
The Ring programming language version 1.5.1 book - Part 45 of 180
PDF
The Ring programming language version 1.5 book - Part 9 of 31
PDF
The Ring programming language version 1.5.3 book - Part 60 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.5.3 book - Part 59 of 184
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 50 of 185
The Ring programming language version 1.7 book - Part 54 of 196
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.10 book - Part 61 of 212
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 36 of 88
The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.5.2 book - Part 47 of 181
The Ring programming language version 1.6 book - Part 50 of 189
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.4 book - Part 60 of 185
The Ring programming language version 1.5.1 book - Part 45 of 180
The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5.3 book - Part 60 of 184

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)

PPTX
maintenance powerrpoint for adaprive and preventive
PDF
Child-friendly e-learning for artificial intelligence education in Indonesia:...
PDF
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
PDF
Domain-specific knowledge and context in large language models: challenges, c...
PDF
State of AI in Business 2025 - MIT NANDA
PDF
Introduction to c language from lecture slides
PDF
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
PDF
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
PPT
Overviiew on Intellectual property right
PDF
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
PDF
Human Computer Interaction Miterm Lesson
PDF
EGCB_Solar_Project_Presentation_and Finalcial Analysis.pdf
PDF
Peak of Data & AI Encore: Scalable Design & Infrastructure
PPTX
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
PPTX
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
PDF
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
PPTX
Presentation - Principles of Instructional Design.pptx
PPTX
Information-Technology-in-Human-Society (2).pptx
PDF
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
PDF
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
maintenance powerrpoint for adaprive and preventive
Child-friendly e-learning for artificial intelligence education in Indonesia:...
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
Domain-specific knowledge and context in large language models: challenges, c...
State of AI in Business 2025 - MIT NANDA
Introduction to c language from lecture slides
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
Overviiew on Intellectual property right
CCUS-as-the-Missing-Link-to-Net-Zero_AksCurious.pdf
Human Computer Interaction Miterm Lesson
EGCB_Solar_Project_Presentation_and Finalcial Analysis.pdf
Peak of Data & AI Encore: Scalable Design & Infrastructure
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
Strategic Picks — Prioritising the Right Agentic Use Cases [2/6]
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
Presentation - Principles of Instructional Design.pptx
Information-Technology-in-Human-Society (2).pptx
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...

The Ring programming language version 1.7 book - Part 53 of 196

  • 1. Ring Documentation, Release 1.7 55.3 Interface to graphics library In this layer we have gl_allegro.ring and gl_libsdl.ring Each library provides the same functions to be used with interacting with the Graphics Library. This layer hides the details and the difference between RingAllegro and RingLibSDL. You have the same functions, Just use it and you can switch between Allegro and LibSDL at anytime. Why ? Allegro is very simple, we can use it to quickly create 2D games for Windows, Linux and MacOS X. In Ring 1.0 we started by supporting Allegro. Also LibSDL is very powerful and popular, very easy to use for Mobile Development. Ring 1.1 comes with support for LibSDL so we can quickly create games for Mobile. Note: We can use just one library for Desktop and Mobile development. • gl_allegro.ring source code : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gl_allegro.ring • gl_libsdl.ring source code : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gl_libsdl.ring 55.4 Game Engine Classes The Engine comes with the next classes • GameBase class • Resources class • Game class • GameObject class • Sprite class • Text class • Animate class • Sound class • Map class • Source Code : https://github.com/ring-lang/ring/blob/master/ringlibs/gameengine/gameengine.ring 55.5 Games Layer In this layer we create our games using the Game Engine classes The classes are designed to be used through Declarative Programming. In our games we will use the next classes • Game class • Sprite class 55.3. Interface to graphics library 492
  • 2. Ring Documentation, Release 1.7 • Text class • Animate class • Sound class • Map class Note: Other classes in the engine are for internal use by the engine. We will introduce some examples and three simple games :- • Stars Fighter Game • Flappy Bird 3000 Game • Super Man 2016 Game 55.6 Game Class The next table present the class attributes. Attributes Description FPS Number determines how many times the draw() method will be called per second. FixedFPS Number determines how many times the animate() method will be called per second. Title String determines the window title of the game. aObjects List contains all objects in the game shutdown True/False value to end the game loop The next table present the class methods. Method Description refresh() Delete objects. settitle(cTitle) Set the window title using a string parameter. shutdown() Close the application. The next table present a group of keywords defined by the class. Keyword Description sprite Create new Sprite object and add it to the game objects. text Create new Text object and add it to the game objects. animate Create new Animate object and add it to the game objects. sound Create new Sound object and add it to the game objects. map Create new Map object and add it ot the game objects. 55.7 GameObject Class The next table present the class attributes. 55.6. Game Class 493
  • 3. Ring Documentation, Release 1.7 Attributes Description enabled True/False determine the state of the object (Active/Not Active) x Number determine the x position of the object. y Number determine the y position of the object. width Number determine the width of the object. height Number determine the height of the object. nIndex Number determine the index of the object in objects list. animate True/False to animate the object or not. move True/False to move the object using the keyboard or not. Scaled True/False to scale the object image or not. draw Function to be called when drawing the object. state Function to be called for object animation. keypress Function to be called when a key is pressed. mouse Function to be called when a mouse event happens. The next table present the class methods. Method Description keyboard(oGame,nkey) Check Keyboard Events mouse(oGame,nType,aMouseList) Check Mouse Events rgb(r,g,b) Return new color using the RGB (Red, Green and Blue) Values. 55.8 Sprite Class Parent Class : GameObject Class The next table present the class attributes. Attributes Description image String determine the image file name. point Number determine the limit of automatic movement of the object. direction Number determine the direction of movement. nstep Number determine the increment/decrement during movement. type Number determine the object type in the game (Optional). transparent True/False value determine if the image is transparent. The next table present the class methods. Method Description Draw(oGame) Draw the object 55.9 Text Class Parent Class : Sprite Class The next table present the class attributes. Attributes Description size Number determine the font size font String determine the font file name text String determine the text to be displayed color Number determine the color The next table present the class methods. 55.8. Sprite Class 494
  • 4. Ring Documentation, Release 1.7 Method Description Draw(oGame) Draw the object 55.10 Animate Class Parent Class : Sprite Class The next table present the class attributes. Attributes Description frames Number determine the number of frames frame Number determine the active frame framewidth Number determine the frame width. animate True/False determine using animate or not. scaled True/False determine scaling image or not. The next table present the class methods. Method Description Draw(oGame) Draw the object 55.11 Sound Class Parent Class : GameObject Class The next table present the class attributes. Attributes Description file String determine the sound file name. once True/False determine to play the file one time or not (loop). The next table present the class methods. Method Description playsound() Play the sound file 55.12 Map Class Parent Class : Sprite Class The next table present the class attributes. Attributes Description aMap List determine the map content using numbers. aImages List determine the image used for each number in the map. BlockWidth Number determine the block width (default = 32). BlockHeight Number determine the block height (default = 32). Animate True/False determine the animation status. The next table present the class methods. Method Description getvalue(x,y) Return the item value in the Map according to the visible part 55.10. Animate Class 495
  • 5. Ring Documentation, Release 1.7 55.13 Using the Game Engine - Creating the Game Window Load "gameengine.ring" # Give Control to the Game Engine func main # Called by the Game Engine oGame = New Game # Create the Game Object { title = "My First Game" } # Start the Events Loop Note: if you want to define global variables, this must be before load “gameengine.ring” because this instruction will give the control to the game engine. Screen Shot: 55.14 Using the Game Engine - Drawing Text Load "gameengine.ring" # Give Control to the Game Engine func main # Called by the Game Engine 55.13. Using the Game Engine - Creating the Game Window 496
  • 6. Ring Documentation, Release 1.7 oGame = New Game # Create the Game Object { title = "My First Game" text { x = 10 y=50 animate = false size = 20 file = "fonts/pirulen.ttf" text = "game development using ring is very fun!" color = rgb(0,0,0) } } # Start the Events Loop Screen Shot: 55.15 Using the Game Engine - Moving Text Load "gameengine.ring" # Give Control to the Game Engine func main # Called by the Game Engine oGame = New Game # Create the Game Object 55.15. Using the Game Engine - Moving Text 497
  • 7. Ring Documentation, Release 1.7 { title = "My First Game" text { x = 10 y=50 animate = false size = 20 file = "fonts/pirulen.ttf" text = "game development using ring is very fun!" color = rgb(0,0,0) # Color = black } text { x = 10 y=150 # Animation Part ===================================== animate = true # Use Animation direction = GE_DIRECTION_INCVERTICAL # Increase y point = 400 # Continue until y=400 nStep = 3 # Each time y+= 3 #===================================================== size = 20 file = "fonts/pirulen.ttf" text = "welcome to the real world!" color = rgb(0,0,255) # Color = Blue } } # Start the Events Loop Screen Shot: 55.15. Using the Game Engine - Moving Text 498
  • 8. Ring Documentation, Release 1.7 55.16 Using the Game Engine - Playing Sound Load "gameengine.ring" # Give Control to the Game Engine func main # Called by the Game Engine oGame = New Game # Create the Game Object { title = "My First Game" text { x = 10 y=50 animate = false size = 20 file = "fonts/pirulen.ttf" text = "game development using ring is very fun!" color = rgb(0,0,0) # Color = black } text { x = 10 y=150 # Animation Part ====================================== animate = true # Use Animation direction = GE_DIRECTION_INCVERTICAL # Increase y 55.16. Using the Game Engine - Playing Sound 499
  • 9. Ring Documentation, Release 1.7 point = 400 # Continue until y=400 nStep = 3 # Each time y+= 3 #====================================================== size = 20 file = "fonts/pirulen.ttf" text = "welcome to the real world!" color = rgb(0,0,255) # Color = Blue } Sound { # Play Sound file = "sound/music1.wav" # Sound File Name } } # Start the Events Loop 55.17 Using the Game Engine - Animation Load "gameengine.ring" # Give Control to the Game Engine func main # Called by the Game Engine oGame = New Game # Create the Game Object { title = "My First Game" animate { file = "images/fire.png" x = 100 y = 200 framewidth = 40 height = 42 nStep = 3 # Used for delay transparent = true state = func oGame,oSelf { # Called by engine each frame oSelf { nStep-- if nStep = 0 nStep = 3 if frame < 13 # we have 13 frames in animation frame++ # move to next frame else oGame.remove(oself.nIndex) # remove object ok ok } } } } # Start the Events Loop 55.17. Using the Game Engine - Animation 500
  • 10. Ring Documentation, Release 1.7 55.18 Using the Game Engine - Animation and Functions Load "gameengine.ring" # Give Control to the Game Engine func main # Called by the Game Engine oGame = New Game # Create the Game Object { title = "My First Game" for x = 70 to 700 step 50 for y = 70 to 500 step 50 showfire(oGame,x,y) next next } # Start the Events Loop func showfire oGame,nX,nY oGame { animate { file = "images/fire.png" x = nX 55.18. Using the Game Engine - Animation and Functions 501