Sie sind auf Seite 1von 10

Ring Documentation, Release 1.5.

ok
ok

}
keypress = func ogame,oself,nKey {
if oGameState.gameresult = false
oself {
if nkey = key_space
y -= 55
oGameState.down = 60
if y<=0 y=0 ok
ok
}
ok
}
mouse = func ogame,oself,nType,aMouseList {
if nType = GE_MOUSE_UP
cFunc = oself.keypress
call cFunc(oGame,oSelf,Key_Space)
ok
}
}

text {
animate = false
point = 400
size = 30
file = "fonts/pirulen.ttf"
text = "Score : " + oGameState.score
x = 500 y=10
state = func oGame,oSelf {
oSelf { text = "Score : " + oGameState.score }
}
}

func newmap aMap


aV = [
[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 8
aMap[y][x] = aVar[y]
next
next

52.28. Flappy Bird 3000 Game 485


Ring Documentation, Release 1.5.4

func checkwin ogame


if oGameState.score = 3000
oGameState.gameresult = true
oGameState.playerwin = true
oGame {
text {
point = 400
size = 30
nStep = 3
file = "fonts/pirulen.ttf"
text = "You Win !!!"
x = 500 y=10
state = func ogame,oself {
if oself.y >= 400
ogame.shutdown = true
oGameState.value = 0
ok
}
}
}
ok

Class GameState
down = 3
gameresult = false
Score = 0
startplay=false
lastcol = 0
playerwin = false

Screen Shot:

52.28. Flappy Bird 3000 Game 486


Ring Documentation, Release 1.5.4

52.29 Super Man 2016 Game

The Super Man 2016 Game source code


# The Ring Standard Library
# Game Engine for 2D Games
# 2016, Mahmoud Fayed <msfclipper@yahoo.com>

oGameState = NULL

Load "gameengine.ring"

func main

oGame = New Game

while true

oGameState = new GameState

oGame {
title = "Super Man 2016"

52.29. Super Man 2016 Game 487


Ring Documentation, Release 1.5.4

sprite
{
file = "images/superman.jpg"
x = 0 y=0 width=800 height = 600 scaled = true animate = false
keypress = func ogame,oself,nKey {
if nkey = key_esc or nKey = GE_AC_BACK
ogame.shutdown()
but nKey = key_space
oGameState.startplay=true
ogame.shutdown=true
ok
}
mouse = func ogame,oself,nType,aMouseList {
if nType = GE_MOUSE_UP
oGameState.startplay=true
ogame.shutdown=true
ok
}
state = func ogame,oself {
oself {
if x > -500
x-=1
y-=1
width +=1
height +=4
ok
}
}
}
text {
animate = false
size = 35
file = "fonts/pirulen.ttf"
text = "Super Man 2016"
x = 20 y=30
}
text {
animate = false
size = 25
file = "fonts/pirulen.ttf"
text = "Version 1.0"
x = 20 y=80
}
text {
animate = false
size = 16
file = "fonts/pirulen.ttf"
text = "(C) 2016, Mahmoud Fayed"
x = 20 y=120
}

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

52.29. Super Man 2016 Game 488


Ring Documentation, Release 1.5.4

text {
animate = false
size = 20
file = "fonts/pirulen.ttf"
text = "Press Esc to Exit"
x = 260 y=510
}

animate {
file = "images/superman.png"
x = 200
y = 200
framewidth = 68
scaled = true
height = 86
width = 60
nStep = 10
transparent = true
animate = true
direction = ge_direction_random
state = func oGame,oSelf {
oSelf {
nStep--
if nStep = 0
nStep = 10
if frame < 1
frame++
else
frame=1
ok
ok
if x <= 0 x=0 ok
if y <= 0 y=0 ok
if x >= 750 x= 750 ok
if 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 = 60
FixedFPS = 15
Title = "Super Man 2016"

52.29. Super Man 2016 Game 489


Ring Documentation, Release 1.5.4

Sprite {
file = "images/supermancity.jpg"
x = 0 y=0 width=800 height = 600 scaled = true animate = false
}
Map {
blockwidth = 80
blockheight = 80
aMap = [
[0,0,0,4,4,4,0,0,0,1,0,0,0,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Images = ["images/smwall.png","images/smwallup.png",
"images/smwalldown.png","images/smstar.png",
"images/smkey.png","images/smstar2.png"]
}

sprite {
type = ge_type_enemy
animate = false
file = "images/smhome.png"
x = 5000
y = 400
width = 290
height = 200
transparent = true

state = func oGame,oSelf {


oself {
x = 5000 + oGame.aObjects[2].x
if x < 0 or x > SCREEN_W return ok
}
if oGameState.gameresult or oGameState.DoorKey = false return ok
if oGame.aObjects[oGameState.playerindex].x > oself.x + 100 and
oGame.aObjects[oGameState.playerindex].y > oself.y + 50
oGameState.gameresult = true
oGame {
sprite {
file = "images/smwin.jpg"
x=0 y=0 width=800 height=600
scaled = true animate=false
state = func ogame,oself {
oself {
x-=5
y-=5

52.29. Super Man 2016 Game 490


Ring Documentation, Release 1.5.4

width +=10
height +=10
if x = -300
ogame.shutdown = true
ok
}
}
}
}
ok
}

animate {
file = "images/superman.png"
x = 0
y = 0
framewidth = 60
scaled = true
height = 86
width = 60
nStep = 3
transparent = true
state = func oGame,oSelf {

checkstarskeycol(oGame,oSelf)

if not oGameState.playerwin
oself {
file = "images/superman.png"
height = 86
width = 60
for t=1 to 8
if checkwall2(oGame,oSelf,0,5,[2,1])
y += 5
else
exit
ok
next
if y > 500 y=500 ok
}
ok

}
keypress = func ogame,oself,nKey {
if oGameState.gameresult = false

oself {
if nkey = key_up and checkwall(oGame,oSelf,0,-40)
oGameState.value -= 1
checkgameover(oGame)
file = "images/supermanup.png"
height = 123
dotransparent()
y -= 40
oGameState.down = 10
if y<=0 y=0 ok

52.29. Super Man 2016 Game 491


Ring Documentation, Release 1.5.4

but nkey = key_down and checkwall(oGame,oSelf,0,40)


file = "images/supermandown.png"
dotransparent()
y += 40
if y>=500 y=500 ok
but nKey = key_right and checkwall(oGame,oSelf,10,0)
file = "images/supermanright.png"
dotransparent()
x += 10
if x >= 440
if oGame.aObjects[2].x > -4500
oGame.aObjects[2].x -= 50
callenemystate(oGame)
else
if x <= 750
if checkwall(oGame,oSelf,10,0)
x += 10
ok
else
if checkwall(oGame,oSelf,-10,0)
x -= 10
ok
ok
return
ok
x=400
ok
but nKey = key_left and checkwall(oGame,oSelf,-10,0)
file = "images/supermanleft.png"
dotransparent()
x -= 10
if x <= 0
x += 10
if oGame.aObjects[2].x != 0
oGame.aObjects[2].x += 50
callenemystate(oGame)
x += 50
ok
ok
but nkey = key_esc or nKey = GE_AC_BACK
ogame.shutdown()
ok
}
ok
}
mouse = func ogame,oself,nType,aMouseList {
if nType = GE_MOUSE_DOWN
oGameState.moveplayer = TRUE
But nType = GE_MOUSE_UP
oGameState.moveplayer = FALSE
ok
if oGameState.moveplayer = TRUE
if aMouseList[GE_MOUSE_X] < oSelf.X # left
cFunc = oself.keypress
call cFunc(oGame,oSelf,Key_left)
else
cFunc = oself.keypress
call cFunc(oGame,oSelf,Key_right)

52.29. Super Man 2016 Game 492


Ring Documentation, Release 1.5.4

ok
if aMouseList[GE_MOUSE_Y] < oSelf.Y # up
cFunc = oself.keypress
call cFunc(oGame,oSelf,Key_up)
else
cFunc = oself.keypress
call cFunc(oGame,oSelf,Key_down)
ok
ok
}
}

addenemy(oGame,600)
addenemy(oGame,900)
addenemy(oGame,1550)
addenemy(oGame,2350)
addenemy(oGame,3350)
addenemy(oGame,3500)
addenemy(oGame,3670)
addenemy(oGame,3840)

text {
animate = false
point = 400
size = 30
file = "fonts/pirulen.ttf"
text = "Score : " + oGameState.score
x = 500 y=0
state = func oGame,oSelf {
oSelf { text = "Score : " + oGameState.score }
}
}

text {
animate = false
point = 400
size = 30
file = "fonts/pirulen.ttf"
text = "Energy : " + oGameState.value
x = 10 y=0
state = func oGame,oSelf { oSelf { text = "Energy : " + oGameState.value } }
}
}

func inlist nValue,aList


for x in aList
if x = nValue
return true
ok
next
return false

func checkwall oGame,oself,diffx,diffy


alist = [1,2,3]
return checkwall2(oGame,oself,diffx,diffy,aList)

func checkwall2 oGame,oself,diffx,diffy,aList

52.29. Super Man 2016 Game 493


Ring Documentation, Release 1.5.4

xPos = oSelf.x + diffx


yPos = oSelf.y + diffy
nValue = oGame.aObjects[2].getvalue(xPos,yPos)
nValue = inlist(nValue,aList)
nValue = not nValue
if nValue = 0 return nValue ok

xPos = oSelf.x + diffx


yPos = oSelf.y + diffy + oSelf.height
nValue = oGame.aObjects[2].getvalue(xPos,yPos)
nValue = inlist(nValue,aList)
nValue = not nValue
if nValue = 0 return nValue ok

xPos = oSelf.x + diffx + oSelf.width


yPos = oSelf.y + diffy
nValue = oGame.aObjects[2].getvalue(xPos,yPos)
nValue = inlist(nValue,aList)
nValue = not nValue
if nValue = 0 return nValue ok

xPos = oSelf.x + diffx + oSelf.width


yPos = oSelf.y + diffy + oSelf.height
nValue = oGame.aObjects[2].getvalue(xPos,yPos)
nValue = inlist(nValue,aList)
nValue = not nValue
if nValue = 0 return nValue ok

return nValue

func checkopenwall oGame


if oGameState.score = 900
oGame.aObjects[2].aMap[3][10] = 3
oGame.aObjects[2].aMap[4][10] = 0
oGame.aObjects[2].aMap[5][10] = 0
oGame.aObjects[2].aMap[6][10] = 0
oGame.aObjects[2].aMap[7][10] = 0
oGame.aObjects[2].aMap[8][10] = 0
but oGameState.score = 1800
oGame.aObjects[2].aMap[3][18] = 3
oGame.aObjects[2].aMap[4][18] = 0
oGame.aObjects[2].aMap[5][18] = 0
oGame.aObjects[2].aMap[6][18] = 0
oGame.aObjects[2].aMap[7][18] = 0
oGame.aObjects[2].aMap[8][18] = 0
but oGameState.score = 5500
oGame.aObjects[2].aMap[1][44] = 0
oGame.aObjects[2].aMap[2][44] = 0
oGame.aObjects[2].aMap[3][44] = 2
ok

func checkgameover ogame


if oGameState.gameresult return ok
if oGameState.value <= 0
oGameState.value = 0
oGameState.gameresult = true
oGame {

52.29. Super Man 2016 Game 494

Das könnte Ihnen auch gefallen