this will build a type that u can use to control your level then build buttons then create a temp type as the same kind as the first, populate the temp with random variables
type then insert it into the real type. We then check for a button press and create the corresponding level.
if you are new to programming this will look confusing. think of a type as a phisical object like a shoe. A shoe has physical properties like width height color lace length and a position in real space x,y,z.
but you cant just type in shoe and the program know what u want. you must define this phisical object. then tell it what properties it has like color.
once you have an object u can acess its properties which will all be set to -1 because u did not define them.
so to set the properties of an object u must access the object shoe and its properties shoe.color
but what if we want a bunch of shoes? well we dont have to recreate the type/object because we already built it to we make an array type shoe as [] an array.
but we dont want a bunch of shoes that are built without width or height or color
so we build a temporary type temp as shoe . this says make a type that is the same as shoe but not an array or shoes. we can then fill in temp with all the property data we want the insert it into the shoe array.
in this case we make temp as level and fill it out. we then insert it into the type.
function are usefull as well they allow u to run code just like normal code but from anywhere. It also allows u to pass it data and then do something with that data.
function printnumber(mynumber)
print(mynumber)
endfunction
if you type printnumber(45) calls the printnumber function and passes it 45 it then mynumber is now equal to 45 inside the function so anycode in the function now treats it as a normal integer value of 45 in the code
functions, arrays and types are your friend. Learn them love them do not avoid them. persue them at all costs. When your skills get better you will find that u dont use agk command anymore but instead your own functions almost exclusively
Global Level as levelType []
type levelType
x as float
y as float
Startx as float
starty as float
speed as integer
CharSpriteID as integer
EndType
width=GetDeviceWidth()
height=GetDeviceHeight()
BtnSize=100
x=(width/2)-(btnSize/2)
y=(height/2)-(btnSize/2)
for i = 1 to 4
AddVirtualButton(i,x,y+(i*btnSize),btnSize)
SetVirtualButtonText(i,"level "+str(i))
next
for i = 0 to 4
ranCol=makecolor(random(1,255),Random(1,255),Random(1,255))
temp as leveltype
drawbox(0,0,30,30,ranCol,ranCol,ranCol,ranCol,1)
tImage=getimage(0,0,30,30)
temp.startx=random(1,400)
temp.starty=random(1,400)
temp.speed=random(1,10)
temp.CharSpriteID=createsprite(tImage)
level.insert(temp)
next
function SetupLevel(ID)
SetSpritePosition(level[id].CharSpriteID,level[id].startx,level[id].starty)
CurrentLevel=id
endfunction
global CurrentLevel=-1
do
print(currentlevel)
for i = 1 to 4
if GetvirtualButtonPressed(i)=1
setuplevel(i)
endif
next
if CurrentLevel >-1
Sprid=level[currentlevel].CharSpriteID
x=getspritex(SprID)
y=getspritey(SprID)
speed=level[CurrentLevel].speed
SetSpritePosition(SprID,x+speed,y)
endif
sync()
loop