SlideShare a Scribd company logo
Ring Documentation, Release 1.6
Switch nKey
on KEY_LEFT
x -= 10
on KEY_RIGHT
x += 10
on KEY_UP
y -= 10
on KEY_DOWN
y += 10
off
}
}
mouse = func oGame,oSelf,nType,aMouseList {
if nType = GE_MOUSE_UP
oSelf {
x = aMouseList[GE_MOUSE_X]
y = aMouseList[GE_MOUSE_Y]
}
ok
}
}
} # Start the Events Loop
53.22 Using the Game Engine - Sprite - State event
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"
sprite
{
type = GE_TYPE_PLAYER # Just for our usage
x=400 y=400 width=100 height=100
file = "images/player.png"
transparent = true
Animate=false
Move=false # Custom Movement
Scaled=true
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
}
}
mouse = func oGame,oSelf,nType,aMouseList {
53.22. Using the Game Engine - Sprite - State event 483
Ring Documentation, Release 1.6
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
53.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
53.23. Using the Game Engine - Animate - Events 484
Ring Documentation, Release 1.6
# 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:
53.23. Using the Game Engine - Animate - Events 485
Ring Documentation, Release 1.6
53.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],
53.24. Using the Game Engine - Map 486
Ring Documentation, Release 1.6
[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:
53.24. Using the Game Engine - Map 487
Ring Documentation, Release 1.6
53.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
53.25. Using the Game Engine - Map Events 488
Ring Documentation, Release 1.6
Screen Shot:
53.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)
53.26. Using the Game Engine - Object and Drawing 489
Ring Documentation, Release 1.6
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:
53.26. Using the Game Engine - Object and Drawing 490
Ring Documentation, Release 1.6
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
}
}
53.26. Using the Game Engine - Object and Drawing 491
Ring Documentation, Release 1.6
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:
53.27 Stars Fighter Game
The Stars Fighter source code
53.27. Stars Fighter Game 492

More Related Content

PDF
The Ring programming language version 1.5.2 book - Part 49 of 181
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 50 of 185
PDF
The Ring programming language version 1.8 book - Part 56 of 202
PDF
The Ring programming language version 1.2 book - Part 37 of 84
PDF
The Ring programming language version 1.7 book - Part 54 of 196
PDF
The Ring programming language version 1.10 book - Part 61 of 212
PDF
The Ring programming language version 1.3 book - Part 39 of 88
The Ring programming language version 1.5.2 book - Part 49 of 181
The Ring programming language version 1.5.1 book - Part 48 of 180
The Ring programming language version 1.5.4 book - Part 50 of 185
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.2 book - Part 37 of 84
The Ring programming language version 1.7 book - Part 54 of 196
The Ring programming language version 1.10 book - Part 61 of 212
The Ring programming language version 1.3 book - Part 39 of 88

What's hot (19)

PDF
The Ring programming language version 1.5.3 book - Part 49 of 184
PDF
The Ring programming language version 1.9 book - Part 59 of 210
PDF
The Ring programming language version 1.3 book - Part 40 of 88
PDF
The Ring programming language version 1.6 book - Part 51 of 189
PDF
The Ring programming language version 1.9 book - Part 60 of 210
PDF
The Ring programming language version 1.5.2 book - Part 48 of 181
PDF
The Ring programming language version 1.5.3 book - Part 50 of 184
PDF
The Ring programming language version 1.5 book - Part 9 of 31
PDF
The Ring programming language version 1.5.4 book - Part 49 of 185
PDF
The Ring programming language version 1.10 book - Part 60 of 212
PDF
The Ring programming language version 1.3 book - Part 43 of 88
PDF
The Ring programming language version 1.5.1 book - Part 47 of 180
PDF
The Ring programming language version 1.3 book - Part 52 of 88
PDF
The Ring programming language version 1.5.1 book - Part 49 of 180
PDF
The Ring programming language version 1.2 book - Part 38 of 84
PPTX
Game dev 101 part 3
PDF
The Ring programming language version 1.4.1 book - Part 15 of 31
PDF
The Ring programming language version 1.3 book - Part 42 of 88
PDF
The Ring programming language version 1.8 book - Part 55 of 202
The Ring programming language version 1.5.3 book - Part 49 of 184
The Ring programming language version 1.9 book - Part 59 of 210
The Ring programming language version 1.3 book - Part 40 of 88
The Ring programming language version 1.6 book - Part 51 of 189
The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.5.2 book - Part 48 of 181
The Ring programming language version 1.5.3 book - Part 50 of 184
The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5.4 book - Part 49 of 185
The Ring programming language version 1.10 book - Part 60 of 212
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.5.1 book - Part 47 of 180
The Ring programming language version 1.3 book - Part 52 of 88
The Ring programming language version 1.5.1 book - Part 49 of 180
The Ring programming language version 1.2 book - Part 38 of 84
Game dev 101 part 3
The Ring programming language version 1.4.1 book - Part 15 of 31
The Ring programming language version 1.3 book - Part 42 of 88
The Ring programming language version 1.8 book - Part 55 of 202
Ad

