Sunteți pe pagina 1din 10

Ring Documentation, Release 1.5.

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:

52.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

52.15. Using the Game Engine - Moving Text 455


Ring Documentation, Release 1.5.4

{
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:

52.15. Using the Game Engine - Moving Text 456


Ring Documentation, Release 1.5.4

52.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

52.16. Using the Game Engine - Playing Sound 457


Ring Documentation, Release 1.5.4

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

52.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

52.17. Using the Game Engine - Animation 458


Ring Documentation, Release 1.5.4

52.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

52.18. Using the Game Engine - Animation and Functions 459


Ring Documentation, Release 1.5.4

y = nY
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
frame=1
ok
ok
}
}
}
}

52.18. Using the Game Engine - Animation and Functions 460


Ring Documentation, Release 1.5.4

52.19 Using the Game Engine - Sprite - Automatic Movement using


Keyboard
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=true # we can move it using keyboard arrows
Scaled=true
}
} # Start the Events Loop

52.19. Using the Game Engine - Sprite - Automatic Movement using Keyboard 461
Ring Documentation, Release 1.5.4

52.20 Using the Game Engine - Sprite - Keypress 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
}
}
}
} # Start the Events Loop

52.21 Using the Game Engine - Sprite - Mouse 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 {

52.20. Using the Game Engine - Sprite - Keypress event 462


Ring Documentation, Release 1.5.4

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

52.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 {

52.22. Using the Game Engine - Sprite - State event 463


Ring Documentation, Release 1.5.4

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

52.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

52.23. Using the Game Engine - Animate - Events 464

S-ar putea să vă placă și