I also saw that little extra endif, edited it out... just a little typo feel silly if I mention those small things...
However, I have quite a working "snap to grid" system now... except one thing...
It looks good from one angle but i decided i wanted to see the scene from another angle so i changed the camera func. The reason is another bug ive found
, but i want to solve this out first.
If youre willing to help me again
hehe, try in the main loop to pass the argument 2 to the update_cam func. I have camvariants 1 and 2.
Also Ive added and edited a small amount of stuff that bothered me. Among those that the goal_z never was an equal ten (sorry if im saying it wrong, i dont know how to say it... the number cant be divided by ten whitout getting fractions) it was aldways 5 added to it. Thats fixed.
Anyways, heres the code as mine is now: (its a new project in case i want something back from the old one, the backup
)
Rem Project: subtanks
Rem Created: 2004-06-05 21:29:49
Rem ***** Main Source File *****
rem setup
set display mode 1024, 768, 32
sync on
sync rate 60
rem variables
max_players = 2
dim goal_x(max_players)
dim goal_z(max_players)
dim direction(max_players)
dim moving(max_players)
dim speed(max_players)
rem LOAD
load_level()
DO
player_input(1)
update_cam(1)
print_status()
SYNC
LOOP
function load_level()
REM --- PLAYER INIT ---
rem make temp player char
make object box 1, 9, 9, 9
position object 1, 20, 5, 20
color object 1, rgb(0,60,80)
direction(1) = 0
moving(1) = 0
speed(1) = 1
goal_z(1) = object position z(1)
goal_x(1) = object position x(1)
REM --- PLAYER INIT END ---
REM WORLD VARIABLES
rem 1 will be added so its the same thing as 20
block=19
worldwidth = 200
worldheight = 200
REM WORLD VARIABLES END
REM MAKE LIGHT AND STUFF
remstart
rem make reference point
make object sphere 10, 5
position object 10, worldwidth/2+5, 10, worldheight/2
rem make light
make light 9
position light 9, worldwidth/2+5, 10, worldheight/2
remend
REM LIGHT AND STUFF END
rem make world, matrix
make matrix 1, worldwidth, worldheight, worldwidth/10, worldheight/10
position matrix 1, 5, -5, 0
remstart
load image "textures/ground.bmp",1
prepare matrix texture 1,1,1,1
fill matrix 1,0,1
remend
update matrix 1
for mazey = 1 to worldheight/10
for mazex = 1 to worldwidth/10
read maze
rem if a block was found
if maze = 1
inc block
make object box block, 10, 10, 10
color object block, rgb(40,15,15)
position object block, mazex*10, groundheight, mazey*10-5
endif
next mazex
next mazey
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
endfunction
function player_input(object)
remstart check player input
up - 1
right - 2
down - 3
left - 4
remend
if moving(object)=0
if upkey()=1 then direction(object)=1
if rightkey()=1 then direction(object)=2
if downkey()=1 then direction(object)=3
if leftkey()=1 then direction(object)=4
rem if direction(object) > 0 then moving(object)=1
endif
rem BIG CHANGE here, moved the part when setting moving(object) to 1 up to
rem where it decides direction from input and only calls the move function
rem if the cube is moving (i.e. moving(object)=1). The reason is that the cube wont move,
rem i added the print status / debugging thing and found out that moving(1) is always 1,
rem so the game wont take input... it only does so if the moving(object)=0.
rem
rem I did solve that by setting the an if statment to only make moving(object) to 1
rem if direction is greater than 0. See that?
rem
rem The main problem now is that the cube wont move :( still... i dont know what i am
rem doing wrong :P. The print status claims that both direction and moving are changed
rem accordingly if an arrowkey is pressed. No idea what could be wrong...
rem if moving(object)=1 then
move(object)
endfunction
function move(object)
rem if object isnt moving, set its status to moving and set distance
if moving(object)=0
if direction(object)=1 then goal_z(object)=object position z(object) + 10
if direction(object)=2 then goal_x(object)=object position x(object) + 10
if direction(object)=3 then goal_z(object)=object position z(object) - 10
if direction(object)=4 then goal_x(object)=object position x(object) - 10
moving(object)=1
endif
rem if its moving....
if moving(object)=1
rem up
if goal_z(object) > object position z(object)
position object object, object position x(object), 5, object position z(object) + speed(object)
endif
rem right
if goal_x(object) > object position x(object)
position object object, object position x(object) + speed(object), 5, object position z(object)
endif
rem down
if goal_z(object) < object position z(object)
position object object, object position x(object), 5, object position z(object) - speed(object)
endif
rem left
if goal_x(object) < object position x(object)
position object object, object position x(object) - speed(object), 5, object position z(object)
endif
rem if its at its destination
rem
rem Here I think something needs to be changed... Just a feeling :P
rem
rem Anyways, i think the error is somewhere in this function. Because the debugging
rem function shows that both direction and movement flags are updated when a key is pressed
rem but the goal_x and goal_z remains the same... why?
if (object position z(object)=goal_z(object)) and (object position x(object)=goal_x(object))
moving(object)=0
direction(object)=0
endif
endfunction
function update_cam(camvariant)
camdistance = 50
rem place camera
if camvariant=1
position camera object position x(1), object position y(1)+camdistance, object position z(1)-camdistance
point camera object position x(1), object position y(1), object position z(1)
endif
rem place camera, variant 2
if camvariant=2
position camera 105, 30, 100
point camera object position x(1), object position y(1), object position z(1)
endif
endfunction
function print_status()
set cursor 0,0
print "direction: ";direction(1)
print "moving: ";moving(1)
print "speed: ";speed(1)
print "goal_z";goal_z(1)
print "goal_x";goal_x(1)
endfunction
Cheers
Mizipzor
Dreaming of creating a highly advanced AI mind