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

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

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
Difference Between Website and Web Application.pdf
PPTX
AI Tools Revolutionizing Software Development Workflows
PPTX
Beige and Black Minimalist Project Deck Presentation (1).pptx
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PPTX
Presentation - Summer Internship at Samatrix.io_template_2.pptx
PDF
Top AI Tools for Project Managers: My 2025 AI Stack
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
Folder Lock 10.1.9 Crack With Serial Key
PPTX
Lesson-3-Operation-System-Support.pptx-I
PPTX
UNIT II: Software design, software .pptx
PDF
Beginner’s Guide to Kentico Xperience Step by Step.pdf
PPTX
Relevance Tuning with Genetic Algorithms
PPTX
Greedy best-first search algorithm always selects the path which appears best...
PDF
Adlice Diag Crack With Serial Key Free Download 2025
PPTX
Foundations of Marketo Engage: Nurturing
PPT
3.Software Design for software engineering
PPTX
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
PDF
How to Write Automated Test Scripts Using Selenium.pdf
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
PDF
OpenColorIO Virtual Town Hall - August 2025
Difference Between Website and Web Application.pdf
AI Tools Revolutionizing Software Development Workflows
Beige and Black Minimalist Project Deck Presentation (1).pptx
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
Presentation - Summer Internship at Samatrix.io_template_2.pptx
Top AI Tools for Project Managers: My 2025 AI Stack
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Folder Lock 10.1.9 Crack With Serial Key
Lesson-3-Operation-System-Support.pptx-I
UNIT II: Software design, software .pptx
Beginner’s Guide to Kentico Xperience Step by Step.pdf
Relevance Tuning with Genetic Algorithms
Greedy best-first search algorithm always selects the path which appears best...
Adlice Diag Crack With Serial Key Free Download 2025
Foundations of Marketo Engage: Nurturing
3.Software Design for software engineering
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
How to Write Automated Test Scripts Using Selenium.pdf
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
OpenColorIO Virtual Town Hall - August 2025

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