10
Ring Documentation, Release 1.2 } } } showfire(oGame,oGame.aObjects[oGameState.PlayerIndex].x+40, oGame.aObjects[oGameState.PlayerIndex].y+40) oGame.aObjects[oGameState.PlayerIndex].enabled = false oGame.remove(oGameState.PlayerIndex) ok func showfire oGame,nX,nY oGame { animate { file = "images/fire.png" x = nX y = nY framewidth = 40 height = 42 nStep = 3 transparent = true state = func oGame,oSelf { oSelf { nStep-- if nStep = 0 nStep = 3 if frame < 13 frame++ else frame=1 oGame.remove(oself.nIndex) ok ok } } } } class gamestate score = 0 level = 1 enemies = 1 value = 100 playerindex = 2 gameresult = false startplay=false Screen Shot: 45.27. Stars Fighter Game 360

The Ring programming language version 1.2 book - Part 39 of 84

Embed Size (px)

Citation preview

Page 1: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

}}

}showfire(oGame,oGame.aObjects[oGameState.PlayerIndex].x+40,

oGame.aObjects[oGameState.PlayerIndex].y+40)oGame.aObjects[oGameState.PlayerIndex].enabled = falseoGame.remove(oGameState.PlayerIndex)

ok

func showfire oGame,nX,nYoGame {

animate {file = "images/fire.png"x = nXy = nYframewidth = 40height = 42nStep = 3transparent = truestate = func oGame,oSelf {

oSelf {nStep--if nStep = 0

nStep = 3if frame < 13frame++

elseframe=1oGame.remove(oself.nIndex)

okok

}}

}}

class gamestatescore = 0level = 1enemies = 1value = 100playerindex = 2gameresult = falsestartplay=false

Screen Shot:

45.27. Stars Fighter Game 360

Page 2: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

45.28 Flappy Bird 3000 Game

The Flappy Bird 3000 Game source code

# The Ring Standard Library# Game Engine for 2D Games# 2016, Mahmoud Fayed <[email protected]>

oGameState = NULL

Load "gameengine.ring"

func main

oGame = New Game

while true

oGameState = New GameState

oGame {

45.28. Flappy Bird 3000 Game 361

Page 3: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

title = "Flappy Bird 3000"sprite{

file = "images/fbback.png"x = 0 y=0 width=800 height = 600 scaled = true animate = falsekeypress = func ogame,oself,nKey {

if nkey = key_esc or nKey = GE_AC_BACKogame.shutdown()

but nKey = key_spaceoGameState.startplay=trueogame.shutdown=true

ok}mouse = func ogame,oself,nType,aMouseList {

if nType = GE_MOUSE_UPcFunc = oself.keypresscall cFunc(oGame,oSelf,Key_Space)

ok}

}text {

animate = falsesize = 35file = "fonts/pirulen.ttf"text = "Flappy Bird 3000"x = 150 y=50

}text {

animate = falsesize = 25file = "fonts/pirulen.ttf"text = "Version 1.0"x = 280 y=100

}text {

animate = falsesize = 16file = "fonts/pirulen.ttf"text = "(C) 2016, Mahmoud Fayed"x = 245 y=140

}

text {animate = falsesize = 25file = "fonts/pirulen.ttf"text = "To Win Get Score = 3000"x = 150 y=270

}

text {animate = falsesize = 25file = "fonts/pirulen.ttf"text = "Press Space to start"x = 190 y=470

}text {

45.28. Flappy Bird 3000 Game 362

Page 4: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

animate = falsesize = 20file = "fonts/pirulen.ttf"text = "Press Esc to Exit"x = 260 y=510

}

animate {file = "images/fbbird.png"x = 200y = 200framewidth = 20scaled = trueheight = 50width = 50nStep = 3transparent = trueanimate = truedirection = ge_direction_randomstate = func oGame,oSelf {

oSelf {nStep--if nStep = 0nStep = 3if frame < 3

frame++else

frame=1ok

okif x <= 0 x=0 okif y <= 0 y=0 okif x >= 750 x= 750 okif y > 550 y=550 ok

}}

}

Sound {file = "sound/music2.wav"

}}if oGameState.startplay

oGame.refresh()playstart(oGame)oGame.refresh()

ok

end

func playstart oGame

