Here's a simple text tile world:
AppTitle "Text Tile World"
Graphics 800,600,32,2
;--------------------------------
; INITIALIZATION
;--------------------------------
Global px=115,py=0,hp=100
Global frametimer=CreateTimer(15)
Global starttime=MilliSecs(),elapsedtime,fpscounter,curfps
Global levelimg=CreateImage(600,400,1)
Dim map$(40,20)
Dim des$(5)
Type enemy
Field startx,starty,x,y,u,d,l,r,dir
End Type
;--------------------------------
; MAIN LOOP
;--------------------------------
updatelevel()
While Not KeyHit(1)
WaitTimer(frametimer)
Text 620,20,FPS()
Color 0,100,0
displaylevel()
updateplayer()
Flip
Cls
Wend
;--------------------------------
; FUNCTIONS
;--------------------------------
Function FPS()
elapsedtime=MilliSecs()-starttime
If elapsedtime>=1000
curfps=fpscounter
fpscounter=0
starttime=MilliSecs()
Else
fpscounter=fpscounter+1
EndIf
Return curfps
End Function
Function updateplayer()
;displays player and updates movement/checks ground
Text px,py,"O",True,True
opx=px
opy=py
If KeyDown(205)
If px+10<16*40
px=px+10
Else
px=16*40
EndIf
EndIf
If KeyDown(203)
If px-10>0
px=px-10
Else
px=0
EndIf
EndIf
If KeyDown(208)
If py+10<16*20
py=py+10
Else
py=16*20
EndIf
EndIf
If KeyDown(200)
If py-10>0
py=py-10
Else
py=0
EndIf
EndIf
mx=px Shr 4
my=py Shr 4
on$=map$(mx,my)
If on$="#"
px=opx
py=opy
EndIf
If on$="_"
hp=0
EndIf
If on$="^"
hp=hp-1
EndIf
Text 0,450,map$(mx,my)
End Function
Function displaylevel()
;displays the level and other crucial information
DrawImage levelimg,0,0
For x=0 To 4
Text 0,420+x*20,des$(x)
Next
Text 610,0,"HP: "+hp
updateenemy()
End Function
Function updatelevel()
;on level change, updates/resets all aspects of level
For m.enemy=Each enemy
Delete m
Next
Restore leveldata
For x=0 To 4
Read d$
des$(x)=d$
Next
For y=0 To 19
For x=0 To 39
Read num
If num=1
map$(x,y)="#" ;wall
ElseIf num=0
map$(x,y)=" " ;floor
ElseIf num=2
map$(x,y)="_" ;hole
ElseIf num=3
map$(x,y)="^" ;spikes
EndIf
Next
Next
Read ennum
For z=1 To ennum
Read x
Read y
Read u
Read d
Read l
Read r
makenemy(x,y,u,d,l,r)
Next
SetBuffer ImageBuffer(levelimg)
Color 0,100,0
For y=0 To 19
For x=0 To 39
Text x*16,y*16,map$(x,y)
Next
Next
SetBuffer BackBuffer()
End Function
Function makenemy(x,y,u,d,l,r)
;creates a new enemy instance from data strip
m.enemy=New enemy
m\startx=x
m\starty=y
m\x=x
m\y=y
m\u=u
m\d=d
m\l=l
m\r=r
m\dir=1
End Function
Function updateenemy()
;controls enemy movement and display
For m.enemy=Each enemy
If m\dir>3
m\dir=0
EndIf
Select m\dir
Case 1
nextstep=m\x+10
on$=map$(nextstep Shr 4,m\y Shr 4)
If on$="#" Or nextstep>m\startx+m\r
m\dir=m\dir+1
Else
m\x=nextstep
EndIf
Case 2
nextstep=m\y+10
on$=map$(m\x Shr 4,nextstep Shr 4)
If on$="#" Or nextstep>m\starty+m\d
m\dir=m\dir+1
Else
m\y=nextstep
EndIf
Case 3
nextstep=m\x-10
on$=map$(nextstep Shr 4,m\y Shr 4)
If on$="#" Or nextstep<m\startx-m\l
m\dir=m\dir+1
Else
m\x=nextstep
EndIf
Case 0
nextstep=m\y-10
on$=map$(m\x Shr 4,nextstep Shr 4)
If on$="#" Or nextstep<m\starty-m\u
m\dir=m\dir+1
Else
m\y=nextstep
EndIf
End Select
Text m\x,m\y,"?"
Next
End Function
;-----------------------------------------------------
; DATA
;-----------------------------------------------------
.leveldata ;5 lines of text, 40x20 num block, enemy line
Data "YOU BEGIN YOUR JOURNEY IN THE DARK DUNGEON, THERE ARE TWO EXITS. IT IS"
Data "QUIET AND DANK. THERE IS A HOLE IN THE FLOOR, AND IT IS VERY DEEP..."
Data "f"
Data "e"
Data "g"
Data 0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,1,1,1,1,1,1,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
Data 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,0,0,0,0,0,0,0,0,0,0,0,1,0
Data 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,0,0,0,0,0,0,0,0,0,0,0,1,0
Data 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,0,0,0,0,0,0,0,0,0,0,0,1,0
Data 0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
Data 1 ;num enemys
Data 200,200,50,50,0,0 ; enemy attributes (x,y,u,d,l,r)
I only get 15 FPS. What optimization techniques should I use to improve it? I already used binary shifts instead of division, but it didn't help much.