## a roguelike game converted from cpp to FB

Game development specific discussions.
dodicat
Posts: 6914
Joined: Jan 10, 2006 20:30
Location: Scotland

### Re: a roguelike game converted from cpp to FB

You could do an arrayinsert and arraydelete to add or annihilate monsters.

Code: Select all

`#macro arrayinsert(a,index,insert)    If index>=Lbound(a) And index<=Ubound(a)+1 Then        Var index2=index-Lbound(a)        Redim Preserve a(Lbound(a) To  Ubound(a)+1)        For x As long= Ubound(a) To Lbound(a)+index2+1 Step -1            Swap a(x),a(x-1)        Next x        a(Lbound(a)+index2)=insert    End If#endmacro#macro arraydelete(a,index)    If index>=Lbound(a) And index<=Ubound(a) Then        For x As long=index To Ubound(a)-1            a(x)=a(x+1)        Next x        Redim Preserve a(Lbound(a) To Ubound(a)-1)    End If#endmacrotype monster    as long headsize    as long taillength    as long bodythickness    as string name    as long teethsize(1 to 20)    as single averagetoothsize    declare constructor    declare sub show    static index as longend typedim monster.index as longconstructor monsterindex+=1headsize=rnd*50taillength=headsize+rnd*50bodythickness=3*headsizename="Monster "+str(index)dim as single afor n as long=1 to 20    teethsize(n)=rnd*headsize/10    a+=teethsize(n)next naveragetoothsize=a/20end constructorsub monster.show    print "Headsize","taillength","bodythickness","name","average tooth size"    print headsize,taillength,bodythickness,name,averagetoothsizeend subredim as monster m(1 to 3)for n as long=1 to 3    m(n).shownextprint:printdim as monster tempmonster.index-=1arrayinsert(m,ubound(m)+1,temp)print "push one at back"for n as long=lbound(m) to ubound(m)    m(n).shownextprint:printprint "pop one at index 3"arraydelete(m,3)for n as long=lbound(m) to ubound(m)    m(n).shownextprint:printtemp.constructormonster.index-=1print "push new one at index 2"arrayinsert(m,2,temp)for n as long=lbound(m) to ubound(m)    m(n).shownextprint:printsleep `
ron77
Posts: 194
Joined: Feb 21, 2019 19:24
Location: Israel
Contact:

### Re: a roguelike game converted from cpp to FB

hello dudicat...

nice... you gave the macro for arrayinsert... however what i need is actually to delete/remove from the array... :-/ i'm trying to figure out how to modify the macro but don't seem to understand how... you wouldn't have the arraydelete/arrayremove macro code hidden somewhere by chance?
dodicat
Posts: 6914
Joined: Jan 10, 2006 20:30
Location: Scotland

Hi ron77