Sei sulla pagina 1di 10

Ring Documentation, Release 1.5.

Attributes Description
enabled True/False determine the state of the object (Active/Not Active)
x Number determine the x position of the object.
y Number determine the y position of the object.
width Number determine the width of the object.
height Number determine the height of the object.
nIndex Number determine the index of the object in objects list.
animate True/False to animate the object or not.
move True/False to move the object using the keyboard or not.
Scaled True/False to scale the object image or not.
draw Function to be called when drawing the object.
state Function to be called for object animation.
keypress Function to be called when a key is pressed.
mouse Function to be called when a mouse event happens.
The next table present the class methods.
Method Description
keyboard(oGame,nkey) Check Keyboard Events
mouse(oGame,nType,aMouseList) Check Mouse Events
rgb(r,g,b) Return new color using the RGB (Red, Green and Blue) Values.

52.8 Sprite Class

Parent Class : GameObject Class


The next table present the class attributes.
Attributes Description
image String determine the image file name.
point Number determine the limit of automatic movement of the object.
direction Number determine the direction of movement.
nstep Number determine the increment/decrement during movement.
type Number determine the object type in the game (Optional).
transparent True/False value determine if the image is transparent.
The next table present the class methods.
Method Description
Draw(oGame) Draw the object

52.9 Text Class

Parent Class : Sprite Class


The next table present the class attributes.
Attributes Description
size Number determine the font size
font String determine the font file name
text String determine the text to be displayed
color Number determine the color
The next table present the class methods.

52.8. Sprite Class 435


Ring Documentation, Release 1.5.1

Method Description
Draw(oGame) Draw the object

52.10 Animate Class

Parent Class : Sprite Class


The next table present the class attributes.
Attributes Description
frames Number determine the number of frames
frame Number determine the active frame
framewidth Number determine the frame width.
animate True/False determine using animate or not.
scaled True/False determine scaling image or not.
The next table present the class methods.
Method Description
Draw(oGame) Draw the object

52.11 Sound Class

Parent Class : GameObject Class


The next table present the class attributes.
Attributes Description
file String determine the sound file name.
once True/False determine to play the file one time or not (loop).
The next table present the class methods.
Method Description
playsound() Play the sound file

52.12 Map Class

Parent Class : Sprite Class


The next table present the class attributes.
Attributes Description
aMap List determine the map content using numbers.
aImages List determine the image used for each number in the map.
BlockWidth Number determine the block width (default = 32).
BlockHeight Number determine the block height (default = 32).
Animate True/False determine the animation status.
The next table present the class methods.
Method Description
getvalue(x,y) Return the item value in the Map according to the visible part

52.10. Animate Class 436


Ring Documentation, Release 1.5.1

52.13 Using the Game Engine - Creating the Game Window


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"
} # Start the Events Loop

Note: if you want to define global variables, this must be before load gameengine.ring because this instruction will
give the control to the game engine.

Screen Shot:

52.14 Using the Game Engine - Drawing Text


Load "gameengine.ring" # Give Control to the Game Engine

func main # Called by the Game Engine

52.13. Using the Game Engine - Creating the Game Window 437
Ring Documentation, Release 1.5.1

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 438


Ring Documentation, Release 1.5.1

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


Ring Documentation, Release 1.5.1

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 440


Ring Documentation, Release 1.5.1

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 441


Ring Documentation, Release 1.5.1

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 442


Ring Documentation, Release 1.5.1

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 443


Ring Documentation, Release 1.5.1

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 444

Potrebbero piacerti anche