SlideShare a Scribd company logo
Ring Documentation, Release 1.10
if nType = GE_MOUSE_UP
oSelf {
x = aMouseList[GE_MOUSE_X]
y = aMouseList[GE_MOUSE_Y]
}
ok
}
state = func oGame,oSelf {
oself {
if x < 0 x = 0 ok
if y < 0 y = 0 ok
if x > ogame.width-width
x= ogame.width - width ok
if y > ogame.height-height
y=ogame.height - height ok
}
}
}
} # Start the Events Loop
60.23 Using the Game Engine - Animate - Events
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/fbbird.png"
x = 10
y = 10
framewidth = 20
scaled = true
height = 50
width = 50
nStep = 3
transparent = true
state = func oGame,oSelf {
oSelf {
# Animation
nStep--
if nStep = 0
nStep = 3
if frame < 3
frame++
else
frame=1
ok
ok
60.23. Using the Game Engine - Animate - Events 568
Ring Documentation, Release 1.10
# Move Down
y += 3
if y > 550 y=550 ok
}
}
keypress = func ogame,oself,nKey {
oself {
if nkey = key_space
y -= 55
if y<=0 y=0 ok
ok
}
}
mouse = func ogame,oself,nType,aMouseList {
if nType = GE_MOUSE_UP
cFunc = oself.keypress
call cFunc(oGame,oSelf,Key_Space)
ok
}
}
} # Start the Events Loop
Screen Shot:
60.23. Using the Game Engine - Animate - Events 569
Ring Documentation, Release 1.10
60.24 Using the Game Engine - Map
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"
Map {
blockwidth = 80
blockheight = 80
aMap = [
[0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
60.24. Using the Game Engine - Map 570
Ring Documentation, Release 1.10
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0]
]
aImages = ["images/fbwall.png",
"images/fbwallup.png",
"images/fbwalldown.png"]
state = func oGame,oSelf {
oSelf {
x -= 3
if x < - 2100 x = 0 ok
}
}
}
} # Start the Events Loop
Screen Shot:
60.24. Using the Game Engine - Map 571
Ring Documentation, Release 1.10
60.25 Using the Game Engine - Map Events
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"
Map {
blockwidth = 80
blockheight = 80
aMap = [
[0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0]
]
aImages = ["images/fbwall.png",
"images/fbwallup.png",
"images/fbwalldown.png"]
state = func oGame,oSelf {
oSelf {
x -= 3
if x < - 2100 x = 0 ok
}
}
mouse = func ogame,oself,nType,aMouseList {
if nType = GE_MOUSE_UP
oSelf {
mX = aMouseList[GE_MOUSE_X]
mY = aMouseList[GE_MOUSE_Y]
nValue = GetValue(mX,mY)
nRow = GetRow(mX,mY)
nCol = GetCol(mX,mY)
Switch nValue
On 1 aMap[nRow][nCol] = 0
On 2 aMap[nRow][nCol] = 0
On 3 aMap[nRow][nCol] = 0
On 0 aMap[nRow][nCol] = 1
Off
}
ok
}
}
} # Start the Events Loop
60.25. Using the Game Engine - Map Events 572
Ring Documentation, Release 1.10
Screen Shot:
60.26 Using the Game Engine - Object and Drawing
We can use the Object keyword (defined by the game engine) to create objects from the GameObject class.
Example:
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"
Object {
x = 0 y=300 width = 200 height=200
draw = func oGame,oSelf {
oSelf {
for t = 1 to 210
gl_draw_circle(x,y,t,
gl_map_rgb(t*random(255),
t*2,t*3),1)
60.26. Using the Game Engine - Object and Drawing 573
Ring Documentation, Release 1.10
next
}
}
state = func oGame,oSelf {
oSelf {
if x <= 800
x+= 3
else
x=0
ok
}
}
keypress = func oGame,oSelf,nKey {
oSelf {
Switch nKey
on KEY_LEFT
x -= 10
on KEY_RIGHT
x += 10
on KEY_UP
y -= 10
on KEY_DOWN
y += 10
off
}
}
}
} # Start the Events Loop
Screen Shot:
60.26. Using the Game Engine - Object and Drawing 574
Ring Documentation, Release 1.10
Example:
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"
Object {
x = 400 y=300 width = 200 height=200
draw = func oGame,oSelf {
oSelf {
for t = 1 to 210
gl_draw_rectangle(x+t,y+t,
x+t*2,y+t*2,
gl_map_rgb(t*random(255),
t*2,t*3),1)
gl_draw_rectangle(x+t*2,y+t*2,
x-t*2,y-t*2,
gl_map_rgb(t*random(255),
t*2,t*3),1)
next
}
}
60.26. Using the Game Engine - Object and Drawing 575
Ring Documentation, Release 1.10
keypress = func oGame,oSelf,nKey {
oSelf {
Switch nKey
on KEY_LEFT
x -= 10
on KEY_RIGHT
x += 10
on KEY_UP
y -= 10
on KEY_DOWN
y += 10
off
}
}
}
} # Start the Events Loop
Screen Shot:
60.27 Stars Fighter Game
The Stars Fighter source code
60.27. Stars Fighter Game 576
Ring Documentation, Release 1.10
# The Ring Standard Library
# Game Engine for 2D Games
# 2016, Mahmoud Fayed <msfclipper@yahoo.com>
oGameState = NULL
load "gameengine.ring"
func main
oGame = New Game
while true
oGameState = new GameState
oGame {
title = "Stars Fighter!"
sprite
{
file = "images/menu1.jpg"
x = 0 y=0 width=800 height = 600 scaled = true animate = false
keypress = func ogame,oself,nKey {
if nkey = key_esc or nKey = GE_AC_BACK
ogame.shutdown()
but nKey = key_space
oGameState.startplay=true
ogame.shutdown=true
ok
}
mouse = func ogame,oself,nType,aMouseList {
if nType = GE_MOUSE_UP
oGameState.startplay=true
ogame.shutdown=true
ok
}
}
text {
animate = false
size = 35
file = "fonts/pirulen.ttf"
text = "Stars Fighter"
x = 10 y=50
}
text {
animate = false
size = 25
file = "fonts/pirulen.ttf"
text = "Version 1.0"
x = 80 y=100
}
text {
animate = false
size = 16
file = "fonts/pirulen.ttf"
text = "(C) 2016, Mahmoud Fayed"
x = 45 y=140
}
60.27. Stars Fighter Game 577

More Related Content

PDF
The Ring programming language version 1.8 book - Part 56 of 202
PDF
The Ring programming language version 1.7 book - Part 54 of 196
PDF
The Ring programming language version 1.6 book - Part 52 of 189
PDF
The Ring programming language version 1.2 book - Part 37 of 84
PDF
The Ring programming language version 1.5.1 book - Part 48 of 180
PDF
The Ring programming language version 1.5.2 book - Part 49 of 181
PDF
The Ring programming language version 1.9 book - Part 60 of 210
PDF
The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.7 book - Part 54 of 196
The Ring programming language version 1.6 book - Part 52 of 189
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.2 book - Part 49 of 181
The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.5 book - Part 9 of 31

What's hot (20)

PDF
The Ring programming language version 1.5.4 book - Part 50 of 185
PDF
The Ring programming language version 1.3 book - Part 40 of 88
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
PDF
The Ring programming language version 1.5.3 book - Part 50 of 184
PDF
The Ring programming language version 1.6 book - Part 51 of 189
PDF
The Ring programming language version 1.7 book - Part 55 of 196
PDF
The Ring programming language version 1.2 book - Part 38 of 84
PDF
The Ring programming language version 1.5.1 book - Part 49 of 180
PDF
The Ring programming language version 1.8 book - Part 59 of 202
PDF
The Ring programming language version 1.9 book - Part 62 of 210
PDF
The Ring programming language version 1.8 book - Part 57 of 202
PDF
The Ring programming language version 1.4.1 book - Part 15 of 31
PDF
The Ring programming language version 1.3 book - Part 43 of 88
PDF
The Ring programming language version 1.3 book - Part 42 of 88
PDF
Writing Server in Python
PDF
The Ring programming language version 1.2 book - Part 39 of 84
PDF
The Ring programming language version 1.9 book - Part 61 of 210
PDF
The Ring programming language version 1.5.4 book - Part 65 of 185
PDF
The Ring programming language version 1.10 book - Part 62 of 212
The Ring programming language version 1.5.4 book - Part 50 of 185
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.9 book - Part 59 of 210
The Ring programming language version 1.3 book - Part 39 of 88
The Ring programming language version 1.5.3 book - Part 50 of 184
The Ring programming language version 1.6 book - Part 51 of 189
The Ring programming language version 1.7 book - Part 55 of 196
The Ring programming language version 1.2 book - Part 38 of 84
The Ring programming language version 1.5.1 book - Part 49 of 180
The Ring programming language version 1.8 book - Part 59 of 202
The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.8 book - Part 57 of 202
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 42 of 88
Writing Server in Python
The Ring programming language version 1.2 book - Part 39 of 84
The Ring programming language version 1.9 book - Part 61 of 210
The Ring programming language version 1.5.4 book - Part 65 of 185
The Ring programming language version 1.10 book - Part 62 of 212
Ad

Similar to The Ring programming language version 1.10 book - Part 61 of 212 (14)

PDF
The Ring programming language version 1.5.3 book - Part 60 of 184
PDF
The Ring programming language version 1.5.3 book - Part 59 of 184
PDF
The Ring programming language version 1.5.3 book - Part 49 of 184
PDF
The Ring programming language version 1.10 book - Part 60 of 212
PDF
The Ring programming language version 1.5.2 book - Part 48 of 181
PDF
The Ring programming language version 1.5.4 book - Part 49 of 185
PDF
The Ring programming language version 1.5.2 book - Part 52 of 181
PDF
The Ring programming language version 1.6 book - Part 55 of 189
PDF
The Ring programming language version 1.8 book - Part 55 of 202
PDF
The Ring programming language version 1.10 book - Part 63 of 212
PDF
The Ring programming language version 1.5.1 book - Part 47 of 180
PDF
The Ring programming language version 1.5.3 book - Part 62 of 184
PDF
The Ring programming language version 1.5.1 book - Part 50 of 180
PDF
The Ring programming language version 1.5.2 book - Part 51 of 181
The Ring programming language version 1.5.3 book - Part 60 of 184
The Ring programming language version 1.5.3 book - Part 59 of 184
The Ring programming language version 1.5.3 book - Part 49 of 184
The Ring programming language version 1.10 book - Part 60 of 212
The Ring programming language version 1.5.2 book - Part 48 of 181
The Ring programming language version 1.5.4 book - Part 49 of 185
The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.10 book - Part 63 of 212
The Ring programming language version 1.5.1 book - Part 47 of 180
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.5.1 book - Part 50 of 180
The Ring programming language version 1.5.2 book - Part 51 of 181
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
top salesforce developer skills in 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
history of c programming in notes for students .pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
medical staffing services at VALiNTRY
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Transform Your Business with a Software ERP System
PPTX
CHAPTER 2 - PM Management and IT Context
top salesforce developer skills in 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ai tools demonstartion for schools and inter college
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
history of c programming in notes for students .pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms I-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Reimagine Home Health with the Power of Agentic AI​
PTS Company Brochure 2025 (1).pdf.......
Softaken Excel to vCard Converter Software.pdf
Odoo POS Development Services by CandidRoot Solutions
medical staffing services at VALiNTRY
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Understanding Forklifts - TECH EHS Solution
How to Migrate SBCGlobal Email to Yahoo Easily
Operating system designcfffgfgggggggvggggggggg
Transform Your Business with a Software ERP System
CHAPTER 2 - PM Management and IT Context

The Ring programming language version 1.10 book - Part 61 of 212

  • 1. Ring Documentation, Release 1.10 if nType = GE_MOUSE_UP oSelf { x = aMouseList[GE_MOUSE_X] y = aMouseList[GE_MOUSE_Y] } ok } state = func oGame,oSelf { oself { if x < 0 x = 0 ok if y < 0 y = 0 ok if x > ogame.width-width x= ogame.width - width ok if y > ogame.height-height y=ogame.height - height ok } } } } # Start the Events Loop 60.23 Using the Game Engine - Animate - Events 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/fbbird.png" x = 10 y = 10 framewidth = 20 scaled = true height = 50 width = 50 nStep = 3 transparent = true state = func oGame,oSelf { oSelf { # Animation nStep-- if nStep = 0 nStep = 3 if frame < 3 frame++ else frame=1 ok ok 60.23. Using the Game Engine - Animate - Events 568
  • 2. Ring Documentation, Release 1.10 # Move Down y += 3 if y > 550 y=550 ok } } keypress = func ogame,oself,nKey { oself { if nkey = key_space y -= 55 if y<=0 y=0 ok ok } } mouse = func ogame,oself,nType,aMouseList { if nType = GE_MOUSE_UP cFunc = oself.keypress call cFunc(oGame,oSelf,Key_Space) ok } } } # Start the Events Loop Screen Shot: 60.23. Using the Game Engine - Animate - Events 569
  • 3. Ring Documentation, Release 1.10 60.24 Using the Game Engine - Map 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" Map { blockwidth = 80 blockheight = 80 aMap = [ [0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], 60.24. Using the Game Engine - Map 570
  • 4. Ring Documentation, Release 1.10 [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0] ] aImages = ["images/fbwall.png", "images/fbwallup.png", "images/fbwalldown.png"] state = func oGame,oSelf { oSelf { x -= 3 if x < - 2100 x = 0 ok } } } } # Start the Events Loop Screen Shot: 60.24. Using the Game Engine - Map 571
  • 5. Ring Documentation, Release 1.10 60.25 Using the Game Engine - Map Events 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" Map { blockwidth = 80 blockheight = 80 aMap = [ [0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0], [0,0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0] ] aImages = ["images/fbwall.png", "images/fbwallup.png", "images/fbwalldown.png"] state = func oGame,oSelf { oSelf { x -= 3 if x < - 2100 x = 0 ok } } mouse = func ogame,oself,nType,aMouseList { if nType = GE_MOUSE_UP oSelf { mX = aMouseList[GE_MOUSE_X] mY = aMouseList[GE_MOUSE_Y] nValue = GetValue(mX,mY) nRow = GetRow(mX,mY) nCol = GetCol(mX,mY) Switch nValue On 1 aMap[nRow][nCol] = 0 On 2 aMap[nRow][nCol] = 0 On 3 aMap[nRow][nCol] = 0 On 0 aMap[nRow][nCol] = 1 Off } ok } } } # Start the Events Loop 60.25. Using the Game Engine - Map Events 572
  • 6. Ring Documentation, Release 1.10 Screen Shot: 60.26 Using the Game Engine - Object and Drawing We can use the Object keyword (defined by the game engine) to create objects from the GameObject class. Example: 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" Object { x = 0 y=300 width = 200 height=200 draw = func oGame,oSelf { oSelf { for t = 1 to 210 gl_draw_circle(x,y,t, gl_map_rgb(t*random(255), t*2,t*3),1) 60.26. Using the Game Engine - Object and Drawing 573
  • 7. Ring Documentation, Release 1.10 next } } state = func oGame,oSelf { oSelf { if x <= 800 x+= 3 else x=0 ok } } keypress = func oGame,oSelf,nKey { oSelf { Switch nKey on KEY_LEFT x -= 10 on KEY_RIGHT x += 10 on KEY_UP y -= 10 on KEY_DOWN y += 10 off } } } } # Start the Events Loop Screen Shot: 60.26. Using the Game Engine - Object and Drawing 574
  • 8. Ring Documentation, Release 1.10 Example: 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" Object { x = 400 y=300 width = 200 height=200 draw = func oGame,oSelf { oSelf { for t = 1 to 210 gl_draw_rectangle(x+t,y+t, x+t*2,y+t*2, gl_map_rgb(t*random(255), t*2,t*3),1) gl_draw_rectangle(x+t*2,y+t*2, x-t*2,y-t*2, gl_map_rgb(t*random(255), t*2,t*3),1) next } } 60.26. Using the Game Engine - Object and Drawing 575
  • 9. Ring Documentation, Release 1.10 keypress = func oGame,oSelf,nKey { oSelf { Switch nKey on KEY_LEFT x -= 10 on KEY_RIGHT x += 10 on KEY_UP y -= 10 on KEY_DOWN y += 10 off } } } } # Start the Events Loop Screen Shot: 60.27 Stars Fighter Game The Stars Fighter source code 60.27. Stars Fighter Game 576
  • 10. Ring Documentation, Release 1.10 # The Ring Standard Library # Game Engine for 2D Games # 2016, Mahmoud Fayed <msfclipper@yahoo.com> oGameState = NULL load "gameengine.ring" func main oGame = New Game while true oGameState = new GameState oGame { title = "Stars Fighter!" sprite { file = "images/menu1.jpg" x = 0 y=0 width=800 height = 600 scaled = true animate = false keypress = func ogame,oself,nKey { if nkey = key_esc or nKey = GE_AC_BACK ogame.shutdown() but nKey = key_space oGameState.startplay=true ogame.shutdown=true ok } mouse = func ogame,oself,nType,aMouseList { if nType = GE_MOUSE_UP oGameState.startplay=true ogame.shutdown=true ok } } text { animate = false size = 35 file = "fonts/pirulen.ttf" text = "Stars Fighter" x = 10 y=50 } text { animate = false size = 25 file = "fonts/pirulen.ttf" text = "Version 1.0" x = 80 y=100 } text { animate = false size = 16 file = "fonts/pirulen.ttf" text = "(C) 2016, Mahmoud Fayed" x = 45 y=140 } 60.27. Stars Fighter Game 577