X Zone Edtior Source
Community Forums/Developer Stations/X Zone Edtior Source
| ||
X Zone Editor - http://www.blitzbasic.com/toolbox/toolbox.php?tool=197 Very poor world dropper, now open source. Poor quality code design too;) But if anyone wants to learn off of it, or rip anything from code, feel free. Was made years ago when I was starting in blitz3d. You will need to download the media from the site as well. You can click the link above to go to the toolbox and download. This is not a release, doesnt require comments, but go ahead if you want. Note: SkyBox function code taken from Blitz3D Examples Source: Graphics3D 800,600,32,2 SetBuffer BackBuffer() Const UpKey = 200 Const DownKey = 208 Const LeftKey = 203 Const RightKey = 205 Global Camera = CreateCamera() Global World = CreatePivot() Global Cursor = LoadImage("Cursor.bmp") Global ID% Global New_ID% Global X# Global Y# Global Z# Global O.Objc Global CollisionType% Global FX% Global Fit% Global Obje$ Global Scale# Global TexDup$ Global Tex1$ Global Tex2$ Global Trunk% Global Branch% Global Tree1$ Global Tree2$ Global Sky Global A% Global Duplicate% Global ShowGUI% = 1 Global DupCounter% Global DupWait% = 1000 EntityType Camera,1 CameraRange Camera,1,10000 Type Button Field Name$ Field ID% Field Image% Field Colors% Field X# Field Y# Field Height# Field Width# End Type HidePointer Type Objc Field Name$ Field State$ Field ForWard% Field Texture$ Field Entity% Field CollisionType% Field ID% Field Rotate% Field X# Field Y# Field Z# Field Scale0# Field Scale1# Field Scale2# Field Image Field FX% Field Fit% End Type Global Entity2% = Camera B.Button = New Button B\Name$ = "Load" B\ID% = 1 B\Colors% = 100 B\X# = 0 B\Y# = 0 B\Height = 120 B\Width = 20 B.Button = New Button B\Name$ = "Save" B\ID% = 2 B\Colors% = 100 B\X# = 0 B\Y# = 50 B\Height = 120 B\Width = 20 B.Button = New Button B\Name$ = "Load Object" B\ID% = 3 B\Colors% = 100 B\X# = 0 B\Y# = 100 B\Height = 120 B\Width = 20 B.Button = New Button B\Name$ = "Load Sprite" B\ID% = 4 B\Colors% = 100 B\X# = 0 B\Y# = 150 B\Height = 120 B\Width = 20 B.Button = New Button B\Name$ = "Duplicate Object" B\ID% = 5 B\Colors% = 100 B\X# = 0 B\Y# = 200 B\Height = 150 B\Width = 20 B.Button = New Button B\Name$ = "Duplicate Sprite" B\ID% = 6 B\Colors% = 1000 B\X# = 0 B\Y# = 250 B\Height = 150 B\Width = 20 B.Button = New Button B\Name$ = "Create XYZ Random" B\ID% = 7 B\Colors% = 1000 B\X# = 0 B\Y# = 300 B\Height = 150 B\Width = 20 B.Button = New Button B\Name$ = "Create Custom Tree" B\ID% = 8 B\Colors% = 1000 B\X# = 0 B\Y# = 350 B\Height = 150 B\Width = 20 B.Button = New Button B\Name$ = "Duplicate Custom Tree" B\ID% = 9 B\Colors% = 1000 B\X# = 0 B\Y# = 400 B\Height = 200 B\Width = 20 B.Button = New Button B\Name$ = "Exit" B\ID% = 10 B\Colors% = 100 B\X# = 0 B\Y# = 450 B\Height = 120 B\Width = 20 SkyBox("Data\Media\Sky\BlueSea") EntityRadius Camera,1 While Not KeyHit(1) If KeyHit(59) If ShowGUI% = 1 ShowGUI% = 0 ElseIf ShowGUI% = 0 ShowGUI% = 1 End If End If If KeyHit(2) If Water% = 0 Water% = Create_Water(500,0.5,-2) Else Error(400,200,"Error!","ERROR!","Water already exists!") End If End If If Water% UnderWater% = Update_Water(Water%,Camera%,-2,0.05,1) End If EntityCoord(Entity2%) If Entity2% = Camera Else While MouseDown(2) Cls UpdateWorld RenderWorld DrawImage Cursor,MouseX(),MouseY() PlayerMove Update_Objects() Flip Wend Entity2% = Camera End If If KeyHit(3) If Plane = 0 Plane = CreatePlane() Tex = LoadTexture("Data\Media\Textures\Moss.bmp") ScaleEntity Plane,20,40,20 ScaleTexture Tex,20,20 EntityTexture Plane,Tex Else Error(400,200,"Error!","ERROR!:","Plane already exists!") End If End If If KeyHit(9) Generate_Random_Entity() If KeyHit(10) For i = 1 To 250 xx = xx + 50 If xx >= 410 zz = zz + 250 xx = 0 Building = CreateCube() ScaleEntity Building,10,50,10 EntityTexture Building,LoadTexture("SkyScraper.bmp") PositionEntity Building,xx,0,zz Next End If Cls UpdateWorld RenderWorld If MouseDown(2) = False And Duplicate = 1 Duplicate = 0 End If Color 0,0,255 If ShowGUI% = 1 Text 200,0,"Your X Coordinate is - " + X# Text 200,20,"Your Y Coordinate is - " + Y# Text 200,40,"Your Z Coordinate is - " + Z# Text 200,60,"Press 1 to create water Text 200,80,"Press 2 to create a flat mossy grass plane" Text 200,100,"Press F1 to take of this text" End If PlayerMove Update_Objects Update_Buttons() PositionEntity Sky,EntityX(Camera),EntityY(Camera),EntityZ(Camera) CameraClsColor Camera,0,0,0 CameraProject Camera,X#,Y#,Z# DrawImage Cursor,MouseX(),MouseY() Flip Wend Function EntityCoord(Entity1%) X# = EntityX#(Entity1%) Y# = EntityY#(Entity1%) Z# = EntityZ#(Entity1%) End Function Function PlayerMove() If KeyDown(UpKey) MoveEntity Entity2%,0,0,10 If KeyDown(DownKey) MoveEntity Entity2%,0,0,-10 If KeyDown(LeftKey) TurnEntity Entity2%,0,2,0 If KeyDown(RightKey) TurnEntity Entity2%,0,-2,0 If KeyDown(6) MoveEntity Entity2%,0,0.2,0 If KeyDown(7) MoveEntity Entity2%,0,-0.2,0 If KeyDown(8) TurnEntity Entity2%,0.2,0,0 FlushKeys If KeyDown(9) TurnEntity Entity2%,-0.2,0,0 FlushKeys End Function Function Create_Object(Name$,Texture$,Entity%,CollisionType%,X#,Y#,Z#,Scale0#,Scale1#,Scale2#,Pitch#,Yaw#,Roll#,FX%,Fit%) O.Objc = New Objc O\Name$ = Name$ O\Texture$ = Texture$ O\Entity% = CopyEntity(Entity%) New_ID O\ID% = New_ID% O\X# = X# O\Y# = Y# O\Z# = Z# O\Scale0# = Scale0# O\Scale1# = Scale1# O\Scale2# = Scale2# O\CollisionType% = CollisionType% O\FX% = FX% O\Fit% = Fit% EntityPickMode O\Entity%,2 EntityRadius O\Entity%,2 EntityFX O\Entity%,O\FX% If O\Fit% = 1 FitMesh O\Entity%,-10,0,0,20,20,0 End If EntityType O\Entity%,O\CollisionType If Not Entity% Error(400,200,"Error!","ERROR!:","Entity Did Not Exist") Return End If If Texture$ <> "" If Texture$ <> "VoidTexture" Tex% = LoadTexture(O\Texture$,4) If Tex% = 0 Error(350,200,"ERROR!","","Texture does Not exist!") FreeEntity O\Entity% Delete O.Objc Return End If EntityTexture O\Entity%,Tex% End If End If If O\Texture$ = "" Or O\Texture$ = " " O\Texture$ = "VoidTexture" End If If Scale0# <> 0 And Scale1# <> 0 And Scale2# <> 0 ScaleEntity O\Entity%,O\Scale0#,O\Scale1#,O\Scale2# End If PositionEntity O\Entity,O\X#,O\Y#,O\Z# If Rotate% = 1 O\Rotate% = 1 EntityParent O\Entity,World RotateEntity O\Entity,Pitch#,Yaw#,Roll# End Function Function Update_Objects() For O.Objc = Each Objc O\X# = EntityX(O\Entity) O\Y# = EntityY(O\Entity) O\Z# = EntityZ(O\Entity) PositionEntity O\Entity%,O\X#,O\Y#,O\Z# Collisions CharacterCollision%,O\CollisionType%,2,2 CameraProject Camera,O\X#,O\Y#,O\Z# If EntityInView(O\Entity%,Camera) If EntityDistance#(Camera,O\Entity%) <= 5000 If Entity2% <> Camera If O\Entity% = Entity2% If KeyHit(211) If Not O\Entity% Error(400,200,"Error!","ERROR!:","Entity Did Not Exist") Exit End If FreeEntity O\Entity% Delete O.Objc FlushKeys Entity2% = Camera Exit End If End If Else If MouseDown(2) If CameraPick(Camera%,MouseX(),MouseY()) If PickedEntity() = O\Entity% ID% = O\ID% Entity2% = O\Entity End If End If End If End If End If End If Next End Function Function Load_Zone(File$) File$ = File$ + ".zdt" File1% = OpenFile(File$) If Not File1% Error(400,200,"Error!","ERROR!:","Error Loading Zone File") Return End If File2% = ReadFile(File$) While Not Eof(File2%) FileRead1$ = ReadLine(File2%) FileRead2$ = ReadLine(File2%) FileRead3$ = ReadLine(File2%) FileRead4# = ReadLine(File2%) FileRead5# = ReadLine(File2%) FileRead6# = ReadLine(File2%) FileRead7# = ReadLine(File2%) FileRead8# = ReadLine(File2%) FileRead9# = ReadLine(File2%) FileRead10% = ReadLine(File2%) FileRead11# = ReadLine(File2%) FileRead12# = ReadLine(File2%) FileRead13# = ReadLine(File2%) FileRead14% = ReadLine(File2%) FileRead15% = ReadLine(File2%) Entity% = LoadMesh(FileRead1$) If Not Entity% RuntimeError "Error Loading Object In Zone File!" HideEntity Entity% Create_Object(FileRead1$,FileRead2$,Entity%,FileRead10%,FileRead4#,FileRead5#,FileRead6#,FileRead7#,FileRead8#,FileRead9#,FileRead11#,FileRead12#,FileRead13#,FileRead14%,FileRead15%) FreeEntity Entity% Wend End Function Function Save_Zone(File$) File1% = WriteFile(File$ + ".zdt") For O.Objc = Each Objc WriteLine(File1%,O\Name$) WriteLine(File1%,O\Texture$) WriteLine(File1%,O\ID%) WriteLine(File1%,O\X#) WriteLine(File1%,O\Y#) WriteLine(File1%,O\Z#) WriteLine(File1%,O\Scale0#) WriteLine(File1%,O\Scale1#) WriteLine(File1%,O\Scale2#) WriteLine(File1%,O\CollisionType%) WriteLine(File1%,EntityPitch#(O\Entity%)) WriteLine(File1%,EntityYaw#(O\Entity%)) WriteLine(File1%,EntityRoll#(O\Entity%)) WriteLine(File1%,O\FX%) WriteLine(File1%,O\Fit%) Next End Function Function New_ID%() New_ID% = New_ID% + 1 O\ID% = New_ID% End Function Function Generate_Random_Entity() Count% = Input("How many of these do you want?") For i = 1 To Count% FlushKeys Entity% = LoadMesh(Obje$) If Not Entity% Error(400,200,"Error!","ERROR!:","Entity Did Not Exist") Return End If HideEntity Entity% Create_Object(Obje$,TexDup$,Entity%,CollisionType%,Rand(-500,500),Y#,Rand(-500,500),Scale#,Scale#,Scale#,0,0,0,FX%,Fit%) FreeEntity Entity% FlushKeys Next End Function Function Create_In_Rows() Count% = Input("How many of these do you want?") Rows% = Input("How Many Rows?") Xx# = X# Zz# = Z# For i = 1 To Count% Xx# = Xx# + 35 If Xx# >= Rows% Xx# = 0 Zz# = Zz# + 25 FlushKeys Entity% = LoadMesh(Obje$) If Not Entity% Error(350,200,"Error!","ERROR!:","Entity Did Not Exist") Exit Else HideEntity Entity% Create_Object(Obje$,"",Entity%,CollisionType%,XX#,Y#,ZZ#,Scale#,Scale#,Scale#,0,0,0,FX%,Fit%) FreeEntity Entity% FlushKeys End If Next End Function Function Update_Buttons() For B.Button = Each Button Color B\Colors%,0,0 Rect(B\X#,B\Y#,B\Height#,B\Width#) Color 0,B\Colors% + 50,0 Text B\X#,B\Y#,B\Name$ If ImageRectOverlap(Cursor,MouseX(),MouseY(),B\X#,B\Y#,B\Height#,B\Width#) B\Colors = B\Colors% + 100 Else B\Colors% = 100 If ImageRectOverlap(Cursor,MouseX(),MouseY(),B\X#,B\Y#,B\Height#,B\Width#) And MouseDown(1) = True Color 255,0,0 Select B\ID% Case 1 Cls FlushKeys Load$ = Input("What Zone To Load?") Load_Zone(Load$) FlushKeys Case 2 Cls FlushKeys Save$ = Input("What zone file would you like to Save To ?") Save_Zone(Save$) FlushKeys Case 3 Cls FlushKeys Obje$ = Input("File path of the mesh?") Scale# = Input("Mesh Scale? (This will make all 3 fields scaled) ") Tex$ = Input("Mesh Texture? (If none,or already textured,leave blank.)") CollisionType% = Input("Collision Type? (For in-game collision) ") FX% = Input("EntityFX with what parameter? (0[Default],1,2,4,8,16)") Fit% = 0 TexDup$ = Tex$ If FX% = 0 Or FX% = 1 Or FX% = 2 Or FX% = 4 Or FX% = 8 Or FX% = 16 Else FX% = 0 End If Entity% = LoadMesh(Obje$) If Not Entity% Error(350,200,"Error!","ERROR!:","Entity Did Not Exist") Return End If HideEntity Entity% Create_Object(Obje$,Tex$,Entity%,CollisionType%,X#,Y#,Z#,Scale#,Scale#,Scale#,0,0,0,FX%,Fit%) FreeEntity Entity% FlushKeys Case 4 Error(350,200,"Error!","ERROR!:","Button Not Implemented Yet!") Case 5 If MilliSecs() >= DupCounter% + DupWait% DupCounter% = MilliSecs() If Duplicate = 0 FlushKeys Entity% = LoadMesh(Obje$) If Not Entity% Error(350,200,"Error!","ERROR!:","Entity Did Not Exist") Exit Else HideEntity Entity% Create_Object(Obje$,TexDup$,Entity%,CollisionType%,X#,Y#,Z#,Scale#,Scale#,Scale#,0,0,0,FX%,Fit%) FreeEntity Entity% FlushKeys Duplicate = 1 End If End If End If Case 6 Error(350,200,"Error!","ERROR!:","Button Not Implemented Yet!") Case 7 Cls Generate_Random_Entity() Case 8 Create_Custom_Tree Case 9 If MouseDown(2) And Duplicate = 0 Trunk% = LoadMesh(Tree1$) Branch% = LoadMesh(Tree2$) Pivot = CreatePivot() PositionEntity Pivot,EntityX(Camera),EntityY(Camera),EntityZ(Camera) Create_Object(Tree1$,Tex1$,Trunk%,2,EntityX(Pivot),EntityY(Pivot),EntityZ(Pivot),Scale#,Scale#,Scale#,0,0,0,FX%,Fit%) Create_Object(Tree2$,Tex2$,Branch%,2,EntityX(Pivot),EntityY(Pivot),EntityZ(Pivot),Scale#,Scale#,Scale#,0,0,0,FX%,Fit%) FreeEntity Trunk% FreeEntity Branch% Duplicate = 1 End If Case 10 End End Select End If Next End Function Function SkyBox(File$) Sky = CreateMesh() SkyB=LoadBrush(File$ + "_ft.bmp",49) s = CreateSurface(Sky,SkyB) AddVertex S,-1,+1,-1,0,0:AddVertex s,+1,+1,-1,1,0 AddVertex S,+1,-1,-1,1,1:AddVertex s,-1,-1,-1,0,1 AddTriangle S,0,1,2:AddTriangle S,0,2,3 FreeBrush SkyB SkyB = LoadBrush(File$ + "_LF.bmp",49) s = CreateSurface( Sky,SkyB ) AddVertex s,+1,+1,-1,0,0:AddVertex s,+1,+1,+1,1,0 AddVertex s,+1,-1,+1,1,1:AddVertex s,+1,-1,-1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush SkyB SkyB = LoadBrush( File$ + "_BK.bmp",49) s = CreateSurface(Sky,SkyB) AddVertex s,+1,+1,+1,0,0:AddVertex s,-1,+1,+1,1,0 AddVertex s,-1,-1,+1,1,1:AddVertex s,+1,-1,+1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush SkyB SkyB = LoadBrush(File$ + "_RT.bmp",49) s=CreateSurface(Sky,SkyB) AddVertex s,-1,+1,+1,0,0:AddVertex s,-1,+1,-1,1,0 AddVertex s,-1,-1,-1,1,1:AddVertex s,-1,-1,+1,0,1 AddTriangle s,0,1,2:AddTriangle s,0,2,3 FreeBrush SkyB SkyB = LoadBrush(File$ + "_UP.bmp",49) s = CreateSurface( Sky,SkyB ) AddVertex s,-1,+1,+1,0,1:AddVertex s,+1,+1,+1,0,0 AddVertex s,+1,+1,-1,1,0:AddVertex s,-1,+1,-1,1,1 AddTriangle s,0,1,2 : AddTriangle s,0,2,3 FreeBrush SkyB ScaleMesh Sky,5000,5000,5000 FlipMesh Sky EntityFX Sky,9 EntityOrder Sky,10 Return Sky End Function Function Error(Height%,Width%,Title$,ErrorMessage1$,ErrorMessage2$) File% = WriteFile("Data.dat") WriteLine(File%,Height%) WriteLine(File%,Width%) WriteLine(File%,Title$) WriteLine(File%,ErrrorMessage1$) WriteLine(File%,ErrorMessage2$) CloseFile File% ExecFile "Window.exe" End Function Function Create_Custom_Tree() Cls Tree1$ = Input("What trunk do you wish to load?") Tree2$ = Input("What Branch do you wish to load?") Tex1$ = Input("What Texture do you wish to load for the Trunk?") Tex2$ = Input("What Texture do you wish to load for the Branch?") Scale# = Input("What scale do you want them to be?") Trunk% = LoadMesh(Tree1$) Branch% = LoadMesh(Tree2$) If Trunk% = 0 Or Branch% = 0 Error(350,200,"Error!","Entity did not exist.","Entity Did Not Exist") Return End If Pivot = CreatePivot() PositionEntity Pivot,X#,Y#,Z# Create_Object(Tree1$,Tex1$,Trunk%,2,EntityX(Pivot),EntityY(Pivot),EntityZ(Pivot),Scale#,Scale#,Scale#,0,0,0,FX,Fit%) Create_Object(Tree2$,Tex2$,Branch%,2,EntityX(Pivot),EntityY(Pivot),EntityZ(Pivot),Scale#,Scale#,Scale#,0,0,0,FX%,Fit%) FreeEntity Trunk% FreeEntity Branch% FreeEntity Pivot End Function Function Create_Water(TempScale#,TempShallow#,TempY#) If TempShallow# >= 1 RuntimeError "Error: Water Shallow Setting To High! (0.1-0.9)" Else If TempShallow# <= 0 RuntimeError "Error: Water Shallow Setting To Low! (0.1-0.9)" End If TempEntity% = CreatePlane() PositionEntity TempEntity%,0,TempY#,0 ScaleEntity TempEntity%,TempScale#,0.001,TempScale# EntityColor TempEntity%,0,0,255 EntityAlpha TempEntity%,TempShallow# TempEntity2% = CreatePlane() PositionEntity TempEntity2%,0,TempY#,0 ScaleEntity TempEntity2%,TempScale#,0.001,TempScale# EntityColor TempEntity2%,0,0,255 EntityAlpha TempEntity2%,TempShallow# RotateEntity TempEntity2%,0,0,180 EntityParent TempEntity2%,TempEntity% Return TempEntity% End Function Function Update_Water(TempEntity%,TempPlayer%,TempY#,TempSpeed#,Duration#) TempTime=MilliSecs()*TempSpeed# PositionEntity TempEntity%,Sin(TempTime%),TempY#+Sin(TempTime%)+Duration#,Cos(TempTime%) If EntityY(TempPlayer%) < EntityY(TempEntity%) CameraFogMode Camera,1 CameraFogColor Camera,0,0,100 CameraFogRange Camera,20,100 Gravity# = 0.05 Speed# = 0.2 TempUnderWater% = 1 Else CameraFogMode Camera,0 Speed# = 1 TempUnderWater% = 0 End If Return TempUnderWater% End Function |
| ||
Very generous to supply the source code, well indented professional looking code ;) |