oGame {FPS = 60FixedFPS = 120Title = "Flappy Bird 3000"Sprite {

45.28. Flappy Bird 3000 Game 363

Page 5: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

file = "images/fbback.png"x = 0 y=0 width=800 height = 600 scaled = true animate = falsekeypress = func ogame,oself,nKey {

if nkey = key_esc or nKey = GE_AC_BACKogame.shutdown()

ok}

}

Map {blockwidth = 80blockheight = 80aMap = [

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

]newmap(aMap)aImages = ["images/fbwall.png","images/fbwallup.png",

"images/fbwalldown.png"]state = func oGame,oSelf {

if oGameState.gameresult = falsepx = oGame.aObjects[3].xpy = oGame.aObjects[3].yoSelf {

x -= 3if x < - 2100x = 0newmap(aMap)

oknCol = getcol(px,0)if nCol=11 or nCol=15 or nCol=19 or nCol=23 or nCol=27if nCol != oGameState.lastcol

oGameState.lastcol = nColoGameState.Score += 100oGame { Sound {once = truefile = "sound/sfx_point.wav"

} }checkwin(oGame)

okok

}if oSelf.getvalue(px+40,py) != 0 or

oSelf.getvalue(px+40,py+40) != 0 oroSelf.getvalue(px,py) != 0 oroSelf.getvalue(px,py+40) != 0

oGameState.gameresult = trueoGame {text {

point = 550size = 30nStep = 3

45.28. Flappy Bird 3000 Game 364

Page 6: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

file = "fonts/pirulen.ttf"text = "Game Over !!!"x = 500 y=10state = func ogame,oself {if oself.y >= 550

ogame.shutdown = trueok

if oself.y = 90ogame {Sound {

once = truefile = "sound/sfx_die.wav"

}}

ok}

}Sound {

once = truefile = "sound/sfx_hit.wav"

}}

okok

}}

animate {file = "images/fbbird.png"x = 10y = 10framewidth = 20scaled = trueheight = 50width = 50nStep = 3transparent = truestate = func oGame,oSelf {

oSelf {nStep--if nStep = 0

nStep = 3if frame < 3frame++

elseframe=1

okok

}

if not oGameState.playerwinoGameState.down --if oGameState.down = 0

oGameState.down = 3oself {y += 25if y > 550 y=550 ok

}

45.28. Flappy Bird 3000 Game 365

Page 7: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

okok

}keypress = func ogame,oself,nKey {

if oGameState.gameresult = falseoself {

if nkey = key_spacey -= 55oGameState.down = 60if y<=0 y=0 ok

ok}

ok}mouse = func ogame,oself,nType,aMouseList {

if nType = GE_MOUSE_UPcFunc = oself.keypresscall cFunc(oGame,oSelf,Key_Space)

ok}

}

text {animate = falsepoint = 400size = 30file = "fonts/pirulen.ttf"text = "Score : " + oGameState.scorex = 500 y=10state = func oGame,oSelf {

oSelf { text = "Score : " + oGameState.score }}

}

}

func newmap aMapaV = [[1,1,3,0,0,2,1,1],[1,3,0,0,0,2,1,1],[1,1,1,3,0,2,1,1],[1,1,1,3,0,0,0,0],[0,0,0,0,2,1,1,1],[0,0,2,1,1,1,1,1],[0,0,0,2,1,1,1,1],[1,1,1,3,0,2,1,1],[1,1,1,1,1,3,0,0],[3,0,0,2,1,1,1,1],[3,0,0,2,3,0,0,2]]for x = 10 to 24 step 4

aVar = aV[ (random(10)+1) ]for y = 1 to 8aMap[y][x] = aVar[y]

nextnext

45.28. Flappy Bird 3000 Game 366

Page 8: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

func checkwin ogameif oGameState.score = 3000

oGameState.gameresult = trueoGameState.playerwin = trueoGame {text {

point = 400size = 30nStep = 3file = "fonts/pirulen.ttf"text = "You Win !!!"x = 500 y=10state = func ogame,oself {

if oself.y >= 400ogame.shutdown = trueoGameState.value = 0

ok}

}}

ok

Class GameStatedown = 3gameresult = falseScore = 0startplay=falselastcol = 0playerwin = false

Screen Shot:

45.28. Flappy Bird 3000 Game 367

Page 9: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

45.29 Super Man 2016 Game

The Super Man 2016 Game source code

# The Ring Standard Library# Game Engine for 2D Games# 2016, Mahmoud Fayed <[email protected]>

oGameState = NULL

Load "gameengine.ring"

func main

oGame = New Game

while true

oGameState = new GameState

oGame {title = "Super Man 2016"

45.29. Super Man 2016 Game 368

Page 10: The Ring programming language version 1.2 book - Part 39 of 84

Ring Documentation, Release 1.2

sprite{

file = "images/superman.jpg"x = 0 y=0 width=800 height = 600 scaled = true animate = falsekeypress = func ogame,oself,nKey {

if nkey = key_esc or nKey = GE_AC_BACKogame.shutdown()

but nKey = key_spaceoGameState.startplay=trueogame.shutdown=true

ok}mouse = func ogame,oself,nType,aMouseList {

if nType = GE_MOUSE_UPoGameState.startplay=trueogame.shutdown=true

ok}state = func ogame,oself {

oself {if x > -500x-=1y-=1width +=1height +=4

ok}

}}text {

animate = falsesize = 35file = "fonts/pirulen.ttf"text = "Super Man 2016"x = 20 y=30

}text {

animate = falsesize = 25file = "fonts/pirulen.ttf"text = "Version 1.0"x = 20 y=80

}text {

animate = falsesize = 16file = "fonts/pirulen.ttf"text = "(C) 2016, Mahmoud Fayed"x = 20 y=120

}

text {animate = falsesize = 25file = "fonts/pirulen.ttf"text = "Press Space to start"x = 190 y=470

}

45.29. Super Man 2016 Game 369