here is a level file i used in a game.
its just for look how i handle the level.
//Level Load/Save/Default/Start
//-------------------------------------- Level
type TLevel
sndWay as integer //mal verschieben in anders Type
sndApplause as integer
sndBande as integer
sndRoll as integer
sndStart as integer
sndLost as integer
imgball as integer
imgway as integer
imgbgandway as integer
imgwaypoint as integer
imghole as integer
imgwall as integer
imgblock as integer
imgpin as integer
imgstartpoint as integer
imgstart as integer
imggoalpoint as integer
imggoal as integer
imglost as integer
imgparticle as integer
idparticle as integer
idparticleway as integer
sprbg as integer
sprway as integer
sprbgandway as integer
colorbg as integer
colorway as integer
colorball as integer
color as integer
style as integer
collibande as integer
lost as integer
ohoh as integer
atgoal as integer
waypointsactivated as integer
Ball as TBall
Start as TStart
Goal as TGoal
holes as integer
waypoints as integer
blocks as integer
pins as integer
walls as integer
cancel as integer
time#
endtype
function LevelFree()
LevelFreeSound()
sync()
LevelFreeImages()
LevelFreeSprites()
endfunction
function LevelFreeSprites()
//Alle Sprites entfernen
if Level.sprbg then deletesprite(Level.sprbg)
Level.sprbg=0
if Level.sprway then deletesprite(Level.sprway)
Level.sprway=0
if Level.sprbgandway then deletesprite(Level.sprbgandway)
Level.sprbgandway=0
if Level.Ball.spr then deletesprite(Level.Ball.spr)
Level.Ball.spr=0
if Level.Start.spr then deletesprite(Level.Start.spr)
Level.Start.spr=0
if Level.Goal.spr then deletesprite(Level.Goal.spr)
Level.Goal.spr=0
for i=1 to Level.holes
if Level_Hole[i].spr then deletesprite(Level_Hole[i].spr)
Level_Hole[i].spr=0
next
Level.holes=0
for i=1 to Level.waypoints
if Level_WayPoint[i].spr then deletesprite(Level_WayPoint[i].spr)
Level_WayPoint[i].spr=0
next
Level.waypoints=0
for i=1 to Level.blocks
if Level_Block[i].spr then deletesprite(Level_Block[i].spr)
Level_Block[i].spr=0
next
Level.blocks=0
for i=1 to Level.pins
if Level_Pin[i].spr then deletesprite(Level_Pin[i].spr)
Level_Pin[i].spr=0
next
Level.pins=0
for i=1 to Level.walls
if Level_Wall[i].spr then deletesprite(Level_Wall[i].spr)
Level_Wall[i].spr=0
next
Level.walls=0
endfunction
function LevelLoadSound()
//-------------------------------------- Sounds 44,1 kHz 16 Bit Mono .Wav
Level.sndWay=Loadsound(\"sound\\way.wav\")
Level.sndApplause=Loadsound(\"sound\\applause.wav\")
Level.sndBande=Loadsound(\"sound\\bande.wav\")
Level.sndLost=Loadsound(\"sound\\fail.wav\")
Level.sndRoll=Loadsound(\"sound\\roll.wav\")
Level.sndStart=Loadsound(\"sound\\start.wav\")
endfunction
function LevelFreeSound()
deletesound(Level.sndWay)
deletesound(Level.sndApplause)
deletesound(Level.sndBande)
deletesound(Level.sndLost)
deletesound(Level.sndRoll)
deletesound(Level.sndStart)
endfunction
function LevelLoadImages()
//-------------------------------------- Particle
Level.imgparticle=LoadImage (\"particle.png\" )
//-------------------------------------- Holes
Level.imghole=loadimage(\"myhole.png\")
//-------------------------------------- Hindernisse Block
Level.imgblock=LoadImage(\"blockgrey.png\")
//-------------------------------------- Hindernisse Pin
Level.imgpin=LoadImage(\"pingrey.png\")
//-------------------------------------- Hindernisse Wand / Rand
Level.imgwall=LoadImage(\"pipe.png\")
//-------------------------------------- Start
Level.imgstartpoint=LoadImage(\"startpoint.png\")
Level.imgstart=LoadImage(\"start.png\")
//-------------------------------------- Goal
Level.imggoalpoint=LoadImage(\"goalpoint.png\")
Level.imggoal=LoadImage(\"goal.png\")
//-------------------------------------- Way
Level.imgwaypoint=LoadImage(\"waypoint.png\")
//-------------------------------------- Ball
Level.imgball=loadimage(\"metalball.png\")
//-------------------------------------- Lost
Level.imglost=loadimage(\"lost.png\")
endfunction
function LevelFreeImages()
deleteimage(Level.imgparticle)
DeleteImage(Level.imghole)
DeleteImage(Level.imgblock)
DeleteImage(Level.imgpin)
DeleteImage(Level.imgwall)
DeleteImage(Level.imgstartpoint)
DeleteImage(Level.imgstart)
DeleteImage(Level.imggoalpoint)
DeleteImage(Level.imggoal)
DeleteImage(Level.imgwaypoint)
DeleteImage(Level.imgball)
DeleteImage(Level.imglost)
if Level.imgway then deleteimage(Level.imgway)
Level.imgway=0
if Level.imgbgandway then deleteimage(Level.imgbgandway)
Level.imgbgandway=0
endfunction
function LevelSave(filename$)
file = OpenToWrite(filename$,0)
Writeline(file,\"Level Ball Labyrinth 1.0\")
WriteInteger ( file, Level.color )
WriteInteger ( file, Level.style )
//Hole x,y
WriteInteger ( file, Level.holes )
for i=1 to Level.holes
WriteSprite(file,Level_Hole[i].spr)
next
//Start x,y
WriteSprite(file,Level.Start.spr)
//Ende x,y
WriteSprite(file,Level.Goal.spr)
//Block x,y,a
WriteInteger ( file, Level.blocks )
for i=1 to Level.blocks
WriteSprite(file,Level_Block[i].spr)
next
//Pin x,y,a
WriteInteger ( file, Level.pins )
for i=1 to Level.pins
WriteSprite(file,Level_Pin[i].spr)
next
//Wall x,y,a
WriteInteger ( file, Level.walls )
for i=1 to Level.walls
WriteSprite(file,Level_Wall[i].spr)
next
//Way x,y,a
WriteInteger ( file, Level.waypoints )
for i=1 to Level.waypoints
WriteSprite(file,Level_WayPoint[i].spr)
next
//Hintergrund/Weg/Ball Farbe
writeinteger( file, Level.colorbg )
writeinteger( file, Level.colorway )
writeinteger( file, Level.colorball )
CloseFile ( file )
endfunction
function WriteSprite(file,spr)
//Eigentlich noch mehr wie Size/Offset/Shape/Category Bit/Depth/Snap
//Physic Daten ... Physic OnOff/Sensor//Is Bullet/Mass/Friction/Damping/Restitution/CanRotate/AngularDamping
WriteFloat(file,getspritexbyoffset(spr))
WriteFloat(file,getspriteybyoffset(spr))
WriteFloat(file,getspriteangle(spr))
WriteColor(file,spr)
endfunction
function ReadSprite(file,spr)
//siehe WriteSprite & Level Lade Funktion
x#=readfloat(file)
y#=readfloat(file)
a#=readfloat(file)
SetSpritePositionbyoffset ( spr, x#, y# )
setspriteangle(spr,a#)
ReadColor(file,spr)
endfunction
function WriteColor(file,spr)
r=getspritecolorred(spr)
g=getspritecolorgreen(spr)
b=getspritecolorblue(spr)
a=getspritecoloralpha(spr)
writebyte(file,r) //0-255
writebyte(file,g)
writebyte(file,b)
writebyte(file,a)
endfunction
function ReadColor(file,spr)
r=readbyte(file) //0-255
g=readbyte(file)
b=readbyte(file)
a=readbyte(file)
setspritecolor(spr,r,g,b,a)
endfunction
Function LevelLoad(filename$)
//message(\"Load\")
ret=0
if GetFileExists( filename$ ) =0
message(\"file \"+filename$+\" not found\")
exitfunction ret
endif
//-----------------------------------------
LevelLoadSound()
sync()
LevelLoadImages()
sync()
file = OpenToRead(filename$)
r$=Readline(file) //Info
//message(r$)
Level.color=readInteger( file )
Level.style=readInteger( file )
//Hole x,y
count=readInteger(file)
Level.holes=0
for i=1 to count
MakeHole(0,0,Level.imghole)
ReadSprite(file,Level_Hole[i].spr)
next
sync()
//Start x,y
MakeStart(0,0,Level.imgstartpoint)
ReadSprite(file,Level.Start.spr)
//Ende x,y
MakeGoal(0,0,Level.imggoalpoint)
ReadSprite(file,Level.Goal.spr)
sync()
//Block x,y,a
count=readInteger(file)
Level.blocks=0
for i=1 to count
MakeBlock(0,0,0,Level.imgblock)
ReadSprite(file,Level_Block[i].spr)
next
sync()
//Pin x,y,a
count=readInteger(file)
Level.pins=0
for i=1 to count
MakePin(0,0,0,Level.imgpin)
ReadSprite(file,Level_Pin[i].spr)
next
sync()
//Wall x,y,a
count=readInteger(file)
Level.walls=0
for i=1 to count
MakeWall(0,0,0,Level.imgwall)
ReadSprite(file,Level_Wall[i].spr)
next
sync()
//Waypoint x,y,a
count=readInteger(file)
Level.waypoints=0
for i=1 to count
MakeWayPoint(0,0,0,Level.imgwaypoint)
ReadSprite(file,Level_WayPoint[i].spr)
a#=i*22.5
setspriteangle(Level_WayPoint[i].spr,a#)
next
sync()
Level.colorbg =readinteger(file)
Level.colorway =readinteger(file)
Level.colorball=readinteger(file)
//Level.colorbg =GetColorRGBA(192,128,64,255)
//Level.colorway =GetColorRGBA(0,0,0,255) //24)
//Level.colorball=GetColorRGBA(255,255,255,255)
CloseFile ( file )
MakeBackgroundAndWaySprite() //erzeugt Hintergrund Bild und malt den Weg
sync()
MakeBall(Level.imgball)
sync()
ret=1
endfunction ret
function LevelDefault()
//Erzeugt einen Standart Level
LevelLoadSound()
LevelLoadImages()
Level.color=0
Level.style=0
Level.colorbg=GetColorRGBA(192,128,64,255)
Level.colorway=GetColorRGBA(0,0,0,255)
Level.colorball=GetColorRGBA(255,255,255,255)
MakeHoles(Level.imghole)
//MakeBlock(50+6.25, 50+6.25,45,Level.imgblock)
//MakePin(50+6.25, 50-6.25,45,Level.imgpin)
//MakeWayPoint(25+6.25, 25-6.25,45,Level.imgway)
MakeWall( 50.0 , 0.0 , 0.0 , Level.imgwall) //Oben
MakeWall( 50.0 , 100.0 , 0.0 , Level.imgwall) //Unten
MakeWall( 0.0 , 50.0 , 90.0 , Level.imgwall) //Links
MakeWall(100.0 , 50.0 , 90.0 , Level.imgwall) //Rechts
MakeStart(25,100.0-12.5,Level.imgstartpoint)
MakeGoal(50+25+12.5,50-12.5*2.0,Level.imggoalpoint)
MakeBackgroundAndWaySprite()
MakeBall(Level.imgball)
endfunction
function LevelEmpty()
//Erzeugt einen Standart Level
LevelLoadSound()
LevelLoadImages()
Level.color=0
Level.style=0
Level.colorbg =GetColorRGBA(192,128,64,255)
Level.colorway =GetColorRGBA(0,0,0,255)
Level.colorball=GetColorRGBA(255,255,255,255)
MakeWall( 50.0 , 0.0 , 0.0 , Level.imgwall) //Oben
MakeWall( 50.0 , 100.0 , 0.0 , Level.imgwall) //Unten
MakeWall( 0.0 , 50.0 , 90.0 , Level.imgwall) //Links
MakeWall(100.0 , 50.0 , 90.0 , Level.imgwall) //Rechts
MakeBackgroundAndWaySprite()
MakeBall(Level.imgball)
endfunction
function LevelStart()
//Alles auf Anfang
Game.pause=0
Level.collibande=0
Level.atgoal=0
Level.lost=0
Level.ohoh=0
Level.cancel=0
Level.time#=0.0
Player.score=0
//Pause(0)
StartBall()
playsound(Level.sndStart,50.0)
//Wegpunkte resetten
Level.waypointsactivated=0
for i = 1 to Level.waypoints
WayPointActivated(i,0)
Level_WayPoint[i].count=0
WayPointColor(i)
next
LevelWayParticleEmitter()
endfunction
function LevelNrDelay(font)
//blinkende Level Nummer
ti=createtext(LevelText()) // \"LEVEL=\"+str(game.level))
settextfontimage(ti,font)
SetTextExtendedFontImage(ti,font)
SetTextAlignment(ti,1)
settextsize(ti,8)
settextposition(ti,50,50)
settextdepth(ti,0)
settextspacing(ti,-1)
t#=timer()
t1#=timer()
b=1
w#=0.0
setviewzoom(1.0)
do
if timer()-t#<1.0 then setviewzoom(getviewzoom()+0.005)
if timer()-t#=>1.0 then setviewzoom(getviewzoom()-0.005)
settextcoloralpha(ti,sin(w#)*255.0)
w#=w#+180.0/60.0
if w#>360.0 then w#=w#-360.0
if timer()-t1#>0.25
b=1-b
//settextvisible(ti,b)
t1#=timer()
endif
if timer()-t#>2.0 then exit
sync()
loop
deletetext(ti)
setviewzoom(1.0)
endfunction
function LevelLost()
//this function will called if the ball is to long at hole
Level.lost=1
x#=getspritexbyoffset(Level.Ball.spr)
y#=getspriteybyoffset(Level.Ball.spr)
Level.idparticle=CreateParticles ( x#,y# )
SetParticlesFrequency ( Level.idparticle, 30 )
SetParticlesLife ( Level.idparticle, 3 )
SetParticlesSize ( Level.idparticle, 4 )
SetParticlesStartZone ( Level.idparticle, -0.25, -0.25, 0.25, 0.25 )
SetParticlesImage ( Level.idparticle, Level.imgparticle )
SetParticlesDirection ( Level.idparticle, 1, 0 )
//SetParticlesAngle ( Level.idparticle, 360 )
SetParticlesAngle ( Level.idparticle, 90 )
SetParticlesMax(Level.idparticle,60)
setParticlesdepth(Level.idparticle,3)
AddParticlesColorKeyFrame ( Level.idparticle, 0.0, 0, 0, 0, 0 )
AddParticlesColorKeyFrame ( Level.idparticle, 1.0, 255 , 0, 0, 192 )
AddParticlesColorKeyFrame ( Level.idparticle, 3.0, 0,0,0, 0 )
endfunction
function LevelWayParticleEmitter()
x#=0.0
y#=0.0
Level.idparticleway=CreateParticles ( x#,y# )
SetParticlesFrequency ( Level.idparticleway, 0 )
SetParticlesLife ( Level.idparticleway, 3 )
SetParticlesSize ( Level.idparticleway, 4 )
SetParticlesStartZone ( Level.idparticleway, -2.5,-2.5,2.5,2.5 )
SetParticlesImage ( Level.idparticleway, Level.imgparticle )
SetParticlesDirection ( Level.idparticleway, 0, 0 )
SetParticlesAngle ( Level.idparticleway, 360 )
//SetParticlesAngle ( Level.idparticleway, 45 )
//SetParticlesMax(Level.idparticleway,60)
setParticlesdepth(Level.idparticleway,3)
AddParticlesColorKeyFrame ( Level.idparticleway, 0.0 ,255, 128, 64, 64 )
AddParticlesColorKeyFrame ( Level.idparticleway, 1.0 ,128, 255, 0, 192 )
AddParticlesColorKeyFrame ( Level.idparticleway, 2.0 , 0, 255, 0, 128 )
AddParticlesColorKeyFrame ( Level.idparticleway, 3.0 , 0, 0, 0, 0 )
endfunction
function WayParticleBoom(spr)
if Level.idparticleway=0 then exitfunction
x#=getspritexbyoffset(spr)
y#=getspriteybyoffset(spr)
//der ball ändert ja seine richtung...
dx#=1 // -getspritephysicsvelocityx(Level.Ball.spr)/4.0
dy#=0 //-getspritephysicsvelocityy(Level.Ball.spr)/4.0
SetParticlesPosition (Level.idparticleway, x#, y#)
SetParticlesDirection(Level.idparticleway,dx#,dy#)
SetParticlesFrequency ( Level.idparticleway, 5 )
endfunction
function WayParticle0()
if Level.idparticleway=0 then exitfunction
SetParticlesFrequency ( Level.idparticleway, 0 )
endfunction
function LevelUpdate()
if Level.idparticleway
endif
if Level.idparticle
x#=getspritexbyoffset(Level.Ball.spr)
y#=getspriteybyoffset(Level.Ball.spr)
w#=random(0,360)
dx#=sin(w#)
dy#=cos(w#)
SetParticlesPosition (Level.idparticle, x#+dx#*2.5, y#+dy#*2.5 )
SetParticlesDirection(Level.idparticle,dx#,dy#)
endif
endfunction
function LevelStop()
if Level.idparticleway
deleteparticles(Level.idparticleway)
Level.idparticleway=0
endif
if Level.idparticle
deleteparticles(Level.idparticle)
Level.idparticle=0
endif
endfunction
function LevelText()
//für Hauptmenü Level wechsel
a$=\"LEVEL = \"
if Game.level=0
a$=a$+\"Training\"
else
a$=a$+str(Game.level)
endif
endfunction a$
AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)