Hi TDK
I've been working on a basic level editor my self.
I'm kind of A noob but if any of my code can be of help to you
then feel free to use it.
I'm particularly proud of the camera movement.
well here's my entire program so far
(here's hoping this actualy goes in a code snipit
this is only my second post.)
`use right click to move
`left clikt to place objects
`space to change to next object
`geen cone taraforms "use (u) key to switch up and down"
`scroll wheel rotates object
`num pad to look left/right and move up/down
`hold shift and use mouse to tilt cam
`F2 save, F3 load, F4 delete
`need to do
` get save working
` make save matrix
` make scale object useing key 31 (S)
`clean up code
sync on
sync rate 40
Xrez=800
Yrez=600
set display mode Xrez,Yrez,32
`set window on
hide mouse
num = 1
flag = 0
fl=0
Q=1
strech# = 0
U#=180
`load image "grass1.jpg",1
`load image "grass.jpg",2
make object cone 1,1
rotate object 1,0,0,U#
color object 1, rgb(0,255,0)
make object cube 2,2
make object cylinder 3,2
color object 3, rgb(200,200,255)
`scale object 3,strech#,100,100
move object 2,5
`texture object 3,2
`load object "S-wall.x",4
`scale object 4,400,400,400
`rotate object 4,90,0,0
`load object "wide-S-wall.x",5
`scale object 5,400,400,400
`rotate object 5,90,0,0
`load object "barnx2.x",6
make matrix 1,60,80,60,80
position matrix 1,0,-1,0
`prepare matrix texture 1,1,1,1
position camera 15,15,22.5
rotate camera 45,0,0
`The start of our loop
do
`only show active object
hide object 1
hide object 2
hide object 3
`hide object 4
`hide object 5
`hide object 6
show object num
` get values
camY# = (camera position Y())
camAngX# = camera angle X()
camAngY# = camera angle Y()
camAngZ# = camera angle Z()
obX#=object position X(num)
obY#=object position Y(num)
obZ#=object position Z(num)
speedx#=((mousex()-(Xrez/2))*.01)
speedy#=((mousey()-(yrez/2))*.01)
posY#=((Yrez-mousey())/5)
posX#=(((Xrez/2)-mousex())/-10)
sizeX#=object size X(num)
sizeY#=object size Y(num)
sizeZ#=object size Z(num)
`Click to place object
if mouseclick()=1 and flag = 0 then gosub placeobject
if mouseclick()=1
flag = 1
else
flag = 0
endif
`Use space to change to next object
if spacekey()=1 and flag2=0 then num=num+1
if num>3 then num=1
if spacekey()=1
flag2 = 1
else
flag2 = 0
endif
`Hold right click to move around level
if mouseclick()=2
camX# = (camera position X())
camZ# = (camera position Z())
else
camX# = int(camera position X())
camZ# = int(camera position Z())
endif
`Fallow terrain height
height#=get ground height(1,obX#,obZ#)
Zval#=height#
`Change terain height
if keystate(22)=1 and flag7=0 then U# = U#+180
if keystate(22)=1
flag7 = 1
else
flag7 = 0
endif
if U#>180 then U#=0
if num=1 and obZ#<80 and obZ#>0 and obX#<60 and obX#>0 and mouseclick()=1
set matrix height 1,obX#,obZ#,height#+.2
set matrix height 1,obX#,obZ#-1,height#+.1
set matrix height 1,obX#,obZ#+1,height#+.1
set matrix height 1,obX#-1,obZ#,height#+.1
set matrix height 1,obX#+1,obZ#,height#+.1
endif
if num=1 and obZ#<80 and obZ#>0 and obX#<60 and obX#>0 and U#=180 and mouseclick()=1
set matrix height 1,obX#,obZ#,height#-.2
set matrix height 1,obX#,obZ#-1,height#-.1
set matrix height 1,obX#,obZ#+1,height#-.1
set matrix height 1,obX#-1,obZ#,height#-.1
set matrix height 1,obX#+1,obZ#,height#-.1
endif
rotate object 1,0,0,U#
`Use scroll wheel to rotate object
if r=1 and shiftkey()=0
if mousemoveZ()>MMZ and flag3=0 and shiftkey()=0 then y=wrapvalue(y+45)
if mousemoveZ()<MMZ and flag3=0 and shiftkey()=0 then y=wrapvalue(y-45)
if mousemoveZ()>MMZ or mousemoveZ()<MMZ
flag3 = 1
else
flag3 = 0
endif
MMZ=mousemoveZ()
endif
`scale object
if keystate(31)=1
MMZ=0
r=0
scale object num,sizeX#+mousemoveZ()*.1,sizeY#+mousemoveZ()*.1,sizeZ#+mousemoveZ()*.1
else
r=1
endif
`a poor atempted at makeing walls fit when placed at angles
if y=45 or y=135 or y=225 or y=315
strech#=140
else
strech#=200
endif
scale object 2,strech#,400,20
rotate object 2,0,y,0
rotate object 3,0,y,0
` rotate object 4,90,0,y
` rotate object 5,90,0,y
` rotate object 6,0,y,0
`Control input for camera rotation/height
`raise/lower camera
if keystate(72)=1 then camY#=camY#+1
if keystate(80)=1 then camY#=camY#-1
`rotate camera view
if keystate(75) and flag4=0 then Q=Q-1
if keystate(75)=1
flag4 = 1
else
flag4 = 0
endif
if keystate(77) and flag5=0 then Q=Q+1
if keystate(77)=1
flag5 = 1
else
flag5 = 0
endif
`Q selects look direction
if Q=5 or Q=-3 then Q=1
if Q=1 then gosub forward
if Q=2 or Q=-2 then gosub right
if Q=3 or Q=-1 then gosub backward
if Q=4 or Q=0 then gosub left
position camera camX#,camY#,camZ#
yrotate camera wrapvalue(camAngY#)
`look up/down using shift key
if shiftkey()=1
position mouse Xrez/2,Yrez/2
if mousemovey() > 0 then xrotate camera wrapvalue(camAngX#+1)
if mousemovey() < 0 then xrotate camera wrapvalue(camAngX#-1)
` if mousemoveZ() > 0 then Move camera 1
` if mousemoveZ() < 0 then Move camera -1
endif
` wire frame
if keystate(17)=1 and flag6 = 0 then wframe = wframe + 1
if wframe>1 then wframe = 0
if keystate(17)=1
flag6 = 1
else
flag6 = 0
endif
if wframe =1
set matrix wireframe off 1
else
set matrix wireframe on 1
endif
`Save / Load / Delete Static objects
`F2 is save, F3 load and F4 is delete
if keystate(60)=1 then gosub _save_routine
if keystate(61)=1 then gosub load
if keystate(62)=1 then delete static objects
`Debug info
set cursor 10,10
print "mouse x " , mousex()
print "mouse y " , mousey()
print mousemovez()
print "object number ",num
print "object angle ",y
print obX#," ",obZ#
print "X ",camX#," Z ",camZ#
print sizeX#," ",sizeY#," ",sizeZ#
print posY#," ",posX#
print speedY#," ",speedX#
print scancode()
update matrix 1
sync
loop
`gosubs
` SPECIAL THANKS TO LATCH FOR THIS ONE!
_save_routine:
repeat
text 300,400,"are you sure you want to save? (Y)/(N)"
choice$=lower$(inkey$())
until choice$="y" or choice$="n"
if choice$="y"
set cursor 300,440
Set Camera View 0,0,1,1
input "Please Enter File Name : ";static$
save static objects "static$"
text 300,460,"File "+static$+" was saved successfully"
else
text 300,460,"LEVEL NOT SAVED !!!"
endif
wait 1000
Set Camera View 0,0,800,600
return
load:
load static objects "static$"
return
placeobject:
if num>1
make static object num
endif
return
`camera movement
forward:
if mouseclick()=2
camX#=camX#+speedx#
camZ#=(camZ#-speedy#)
endif
camAngY#=0
position object num,posX#+camX#,Zval#,(posY#+camZ#)-32.5
return
right:
camAngY#=90
if mouseclick()=2
camX#=camX#-speedy#
camZ#=camZ#-speedx#
endif
position object num,(posY#-32)+camX#,Zval#,((posX#*-1)+camZ#)+.5
return
backward:
if mouseclick()=2
camX#=camX#-speedx#
camZ#=(camZ#+speedy#)
endif
camAngY#=180
position object num,(posX#*-1)+camX#,Zval#,((posY#*-1)+camZ#)+32.5
return
left:
if mouseclick()=2
camX#=camX#+speedy#
camZ#=camZ#+speedx#
endif
camAngY#=270
position object num,((posY#*-1)+camX#)+32,Zval#,((posX#)+camZ#)+.5
return
Why do we BAKE cookies and COOK bacon?