Similar to The Ring programming language version 1.6 book - Part 52 of 189 (17)

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 60 of 184
PDF
The Ring programming language version 1.7 book - Part 53 of 196
PDF
The Ring programming language version 1.4 book - Part 14 of 30
PDF
The Ring programming language version 1.3 book - Part 38 of 88
PDF
The Ring programming language version 1.2 book - Part 36 of 84
PDF
The Ring programming language version 1.5.3 book - Part 48 of 184
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.10 book - Part 64 of 212
PDF
The Ring programming language version 1.5.1 book - Part 50 of 180
PDF
The Ring programming language version 1.8 book - Part 58 of 202
PDF
The Ring programming language version 1.5.4 book - Part 53 of 185
PDF
The Ring programming language version 1.6 book - Part 54 of 189
PDF
The Ring programming language version 1.5.2 book - Part 51 of 181
PDF
The Ring programming language version 1.5.1 book - Part 54 of 180
PDF
The Ring programming language version 1.8 book - Part 62 of 202
The Ring programming language version 1.5.3 book - Part 59 of 184
The Ring programming language version 1.5.3 book - Part 60 of 184
The Ring programming language version 1.7 book - Part 53 of 196
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.2 book - Part 36 of 84
The Ring programming language version 1.5.3 book - Part 48 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.10 book - Part 64 of 212
The Ring programming language version 1.5.1 book - Part 50 of 180
The Ring programming language version 1.8 book - Part 58 of 202
The Ring programming language version 1.5.4 book - Part 53 of 185
The Ring programming language version 1.6 book - Part 54 of 189
The Ring programming language version 1.5.2 book - Part 51 of 181
The Ring programming language version 1.5.1 book - Part 54 of 180
The Ring programming language version 1.8 book - Part 62 of 202
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
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
System and Network Administration Chapter 2
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
AI in Product Development-omnex systems
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Transform Your Business with a Software ERP System
top salesforce developer skills in 2025.pdf
How Creative Agencies Leverage Project Management Software.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
System and Network Administration Chapter 2
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
wealthsignaloriginal-com-DS-text-... (1).pdf
AI in Product Development-omnex systems
VVF-Customer-Presentation2025-Ver1.9.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Design an Analysis of Algorithms II-SECS-1021-03
L1 - Introduction to python Backend.pptx
Reimagine Home Health with the Power of Agentic AI​
Transform Your Business with a Software ERP System

The Ring programming language version 1.6 book - Part 52 of 189

  • 1. Ring Documentation, Release 1.6 Switch nKey on KEY_LEFT x -= 10 on KEY_RIGHT x += 10 on KEY_UP y -= 10 on KEY_DOWN y += 10 off } } mouse = func oGame,oSelf,nType,aMouseList { if nType = GE_MOUSE_UP oSelf { x = aMouseList[GE_MOUSE_X] y = aMouseList[GE_MOUSE_Y] } ok } } } # Start the Events Loop 53.22 Using the Game Engine - Sprite - State event 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" sprite { type = GE_TYPE_PLAYER # Just for our usage x=400 y=400 width=100 height=100 file = "images/player.png" transparent = true Animate=false Move=false # Custom Movement Scaled=true 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 } } mouse = func oGame,oSelf,nType,aMouseList { 53.22. Using the Game Engine - Sprite - State event 483
  • 2. Ring Documentation, Release 1.6 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 53.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 53.23. Using the Game Engine - Animate - Events 484
  • 3. Ring Documentation, Release 1.6 # 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: 53.23. Using the Game Engine - Animate - Events 485
  • 4. Ring Documentation, Release 1.6 53.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], 53.24. Using the Game Engine - Map 486
  • 5. Ring Documentation, Release 1.6 [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: 53.24. Using the Game Engine - Map 487
  • 6. Ring Documentation, Release 1.6 53.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 53.25. Using the Game Engine - Map Events 488
  • 7. Ring Documentation, Release 1.6 Screen Shot: 53.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) 53.26. Using the Game Engine - Object and Drawing 489
  • 8. Ring Documentation, Release 1.6 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: 53.26. Using the Game Engine - Object and Drawing 490
  • 9. Ring Documentation, Release 1.6 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 } } 53.26. Using the Game Engine - Object and Drawing 491
  • 10. Ring Documentation, Release 1.6 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: 53.27 Stars Fighter Game The Stars Fighter source code 53.27. Stars Fighter Game 492