take a look at this code,it uses the loading and saving of types, if you wish to use it then use the attached media folder for the gfx...
// Project: genesis67
// Created: 2015-10-22
// set window properties
SetWindowTitle( "genesis67" )
SetWindowSize( 800, 600, 1 )
// set display properties
SetVirtualResolution( 800, 600 )
SetOrientationAllowed( 1, 1, 1, 1 )
#include "keys.agc"
#constant maxsprites=5000
type TMouse
x1#
y1#
x2#
y2#
x3
y3
endtype
type mysprites
xp# as float
yp# as float
sizex# as float
sizey# as float
scalex as integer
scaley as integer
restitution# as float
friction# as float
spritenumber as integer
imagenumber as integer
transparency as integer
visibility as integer
groupnumber as integer
physicstype as integer
shape as integer
angle as integer
depth as integer
host as integer
client as integer
tilevalue as integer
canrotate as integer
red as integer
green as integer
blue as integer
selected as integer
framestart as integer
frameamount as integer
frameend as integer
loopframe as integer
texturerep as integer
alpha as integer
endtype
Global level = 1
Global texturerep = 1
Global Quit = 0
Global CursorX# = 0.0
Global CursorY# = 0.0
Global CursorSprite = 6000
Global CurrentImage = 1
Global SpriteNumber = 0
global Sizex# = 32
global Sizey# = 32
global scalex = 1
global scaley = 1
global canrotate = 0
global red = 255
global green = 255
global blue = 255
global tilevalue = 0
global depth = 50
global friction# = 0
global restitution# = 0
global gridx = 8
global gridy = 8
global angle = 0
global visibility = 0
global groupnumber = 0
global transparency = 0
global shape = 2
global physicstype = 1
global alpha = 255
global hide=0
global Mouse as TMouse
dim mysprite[maxsprites] as mysprites
dim deleted[maxsprites]
load_images()
init()
Repeat
control()
r=GetVirtualButtonPressed(2)
if r>0 or getrawkeyreleased(KEY_Q)
Quit=1
endif
FillMouse(gridx,gridy)
setspritepositionbyoffset(CursorSprite,Mouse.x3,Mouse.y3)
Sync()
Until Quit=1
function init()
AddVirtualJoystick(1,30,470,64)
createmyeditbox(1,120,10,1,255,0,0,0,30,12,255,"1") // Game Type
createmyeditbox(2,120,30,1,255,0,0,0,30,12,255,"1")
createmyeditbox(3,120,50,1,255,0,0,0,30,12,255,"8")
createmyeditbox(4,120,70,1,255,0,0,0,30,12,255,"8")
createmyeditbox(5,120,90,1,255,0,0,0,30,12,255,"1")
createmyeditbox(6,120,110,1,255,0,0,0,30,12,255,"1")
createmyeditbox(7,120,130,1,255,0,0,0,30,12,255,"0")
createmyeditbox(8,120,150,1,255,0,0,0,30,12,255,"1")
//
createmytext(1,1,10,12,255,0,0,"Game Type --- ",0)
createmytext(2,1,30,12,255,0,0,"Image Rep --- ",0)
createmytext(3,1,50,12,255,0,0,"Grid X# --- ",0)
createmytext(4,1,70,12,255,0,0,"Grid Y# --- ",0)
createmytext(5,1,90,12,255,0,0,"Scale X --- ",0)
createmytext(6,1,110,12,255,0,0,"Scale Y --- ",0)
createmytext(7,1,130,12,255,0,0,"Angle --- ",0)
createmytext(8,1,150,12,255,0,0,"Image --- ",0)
//
createmyeditbox(9,250,10,1,255,0,0,0,30,12,255,"0") // Game Type
createmyeditbox(10,250,30,1,255,0,0,0,30,12,255,"255")
createmyeditbox(11,250,50,1,255,0,0,0,30,12,255,"255")
createmyeditbox(12,250,70,1,255,0,0,0,30,12,255,"255")
createmyeditbox(13,250,90,1,255,0,0,0,30,12,255,"32")
createmyeditbox(14,250,110,1,255,0,0,0,30,12,255,"32")
createmyeditbox(15,250,130,1,255,0,0,0,30,12,255,str(level))
createmyeditbox(16,250,150,1,255,0,0,0,30,12,255,"1")
createmytext(9,160,10,12,255,0,0,"Group --- ",0)
createmytext(10,160,30,12,255,0,0,"Red --- ",0)
createmytext(11,160,50,12,255,0,0,"Green --- ",0)
createmytext(12,160,70,12,255,0,0,"Blue --- ",0)
createmytext(13,160,90,12,255,0,0,"Size X --- ",0)
createmytext(14,160,110,12,255,0,0,"Size Y --- ",0)
createmytext(15,160,130,12,255,0,0,"Level --- ",0)
//
createmyeditbox(17,380,10,1,255,0,0,0,30,12,255,"0")
createmyeditbox(18,380,30,1,255,0,0,0,30,12,255,"2")
createmyeditbox(19,380,50,1,255,0,0,0,30,12,255,"1")
createmyeditbox(20,380,70,1,255,0,0,0,30,12,255,"1")
createmyeditbox(21,380,90,1,255,0,0,0,30,12,255,str(depth))
createmyeditbox(22,380,110,1,255,0,0,0,30,12,255,"1")
createmyeditbox(23,380,130,1,255,0,0,0,30,12,255,"1")
createmyeditbox(24,380,150,1,255,0,0,0,30,12,255,"1")
createmytext(17,295,10,12,255,0,0,"Transp --- ",0)
createmytext(18,295,30,12,255,0,0,"Shape --- ",0)
createmytext(19,295,50,12,255,0,0,"Phyics --- ",0)
createmytext(20,295,70,12,255,0,0,"Type --- ",0)
createmytext(21,295,90,12,255,0,0,"Depth --- ",0)
//
createmyeditbox(25,520,10,1,255,0,0,0,30,12,255,"1")
createmyeditbox(26,520,30,1,255,0,0,0,30,12,255,"1")
createmyeditbox(27,520,50,1,255,0,0,0,30,12,255,"1")
createmyeditbox(28,520,70,1,255,0,0,0,30,12,255,"1")
createmyeditbox(29,520,90,1,255,0,0,0,30,12,255,"1")
createmyeditbox(30,520,110,1,255,0,0,0,30,12,255,"1")
createmyeditbox(31,520,130,1,255,0,0,0,30,12,255,"1")
createmyeditbox(32,520,150,1,255,0,0,0,30,12,255,"1")
//
createmyeditbox(33,650,10,1,255,0,0,0,30,12,255,"1")
createmyeditbox(34,650,30,1,255,0,0,0,30,12,255,"1")
createmyeditbox(35,650,50,1,255,0,0,0,30,12,255,"1")
createmyeditbox(36,650,70,1,255,0,0,0,30,12,255,"1")
createmyeditbox(37,650,90,1,255,0,0,0,30,12,255,"1")
createmyeditbox(38,650,110,1,255,0,0,0,30,12,255,"1")
createmyeditbox(39,650,130,1,255,0,0,0,30,12,255,"1")
createmyeditbox(40,650,150,1,255,0,0,0,30,12,255,"1")
//
make_my_button(1,720,30,40,"Anim",0,255,0,255)
make_my_button(2,720,80,40,"Quit",255,0,0,255)
createsprite(CursorSprite,CurrentImage)
SetSpriteSize(CursorSprite,Sizex#,Sizey#)
SetSpriteDepth (cursorsprite, 200 )
endfunction
function control()
If GetPointerreleased()
for n=1 to maxsprites
if deleted[n]<>0
myfoundsprite=n
found=1
exit
endif
next
if found=1
found=0
deleted[myfoundsprite]=0
createsprite(myfoundsprite,CurrentImage)
setspritecolor(myfoundsprite,red,green,blue,255)
SetObjectTransparency(myfoundsprite,transparency)
SetSpriteSize(myfoundsprite,Sizex#,Sizey#)
setspriteshape(myfoundsprite,shape)
SetSpriteScaleByOffset(myfoundsprite,scalex,scaley)
setspritepositionbyoffset(myfoundsprite,Mouse.x3,Mouse.y3)
setspritedepth(myfoundsprite,depth)
SetSpriteAngle(myfoundsprite,angle)
setvalues(myfoundsprite)
else
Inc Spritenumber
createsprite(Spritenumber,CurrentImage)
setspritecolor(Spritenumber,red,green,blue,255)
SetObjectTransparency(Spritenumber,transparency)
SetSpriteSize(Spritenumber,Sizex#,Sizey#)
setspriteshape(Spritenumber,shape)
SetSpriteScaleByOffset(spritenumber,scalex,scaley)
setspritepositionbyoffset(Spritenumber,Mouse.x3,Mouse.y3)
setspritedepth(Spritenumber,depth)
SetSpriteAngle(Spritenumber,angle)
setvalues(Spritenumber)
endif
endif
if getrawkeypressed(KEY_F1)
load_level(level)
my_system_message(200,10,200,20,255,0,0,255,0,"Level Loaded!")
endif
if getrawkeypressed(KEY_F2)
save_level(level)
my_system_message(200,10,200,20,255,0,0,255,0,"Level Saved!")
endif
m=GetRawMouseRightPressed()
if m>0
sprite = GetSpriteHit ( GetPointerX ( ), GetPointerY ( ) )
if sprite<>cursorsprite
if mysprite[sprite].selected=0
setspritecolor(sprite,255,0,0,100)
mysprite[sprite].selected=1
elseif mysprite[sprite].selected=1
setspritecolor(sprite,mysprite[sprite].red,mysprite[sprite].blue,mysprite[sprite].green,255)
mysprite[sprite].selected=0
endif
endif
endif
if getrawkeypressed(KEY_DELETE)
for n=1 to maxsprites
if mysprite[n].selected = 1
deletesprite(n)
mysprite[n].selected=0
deleted[n]=1
reset_value(n)
endif
next n
endif
if getrawkeypressed(KEY_F8)
clear()
endif
if getrawkeyreleased(KEY_H)
inc hide
if hide>1
hide=0
endif
select hide
case 0
show_all()
endcase
case 1
hide_all()
endcase
endselect
endif
if getrawkeypressed(KEY_Z)
dec CurrentImage
setspriteimage(cursorsprite,CurrentImage)
endif
if getrawkeypressed(KEY_X)
inc CurrentImage
setspriteimage(cursorsprite,CurrentImage)
endif
read_boxes()
endfunction
function createmyeditbox(number,x#,y#,bordersize#,r,g,b,backcolor,bsizex#,bsizey#,alpha,box$)
createeditbox(number)
SetEditBoxBorderSize(number,bordersize#)
SetEditBoxTextColor(number,r,g,b)
SetEditBoxBorderColor(number,r,g,b,alpha)
SetEditBoxBackgroundColor( number, 0, 0, 0, alpha )
seteditboxsize(number,bsizex#,bsizey#)
SetEditBoxPosition(number,x#,y#)
FixEditBoxToScreen(number,1)
seteditboxdepth(number,0)
SetEditBoxText(number,box$)
endfunction
function createmytext(number,x#,y#,size,r,g,b,mystring$,depth)
createtext(number,mystring$)
settextsize(number,size)
settextcolor(number,r,b,g,255)
SetTextPosition(number,x#,y#)
FixTextToScreen(number,1)
settextdepth(number,depth)
endfunction
function make_my_button(index,x,y,size,text$,br,bg,bb,al)
AddVirtualButton( index, x, y, size )
setvirtualbuttontext(index,text$)
SetVirtualButtonColor(index,br,bg,bb)
SetVirtualButtonAlpha(index,al)
SetVirtualButtonVisible(index,1)
endfunction
function load_images()
for n=1 to 100
f$=str(n) + ".png"
if getfileexists(f$)
loadimage (n,f$)
`SetImageWrapU(n,1)
`SetImageWrapV(n,1)
endif
next
endfunction
function hide_all()
for n=1 to 100
if GetEditBoxExists(n)
SetEditBoxVisible(n,0)
endif
if gettextexists(n)
settextvisible(n,0)
endif
if GetVirtualButtonExists(n)
SetVirtualButtonVisible(n,0)
endif
next n
endfunction
function show_all()
for n=1 to 100
if GetEditBoxExists(n)
SetEditBoxVisible(n,1)
endif
if gettextexists(n)
settextvisible(n,1)
endif
if GetVirtualButtonExists(n)
SetVirtualButtonVisible(n,1)
endif
next n
endfunction
function read_boxes()
if getrawkeypressed(KEY_ENTER)
focus=GetCurrentEditBox()
select focus
case 2
t$=GetEditBoxText(2)
texturerep=val(t$)
select texturerep
case 1
SetImageWrapU(GetSpriteImageID(cursorsprite),1)
SetImageWrapV(GetSpriteImageID(cursorsprite),1)
SetSpriteUVScale(cursorsprite,1.0/scalex,1.0/scaley)
`sync()
endcase
case 0
SetImageWrapU(GetSpriteImageID(cursorsprite),0)
SetImageWrapV(GetSpriteImageID(cursorsprite),0)
SetSpriteUVScale(cursorsprite,1.0,1.0)
`sync()
endcase
endselect
endcase
case 3
t$=GetEditBoxText(3)
t=val(t$)
gridx=t
endcase
case 4
t$=GetEditBoxText(4)
t=val(t$)
gridy=t
endcase
case 5
t$=GetEditBoxText(5)
t=val(t$)
scalex=t
SetSpriteScaleByOffset(CursorSprite,scalex,scaley)
select texturerep
case 1
SetImageWrapU(GetSpriteImageID(cursorsprite),1)
SetImageWrapV(GetSpriteImageID(cursorsprite),1)
SetSpriteUVScale(cursorsprite,1.0/scalex,1.0/scaley)
`sync()
endcase
case 0
SetImageWrapU(GetSpriteImageID(cursorsprite),0)
SetImageWrapV(GetSpriteImageID(cursorsprite),0)
SetSpriteUVScale(cursorsprite,1.0,1.0)
`sync()
endcase
endselect
endcase
case 6
t$=GetEditBoxText(6)
t=val(t$)
scaley=t
SetSpriteScaleByOffset(CursorSprite,scalex,scaley)
select texturerep
case 1
SetImageWrapU(GetSpriteImageID(cursorsprite),1)
SetImageWrapV(GetSpriteImageID(cursorsprite),1)
SetSpriteUVScale(cursorsprite,1.0/scalex,1.0/scaley)
`sync()
endcase
case 0
SetImageWrapU(GetSpriteImageID(cursorsprite),0)
SetImageWrapV(GetSpriteImageID(cursorsprite),0)
SetSpriteUVScale(cursorsprite,1.0,1.0)
`sync()
endcase
endselect
endcase
case 7
t$=GetEditBoxText(7)
t=val(t$)
angle=t
setspriteangle(cursorsprite,angle)
endcase
case 8
t$=GetEditBoxText(8)
t=val(t$)
CurrentImage=t
setspriteimage(cursorsprite,CurrentImage)
endcase
case 9
t$=GetEditBoxText(9)
t=val(t$)
groupnumber=t
endcase
case 10
t$=GetEditBoxText(10)
t=val(t$)
red=t
setspritecolor(cursorsprite,red,green,blue,255)
endcase
case 11
t$=GetEditBoxText(11)
t=val(t$)
green=t
setspritecolor(cursorsprite,red,green,blue,255)
endcase
case 12
t$=GetEditBoxText(12)
t=val(t$)
blue=t
setspritecolor(cursorsprite,red,green,blue,255)
endcase
case 13
t$=GetEditBoxText(13)
t#=valfloat(t$)
sizex#=t#
setspritesize(cursorsprite,sizex#,sizey#)
endcase
case 14
t$=GetEditBoxText(14)
t#=valfloat(t$)
sizey#=t#
setspritesize(cursorsprite,sizex#,sizey#)
endcase
case 15
t$=GetEditBoxText(15)
t=val(t$)
level=t
endcase
case 17
t$=GetEditBoxText(17)
t=val(t$)
transparency=t
SetSpriteTransparency(cursorsprite,transparency)
endcase
case 18
t$=GetEditBoxText(18)
t=val(t$)
shape=t
endcase
case 19
t$=GetEditBoxText(19)
t=val(t$)
physicstype=t
endcase
case 20
t$=GetEditBoxText(20)
t=val(t$)
tiletype=t
endcase
case 21
t$=GetEditBoxText(21)
t=val(t$)
depth=t
endcase
endselect
endif
endfunction
function FillMouse(gridx,gridy)
Mouse.x1#=getpointerx()
Mouse.y1#=getpointery()
Mouse.x2#=screentoworldx(Mouse.x1#)
Mouse.y2#=screentoworldy(Mouse.y1#)
Mouse.x3=floor(Mouse.x2#/gridx)*gridx
Mouse.y3=floor(Mouse.y2#/gridy)*gridy
endfunction
function setvalues(spr)
mysprite[spr].spritenumber=spr
mysprite[spr].angle=angle
mysprite[spr].canrotate=canrotate
mysprite[spr].blue=blue
mysprite[spr].red=red
mysprite[spr].green=green
mysprite[spr].sizex#=sizex#
mysprite[spr].sizey#=sizey#
mysprite[spr].scalex=scalex
mysprite[spr].scaley=scaley
mysprite[spr].groupnumber=groupnumber
mysprite[spr].xp#=Mouse.x3
mysprite[spr].yp#=Mouse.y3
mysprite[spr].texturerep=texturerep
mysprite[spr].depth=depth
mysprite[spr].friction#=friction#
mysprite[spr].restitution#=restitution#
mysprite[spr].canrotate=canrotate
mysprite[spr].shape=shape
mysprite[spr].physicstype=physicstype
mysprite[spr].visibility=visibility
mysprite[spr].transparency=transparency
mysprite[spr].imagenumber=CurrentImage
mysprite[spr].tilevalue=tilevalue
mysprite[spr].alpha=alpha
select texturerep
case 1
SetImageWrapU(GetSpriteImageID(spr),1)
SetImageWrapV(GetSpriteImageID(spr),1)
SetSpriteUVScale(spr,1.0/(scalex),1.0/(scaley))
`sync()
endcase
case 0
SetImageWrapU(GetSpriteImageID(spr),0)
SetImageWrapV(GetSpriteImageID(spr),0)
SetSpriteUVScale(spr,1.0,1.0)
`sync()
endcase
endselect
endfunction
function save_level(level)
f$=""
f$="level"
f$=f$+str(level)
f$=f$+".lev"
myfile=opentowrite(f$,0)
for n=1 to maxsprites
writefloat(myfile,mysprite[n].xp#)
writefloat(myfile,mysprite[n].yp#)
writefloat(myfile,mysprite[n].sizex#)
writefloat(myfile,mysprite[n].sizey#)
writeinteger(myfile,mysprite[n].scalex)
writeinteger(myfile,mysprite[n].scaley)
writefloat(myfile,mysprite[n].restitution#)
writefloat(myfile,mysprite[n].friction#)
writeinteger(myfile,mysprite[n].spritenumber)
writeinteger(myfile,mysprite[n].imagenumber)
writeinteger(myfile,mysprite[n].transparency)
writeinteger(myfile,mysprite[n].visibility)
writeinteger(myfile,mysprite[n].groupnumber)
writeinteger(myfile,mysprite[n].physicstype)
writeinteger(myfile,mysprite[n].shape)
writeinteger(myfile,mysprite[n].angle)
writeinteger(myfile,mysprite[n].depth)
writeinteger(myfile,mysprite[n].host)
writeinteger(myfile,mysprite[n].client)
writeinteger(myfile,mysprite[n].tilevalue)
writeinteger(myfile,mysprite[n].canrotate)
writeinteger(myfile,mysprite[n].red)
writeinteger(myfile,mysprite[n].green)
writeinteger(myfile,mysprite[n].blue)
writeinteger(myfile,mysprite[n].selected)
writeinteger(myfile,mysprite[n].framestart)
writeinteger(myfile,mysprite[n].frameamount)
writeinteger(myfile,mysprite[n].frameend)
writeinteger(myfile,mysprite[n].loopframe)
writeinteger(myfile,mysprite[n].texturerep)
writeinteger(myfile,mysprite[n].alpha)
next n
closefile(myfile)
endfunction
function my_system_message(textnumber,tx#,ty#,textsize#,r,g,b,alpha,depth,message$)
createtext(textnumber,message$)
settextsize(textnumber,textsize#)
settextcolor(textnumber,r,g,b,alpha)
settextposition(textnumber,tx#,ty#)
settextdepth(textnumber,depth)
settextvisible(textnumber,1)
FixTextToScreen(textnumber,1)
sync()
sleep(1500)
deletetext(textnumber)
endfunction
function reset_value(spr)
mysprite[spr].xp#=0
mysprite[spr].yp# =0
mysprite[spr].sizex# =0
mysprite[spr].sizey# =0
mysprite[spr].scalex =0
mysprite[spr].scaley =0
mysprite[spr].restitution# =0
mysprite[spr].friction# =0
mysprite[spr].spritenumber =0
mysprite[spr].imagenumber =0
mysprite[spr].transparency =0
mysprite[spr].visibility =0
mysprite[spr].groupnumber =0
mysprite[spr].physicstype=0
mysprite[spr].shape =0
mysprite[spr].angle =0
mysprite[spr].depth=0
mysprite[spr].host =0
mysprite[spr].client =0
mysprite[spr].tilevalue=0
mysprite[spr].canrotate =0
mysprite[spr].red =0
mysprite[spr].green =0
mysprite[spr].blue =0
mysprite[spr].selected =0
mysprite[spr].framestart =0
mysprite[spr].frameamount =0
mysprite[spr].frameend =0
mysprite[spr].loopframe =0
mysprite[spr].texturerep=0
mysprite[spr].alpha=255
endfunction
function load_level(level)
f$=""
f$="level"
f$=f$+str(level)
f$=f$+".lev"
myfile=opentoread(f$)
if getfileexists(f$)
clear()
for n=1 to maxsprites
mysprite[n].xp#=readfloat(myfile)
mysprite[n].yp#=readfloat(myfile)
mysprite[n].sizex#=readfloat(myfile)
mysprite[n].sizey#=readfloat(myfile)
mysprite[n].scalex=readinteger(myfile)
mysprite[n].scaley=readinteger(myfile)
mysprite[n].restitution#=readfloat(myfile)
mysprite[n].friction#=readfloat(myfile)
mysprite[n].spritenumber=readinteger(myfile)
mysprite[n].imagenumber=readinteger(myfile)
mysprite[n].transparency=readinteger(myfile)
mysprite[n].visibility=readinteger(myfile)
mysprite[n].groupnumber=readinteger(myfile)
mysprite[n].physicstype=readinteger(myfile)
mysprite[n].shape=readinteger(myfile)
mysprite[n].angle=readinteger(myfile)
mysprite[n].depth=readinteger(myfile)
mysprite[n].host=readinteger(myfile)
mysprite[n].client=readinteger(myfile)
mysprite[n].tilevalue=readinteger(myfile)
mysprite[n].canrotate=readinteger(myfile)
mysprite[n].red=readinteger(myfile)
mysprite[n].green=readinteger(myfile)
mysprite[n].blue=readinteger(myfile)
mysprite[n].selected=readinteger(myfile)
mysprite[n].framestart=readinteger(myfile)
mysprite[n].frameamount=readinteger(myfile)
mysprite[n].frameend=readinteger(myfile)
mysprite[n].loopframe=readinteger(myfile)
mysprite[n].texturerep=readinteger(myfile)
mysprite[n].alpha=readinteger(myfile)
//place the sprite
if mysprite[n].spritenumber<>0
createsprite(mysprite[n].spritenumber,mysprite[n].imagenumber)
setspritesize(mysprite[n].spritenumber,mysprite[n].sizex#,mysprite[n].sizey#)
setspriteshape(mysprite[n].spritenumber,mysprite[n].shape)
SetSpriteScaleByOffset(mysprite[n].spritenumber,mysprite[n].scalex,mysprite[n].scaley)
SetSpriteAngle(mysprite[n].spritenumber,mysprite[n].angle)
setspritecolor(mysprite[n].spritenumber,mysprite[n].red,mysprite[n].green,mysprite[n].blue,255)
SetSpriteTransparency(mysprite[n].spritenumber,mysprite[n].transparency)
SetSpritePositionByOffset(mysprite[n].spritenumber,mysprite[n].xp#,mysprite[n].yp#)
setspritedepth(mysprite[n].spritenumber,mysprite[n].depth)
endif
next n
closefile(myfile)
for n=1 to maxsprites
if mysprite[n].spritenumber<>0
if spritenumber<=mysprite[n].spritenumber
spritenumber=mysprite[n].spritenumber+1
endif
endif
next n
endif
endfunction
function clear()
for n=1 to maxsprites
if mysprite[n].spritenumber<>0
deletesprite(n)
endif
mysprite[n].xp#=0
mysprite[n].yp#=0
mysprite[n].sizex#=0
mysprite[n].sizey#=0
mysprite[n].scalex=0
mysprite[n].scaley=0
mysprite[n].restitution#=0
mysprite[n].friction#=0
mysprite[n].spritenumber=0
mysprite[n].imagenumber=0
mysprite[n].transparency=0
mysprite[n].visibility=0
mysprite[n].groupnumber=0
mysprite[n].physicstype=0
mysprite[n].shape=0
mysprite[n].angle=0
mysprite[n].depth=0
mysprite[n].host=0
mysprite[n].client=0
mysprite[n].tilevalue=0
mysprite[n].canrotate=0
mysprite[n].red=0
mysprite[n].green=0
mysprite[n].blue=0
mysprite[n].selected=0
mysprite[n].framestart=0
mysprite[n].frameamount=0
mysprite[n].frameend=0
mysprite[n].loopframe=0
mysprite[n].texturerep=0
mysprite[n].alpha=255
deleted[n]=0
spritenumber=0
next n
endfunction
and here is an example of how I load in the created level and put it to use, i would create a new project(in this case called zenoid) and copy over the needed functions from the editor, copy the media folders contents of the editors to the zenoid media folder, and copy the level saved out from the editor to zenoid media folder, what I basically did was make sure that the object I placed for the player had a group value of 1, the group value is defined in the editor under the text editor box coincidentally labelled 'group'! in the code below somewhere (in bold) I check to see if the group value is 1, if so then I indicate it as being the players sprite!
// Project: Zeknoid
// Created: 2015-10-25
// set window properties
SetWindowSize( 800, 600, 1 )
// set display properties
SetVirtualResolution( 800, 600 )
SetSyncRate(60,0)
SetOrientationAllowed( 1, 1, 1, 1 )
setphysicsscale(0.05) //belongs resolution! default 1 unit = 1 meter
SetPhysicsGravity(0 , 0)
`setphysicsdebugon()
#constant maxsprites=5000
global level=1
global quit=0
global hits=0
global ballsprite=0
global playersprite=0
type mysprites
xp# as float
yp# as float
sizex# as float
sizey# as float
scalex as integer
scaley as integer
restitution# as float
friction# as float
spritenumber as integer
imagenumber as integer
transparency as integer
visibility as integer
groupnumber as integer
physicstype as integer
shape as integer
angle as integer
depth as integer
host as integer
client as integer
tilevalue as integer
canrotate as integer
red as integer
green as integer
blue as integer
selected as integer
framestart as integer
frameamount as integer
frameend as integer
loopframe as integer
texturerep as integer
alpha as integer
endtype
dim mysprite[maxsprites] as mysprites
load_images()
init()
load_level(level)
Repeat
p=GetVirtualButtonPressed(1)
oldx#=GetSpriteXByOffset(ballsprite)
oldy#=GetSpriteYByOffset(ballsprite)
ballCollision(ballsprite)
x#=GetVirtualJoystickX(1)
if x#<0
setspriteposition(playersprite,getspritex(playersprite)-1,getspritey(playersprite))
`SetSpritePhysicsForce( playersprite, getspritex(playersprite), getspritey(playersprite), -0.1,0 )
endif
if x#>0
setspriteposition(playersprite,getspritex(playersprite)+1,getspritey(playersprite))
`SetSpritePhysicsForce( playersprite, getspritex(playersprite), getspritey(playersprite), -0.1,0 )
endif
if p
quit=1
endif
Print( ScreenFPS() )
print("hits = "+str(hits))
Sync()
Until quit=1
function init()
AddVirtualJoystick(1,60,550,64)
addvirtualbutton(1,720,550,40)
endfunction
function load_images()
for n=1 to 100
f$=str(n) + ".png"
if getfileexists(f$)
loadimage (n,f$)
`SetImageWrapU(n,1)
`SetImageWrapV(n,1)
endif
next
endfunction
function load_level(level)
f$=""
f$="level"
f$=f$+str(level)
f$=f$+".lev"
myfile=opentoread(f$)
if getfileexists(f$)
clear()
for n=1 to maxsprites
mysprite[n].xp#=readfloat(myfile)
mysprite[n].yp#=readfloat(myfile)
mysprite[n].sizex#=readfloat(myfile)
mysprite[n].sizey#=readfloat(myfile)
mysprite[n].scalex=readinteger(myfile)
mysprite[n].scaley=readinteger(myfile)
mysprite[n].restitution#=readfloat(myfile)
mysprite[n].friction#=readfloat(myfile)
mysprite[n].spritenumber=readinteger(myfile)
mysprite[n].imagenumber=readinteger(myfile)
mysprite[n].transparency=readinteger(myfile)
mysprite[n].visibility=readinteger(myfile)
mysprite[n].groupnumber=readinteger(myfile)
mysprite[n].physicstype=readinteger(myfile)
mysprite[n].shape=readinteger(myfile)
mysprite[n].angle=readinteger(myfile)
mysprite[n].depth=readinteger(myfile)
mysprite[n].host=readinteger(myfile)
mysprite[n].client=readinteger(myfile)
mysprite[n].tilevalue=readinteger(myfile)
mysprite[n].canrotate=readinteger(myfile)
mysprite[n].red=readinteger(myfile)
mysprite[n].green=readinteger(myfile)
mysprite[n].blue=readinteger(myfile)
mysprite[n].selected=readinteger(myfile)
mysprite[n].framestart=readinteger(myfile)
mysprite[n].frameamount=readinteger(myfile)
mysprite[n].frameend=readinteger(myfile)
mysprite[n].loopframe=readinteger(myfile)
mysprite[n].texturerep=readinteger(myfile)
mysprite[n].alpha=readinteger(myfile)
//place the sprite
if mysprite[n].spritenumber<>0
createsprite(mysprite[n].spritenumber,mysprite[n].imagenumber)
setspritesize(mysprite[n].spritenumber,mysprite[n].sizex#,mysprite[n].sizey#)
setspriteshape(mysprite[n].spritenumber,mysprite[n].shape)
SetSpriteScaleByOffset(mysprite[n].spritenumber,mysprite[n].scalex,mysprite[n].scaley)
SetSpriteAngle(mysprite[n].spritenumber,mysprite[n].angle)
setspritecolor(mysprite[n].spritenumber,mysprite[n].red,mysprite[n].green,mysprite[n].blue,255)
SetSpriteTransparency(mysprite[n].spritenumber,mysprite[n].transparency)
SetSpritePositionByOffset(mysprite[n].spritenumber,mysprite[n].xp#,mysprite[n].yp#)
setspritedepth(mysprite[n].spritenumber,mysprite[n].depth)
setspritegroup(mysprite[n].spritenumber,mysprite[n].groupnumber)
select mysprite[n].groupnumber
[b]case 1
playersprite=mysprite[n].spritenumber
setspritephysicson(playersprite,3)
setspritephysicsmass(playersprite,10)
`SetSpritePhysicsangularVelocity( ballsprite,200 )
`SetSpritePhysicsImpulse ( ballsprite, getspritex(ballsprite), getspritey(ballsprite), 2000, 2000)
SetSpritePhysicsRestitution(playersprite,1)
setspritephysicsfriction(playersprite,0)
SetSpritePhysicsCanRotate(playersprite,0)
endcase[/b]
case 2
ballsprite=mysprite[n].spritenumber
setspritephysicson(ballsprite,2)
setspritephysicsmass(ballsprite,1)
`SetSpritePhysicsangularVelocity( ballsprite,2000)
SetSpritePhysicsImpulse ( ballsprite, getspritex(ballsprite), getspritey(ballsprite), 6000, 6000)
SetSpritePhysicsRestitution(ballsprite,1)
setspritephysicsfriction(ballsprite,0)
SetSpritePhysicsCanRotate(ballsprite,1)
SetSpritePhysicsDamping( ballsprite, 0.0 )
SetSpritePhysicsFriction ( ballsprite, 0.0)
setspritescalebyoffset(ballsprite,0.5,0.5)
endcase
case 3
bricksprite=mysprite[n].spritenumber
setspritephysicson(bricksprite,1)
setspritephysicsmass(bricksprite,3)
`SetSpritePhysicsangularVelocity( ballsprite,20 )
`SetSpritePhysicsImpulse ( ballsprite, getspritex(ballsprite), getspritey(ballsprite), 2000, 2000)
SetSpritePhysicsRestitution(bricksprite,1)
setspritephysicsfriction(bricksprite,0)
SetSpritePhysicsCanRotate(bricksprite,0)
endcase
case 4
wallsprite=mysprite[n].spritenumber
setspritephysicson(wallsprite,1)
endcase
endselect
endif
next n
closefile(myfile)
for n=1 to maxsprites
if mysprite[n].spritenumber<>0
if spritenumber<=mysprite[n].spritenumber
spritenumber=mysprite[n].spritenumber+1
endif
endif
next n
endif
endfunction
function clear()
for n=1 to maxsprites
if mysprite[n].spritenumber<>0
deletesprite(n)
endif
mysprite[n].xp#=0
mysprite[n].yp#=0
mysprite[n].sizex#=0
mysprite[n].sizey#=0
mysprite[n].scalex=0
mysprite[n].scaley=0
mysprite[n].restitution#=0
mysprite[n].friction#=0
mysprite[n].spritenumber=0
mysprite[n].imagenumber=0
mysprite[n].transparency=0
mysprite[n].visibility=0
mysprite[n].groupnumber=0
mysprite[n].physicstype=0
mysprite[n].shape=0
mysprite[n].angle=0
mysprite[n].depth=0
mysprite[n].host=0
mysprite[n].client=0
mysprite[n].tilevalue=0
mysprite[n].canrotate=0
mysprite[n].red=0
mysprite[n].green=0
mysprite[n].blue=0
mysprite[n].selected=0
mysprite[n].framestart=0
mysprite[n].frameamount=0
mysprite[n].frameend=0
mysprite[n].loopframe=0
mysprite[n].texturerep=0
mysprite[n].alpha=255
next n
endfunction
function BallCollision(ballsprite)
c=GetSpriteFirstContact(ballsprite)
do
if c=0 then exit
spr=GetSpriteContactSpriteID2() //komisch knn 0 zurück geben^^
if spr<>0
cx#=GetSpriteContactWorldX()
cy#=GetSpriteContactWorldy()
`BrickHit(spr) //< löscht ein Sprite!
inc hits
vx#= getspritexbyoffset(ballsprite)-cx#
vy#= getspriteybyoffset(ballsprite)-cy#
l#=sqrt(vx#*vx# + vy#*vy#)
if l#<1.0 then l#=1.0
vx#=vx#/l#
vy#=vy#/l#
vx#=vx#*0.5
vy#=vy#*0.5
SetSpritePhysicsImpulse( ballsprite, getspritexbyoffset(ballsprite),getspriteybyoffset(ballsprite), vx#, vy# )
if mysprite[spr].groupnumber=3
deletesprite(spr)
endif
endif
c=GetSpriteNextContact()
loop
endfunction
the above is the start of a 'breakout' clone, the collisions are already in there and it uses the box physics. hope you learn from this code!
If i have more time I will finish all this stuff and release it here with all the documentation explaining it all fully! just that health problems have thrwarted my plan somewhat!
***edit** you also need keys.agk for the first code, here is the code: name a new file in the project as keys.agk and paste the code below
#constant spacer# = 0.125
#constant KEY_BACK = 8
#constant KEY_TAB = 9
#constant KEY_ENTER = 13
#constant KEY_SHIFT = 16
#constant KEY_CONTROL = 17
#constant KEY_ESCAPE = 27
#constant KEY_SPACE = 32
#constant KEY_PAGEUP = 33
#constant KEY_PAGEDOWN = 34
#constant KEY_END = 35
#constant KEY_HOME = 36
#constant KEY_LEFT = 37
#constant KEY_UP = 38
#constant KEY_RIGHT = 39
#constant KEY_DOWN = 40
#constant KEY_INSERT = 45
#constant KEY_DELETE = 46
#constant KEY_0 = 48
#constant KEY_1 = 49
#constant KEY_2 = 50
#constant KEY_3 = 51
#constant KEY_4 = 52
#constant KEY_5 = 53
#constant KEY_6 = 54
#constant KEY_7 = 55
#constant KEY_8 = 56
#constant KEY_9 = 57
#constant KEY_A = 65
#constant KEY_B = 66
#constant KEY_C = 67
#constant KEY_D = 68
#constant KEY_E = 69
#constant KEY_F = 70
#constant KEY_G = 71
#constant KEY_H = 72
#constant KEY_I = 73
#constant KEY_J = 74
#constant KEY_K = 75
#constant KEY_L = 76
#constant KEY_M = 77
#constant KEY_N = 78
#constant KEY_O = 79
#constant KEY_P = 80
#constant KEY_Q = 81
#constant KEY_R = 82
#constant KEY_S = 83
#constant KEY_T = 84
#constant KEY_U = 85
#constant KEY_V = 86
#constant KEY_W = 87
#constant KEY_X = 88
#constant KEY_Y = 89
#constant KEY_Z = 90
#constant KEY_F1 = 112
#constant KEY_F2 = 113
#constant KEY_F3 = 114
#constant KEY_F4 = 115
#constant KEY_F5 = 116
#constant KEY_F6 = 117
#constant KEY_F7 = 118
#constant KEY_F8 = 119
#constant KEY_PERIOD = 190
#constant KEY_SLASH = 191
#constant KEY_LBRACKET=219
#constant KEY_RBRACKET=221
#constant maxobjects = 5000
#constant camspeed#=0.1
The main reason I posted here was to also think that i may not get chance to finish it, so just in case, then perhaps someone like you or someone else can finish it off for me! I will nevertheless code as much as I can to try and complete it and document it all. God willing!Besides a minor bug here and there it is all good so far
Hail to the king, baby!