Sie sind auf Seite 1von 10

Ring Documentation, Release 1.

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

47.16. Using the Game Engine - Playing Sound 358


Ring Documentation, Release 1.3

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

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

47.17. Using the Game Engine - Animation 359


Ring Documentation, Release 1.3

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

47.18. Using the Game Engine - Animation and Functions 360


Ring Documentation, Release 1.3

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
}
}
}
}

47.18. Using the Game Engine - Animation and Functions 361


Ring Documentation, Release 1.3

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

47.19. Using the Game Engine - Sprite - Automatic Movement using Keyboard 362
Ring Documentation, Release 1.3

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

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

47.20. Using the Game Engine - Sprite - Keypress event 363


Ring Documentation, Release 1.3

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

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

47.22. Using the Game Engine - Sprite - State event 364


Ring Documentation, Release 1.3

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

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

47.23. Using the Game Engine - Animate - Events 365


Ring Documentation, Release 1.3

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

47.23. Using the Game Engine - Animate - Events 366


Ring Documentation, Release 1.3

47.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],

47.24. Using the Game Engine - Map 367

Das könnte Ihnen auch gefallen