Sie sind auf Seite 1von 10

Ring Documentation, Release 1.

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

45.18. Using the Game Engine - Animation and Functions 340


Ring Documentation, Release 1.2

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

45.18. Using the Game Engine - Animation and Functions 341


Ring Documentation, Release 1.2

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

45.19. Using the Game Engine - Sprite - Automatic Movement using Keyboard 342
Ring Documentation, Release 1.2

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

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

45.20. Using the Game Engine - Sprite - Keypress event 343


Ring Documentation, Release 1.2

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

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

45.22. Using the Game Engine - Sprite - State event 344


Ring Documentation, Release 1.2

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

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

45.23. Using the Game Engine - Animate - Events 345


Ring Documentation, Release 1.2

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

45.23. Using the Game Engine - Animate - Events 346


Ring Documentation, Release 1.2

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

45.24. Using the Game Engine - Map 347


Ring Documentation, Release 1.2

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

45.24. Using the Game Engine - Map 348


Ring Documentation, Release 1.2

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

45.25. Using the Game Engine - Map Events 349

Das könnte Ihnen auch gefallen