Hmmmm..Guess I'm not really done yet. The loaded map is messed up.
It does only load half the map? It's like it has been cut of from upper right to lower left?
See attached pic, since I have absolutely no idea of that might be wrong. I hope you guys have any idea of what the problem might be.
EDIT - Nope, the objects just disappear as it pleases?! The walls and floor disappear but the player object doesn't. I have tried a lot of times, and the player never disappear..?
My code right now :
Editor
Rem ***** Main Source File *****
Sync On : Sync Rate 0
autocam off
`Makes the map area
Make matrix 1, 70, 70, 35, 35
Position Matrix 1, -35,0,-35
`Makes the Cursor
Make Object box 1, 1.5, 2, 1.5
Position Object 1, 0, 1, 0
Color Object 1, RGB (255, 0, 0)
`Orients the camera
Position Camera 0, 70, 0
Point Camera 0, 0, 0
rem Set the image to use to #1.
NextTexture = 1
`Variables
WallFlag as boolean
PillarFlag as boolean
FloorFlag as boolean
CeilingFlag as boolean
DeleteFlag as boolean
PlayerFlag as boolean
UpFlag as boolean
DownFlag as boolean
LeftFlag as boolean
RightFlag as boolean
`Arrays
dim AllObjects#(2000,6)
remstart
1: X pos
2: Y pos
3: Z pos
4: Object number
5: Object type
#1: wall
#2: floor
#3: ceiling
#4: pillar
#5: Enemy
#6: Ammo
#7: PlayerStart
6: Texture
remend
ObjectSlot=0
`-----------------------------------------------------------------
`--------------------------The main loop--------------------------
`-----------------------------------------------------------------
DO
gosub controls
gosub info
sync
LOOP
`-----------------------------------------------------------------
`--------------------------The controls---------------------------
`-----------------------------------------------------------------
controls:
`Moves the cursor
`Up
if upkey()=1 and UpFlag = 0
UpFlag = 1
Move Object 1, 2
endif
if upkey()=0 then UpFlag = 0
`Down
if downkey()=1 and DownFlag = 0
DownFlag = 1
Move Object 1, -2
endif
if downkey()=0 then DownFlag = 0
`Right
if rightkey()=1 and RightFlag = 0
RightFlag= 1
move object right 1, 2
endif
if rightkey()=0 then RightFlag = 0
`Left
if leftkey()=1 and LeftFlag = 0
LeftFlag = 1
move object left 1, 2
endif
if leftkey()=0 then LeftFlag = 0
`Make wall when W-key is pressed
if Keystate(17)=1 and WallFlag = 0
WallFlag = 1
s = 0
repeat
inc s,1
until AllObjects#(s,4)= 0
ObjectSlot=s
o=0
Repeat
inc o,1
until object exist(o)=0
make object cube o, 2
Position Object o, Object Position X(1), Object Position Y(1), Object Position Z(1)
Texture Object o, NextTexture
AllObjects#(ObjectSlot,1)=Object Position X(o) `store X pos
AllObjects#(ObjectSlot,2)=Object Position Y(o) `Store Y pos
AllObjects#(ObjectSlot,3)=Object Position Z(o) `Store Z pos
AllObjects#(ObjectSlot,4)=o `Store Object num
AllObjects#(ObjectSlot,5)=1 `Store object Type, In this case a wall, see top-
AllObjects#(ObjectSlot,6)=NewTexture
endif
if Keystate(17)=0 then WallFlag = 0
`Makes pillar, yay!
if Keystate(44)=1 and PillarFlag = 0
PillarFlag = 1
s = 0
repeat
inc s,1
until AllObjects#(s,4) = 0
ObjectSlot=s
o=0
repeat
inc o,1
until object exist(o)=0
Make Object box o, 0.5, 2, 0.5
Position Object o, Object Position X(1), Object Position Y(1), Object Position Z(1)
Texture Object o, NextTexture
AllObjects#(ObjectSlot,1)=Object Position X(o) `store X pos
AllObjects#(ObjectSlot,2)=Object Position Y(o) `Store Y pos
AllObjects#(ObjectSlot,3)=Object Position Z(o) `Store Z pos
AllObjects#(ObjectSlot,4)=o `Store Object num
AllObjects#(ObjectSlot,5)=4 `Store object Type, in this case a pillar, see top-
AllObjects#(ObjectSlot,6)=NewTexture
endif
if keystate(44)=0 then PillarFlag = 0
`Make Floor when F-key is pressed
if Keystate(33)=1 and FloorFlag = 0
FloorFlag = 1
s = 0
repeat
inc s,1
until AllObjects#(s,4) = 0
ObjectSlot=s
o=0
repeat
inc o,1
until object exist(o)=0
Make Object box o, 2, 0.1, 2
Position Object o, Object Position X(1), Object Position Y(1)-1, Object Position Z(1)
Texture Object o, NextTexture
AllObjects#(ObjectSlot,1)=Object Position X(o) `store X pos
AllObjects#(ObjectSlot,2)=Object Position Y(o) `Store Y pos
AllObjects#(ObjectSlot,3)=Object Position Z(o) `Store Z pos
AllObjects#(ObjectSlot,4)=o `Store Object num
AllObjects#(ObjectSlot,5)=2 `Store object Type, in this case a pillar, see top-
AllObjects#(ObjectSlot,6)=NewTexture
endif
if keystate(33)=0 then FloorFlag = 0
`Makes Ceiling when C-key is pressed
if keystate(46)=1 and CeilingFlag = 0
CeilingFlag = 1
s = 0
repeat
inc s,1
until AllObjects#(s,4) = 0
ObjectSlot=s
o=0
repeat
inc o,1
until object exist(o)=0
make object box o, 2, 0.1, 2
position object o, Object Position X(1), Object Position Y(1)+1, Object Position Z(1)
texture object o, NextTexture
ghost object on o
AllObjects#(ObjectSlot,1)=Object Position X(o) `store X pos
AllObjects#(ObjectSlot,2)=Object Position Y(o) `Store Y pos
AllObjects#(ObjectSlot,3)=Object Position Z(o) `Store Z pos
AllObjects#(ObjectSlot,4)=o `Store Object num
AllObjects#(ObjectSlot,5)=3 `Store object Type, in this case a pillar, see top-
AllObjects#(ObjectSlot,6)=NewTexture
endif
if keystate(46)=0 then CeilingFlag = 0
`Makes Player!
if keystate(25)=1 and PlayerFlag = 0
PlayerFlag = 1
s = 0
repeat
inc s, 1
until AllObjects#(s,4) = 0
ObjectSlot=s
o=0
repeat
inc o,1
until object exist (o)=0
make object sphere o, 1
position object o, Object Position X(1), Object Position Y(1), Object Position Z(1)
color object o, RGB(0,255,0)
AllObjects#(ObjectSlot,1)=Object position X(o)
AllObjects#(ObjectSlot,2)=Object position Y(o)
AllObjects#(ObjectSlot,3)=Object position Z(o)
AllObjects#(ObjectSlot,4)=o
AllObjects#(ObjectSlot,5)=7
endif
if keystate(25)=0 then PlayerFlag = 0
Elapsed# = Timer() - OldTime
OldTime = Timer()
`Camera Zoom
if Keystate(74) then Move Camera -Elapsed#*.04
if Keystate(78) then Move Camera Elapsed#*.04
`Camera Movement
if Keystate(72) then Position Camera Camera Position X(), Camera Position Y(), Camera Position Z()+Elapsed#*.01
if Keystate(80) then Position Camera Camera Position X(), Camera Position Y(), Camera Position Z()-Elapsed#*.01
if Keystate(75) then Position Camera Camera Position X()-Elapsed#*.01, Camera Position Y(), Camera Position Z()
if Keystate(77) then Position Camera Camera Position X()+Elapsed#*.01, Camera Position Y(), Camera Position Z()
`Pitch camera
if Keystate(79) then Pitch Camera Down Elapsed#*.04
if Keystate(81) then Pitch Camera Up Elapsed#*.04
`Rotate camera
if keystate(71) then turn camera left Elapsed#*.04
if keystate(73) then turn camera right Elapsed#*.04
`Loads a Texture
if Keystate(20)
REM ME BEING CAUTIOUS ABOUT THE FILE DIRECTORY :P. Feel free to remove the two lines surrounding your OpenFile command.
rem Get the program's base directory before the file command, and reset it after.
TextureDirectory$=get dir$()
FilePath$ = OpenFileBox("DataTextures","Load a texture","Load a texture (*.jpg, *..bmp, *..png)|*.jpg;*.bmp;*.png|Load All (*.*)|*.*")
set dir TextureDirectory$
rem if the user didn't press cancel (in which case the file wouldn't exist) then load the image into a NEW number.
if file exist(FilePath$)
inc NextTexture,1
load image FilePath$,NextTexture
endif
endif
`Deletes entity
Collide = Object collision(1,0)
if Collide>0
if spacekey()=1 and DeleteFlag = 0
DeleteFlag = 1
Delete Object Collide
endif
endif
if spacekey()=0 then DeleteFlag = 0
`Saves the level
if keystate(63)=1
If file exist("MAP.stu") then delete file "MAP.stu"
save array "MAP.stu", AllObjects#(1000)
endif
return
`-----------------------------------------------------------------
`----------------------------Infotext-----------------------------
`-----------------------------------------------------------------
info:
text 1, 1, "Controlls: "
text 1, 15, "Arrowkeys - Move cursor arround."
text 1, 30, "W - Place Wall. F - Place Floor."
text 1, 45, "+ & - keys - Zoom in and out."
text 1, 60, "8,4,6,2 numpads - Move camera around."
text 1, 75, "1,3 numpads - Pitch camera up and down."
text 1, 90, "T - Change Texture."
return
Loading Levels
sync on
sync rate 33
make camera 1
position camera 1, 0,2,0
point camera 1, 0,0,0
DIM AllObjects#(2000,6)
do
rem ====================================================================================
rem
rem LOADING THE "LEVEL"
rem
rem ====================================================================================
if inkey$()="l"
rem ONLY LOAD if you've saved before!
if file exist("MAP.stu")
rem First, we'll delete all of our objects.
For o = 1 to 1000
rem If there's an object using this "dresser"/slot then delete it!
if AllObjects#(o,4)>0
Delete Object AllObjects#(o,4)
Endif
next o
rem Now... load the array
Load Array "MAP.stu",AllObjects#(2000)
rem go through each "dresser"/object slot and do the following...
for o = 1 to 1000
rem If an object existed in that "dresser"/object slot, then re-create it.
if AllObjects#(o,4)>0
rem Find the new object number. The reason why I don't just use the one
rem that was saved is because that object may or may not already be in use in your game.
rem It's safer to just get a new object number. This way you avoid the "object already exists" error.
obj=0
repeat
inc obj,1
until object exist(obj)=0
rem If saved object was a cube, then make a cube.
if AllObjects#(o,5)=1
Make Object cube obj,2
rem Set this "dresser"/object slot's object number equal to that of the cube.
AllObjects#(o,4)=obj
rem Position the object at its saved coordinates.
Position Object obj,AllObjects#(o,1),AllObjects#(o,2),AllObjects#(o,3)
Endif
rem If the saved object was a cone, then make a cone.
if AllObjects#(o,5)=2
Make Object box obj, 2, 0.1, 2
rem Set this "dresser"/object slot's object number equal to that of the cone.
AllObjects#(o,4)=obj
rem Position the object at its saved coordinates.
Position Object obj,AllObjects#(o,1),AllObjects#(o,2),AllObjects#(o,3)
Endif
rem If the saved object was a sphere, then make a sphere.
if AllObjects#(o,5)=3
Make Object box obj,2, 0.1,2
rem Set this "dresser"/object slot's object number equal to that of the sphere.
AllObjects#(o,4)=obj
rem Position the object at its saved coordinates.
Position Object obj,AllObjects#(o,1),AllObjects#(o,2),AllObjects#(o,3)
Endif
if AllObjects#(o,5)=7
make object sphere obj, 2
AllObjects#(o,4)=obj
position object obj, AllObjects#(o,1), AllObjects#(o,2), AllObjects#(o,3)
position camera object position x(o), object position Y(o), object position Z(o)
endif
Endif
next o
rem Print some text saying the level was loaded
wait 200
Center Text Screen Width()/2,Screen Height()/2,"Your level was loaded!"
Sync
Wait Key
Else
rem Print some text saying the file didn't exist!
Center Text Screen Width()/2,Screen Height()/2,"You haven't saved a level yet"
Sync
Wait Key
Endif
Endif
control camera using arrowkeys 1,1,1
sync
loop