Ok.
I take it the THEN keyword is not needed in an if statement? What is it for then? The manual says to make sure the lines after the THEN statement are seperated by a :, implying that I am supposed to follow every if with a then. But then again, the manual is often useless with it's syntax examples, and the example code provided is too confusing to new people since it contains a bunch of stuff needed to run a demo instead of a simple example of a possible use of the command. Either that or I'm just missing something somewhere.
Now I get an error on the very last line, the LOOP command.
I'll post all my code in the main do loop. It's long, but I guess it can't be helped.
remstart
//MAIN LOOP STARTS HERE
//START MAIN LOOP
remend
DO
//pointless spinning of happy to show that program is still working
Yrotate object 1,object angle y(1)+0.1
//a wait to slow the program down a bit in the quick and dirty fashion for now
//wait 5
remstart
//CAMERA CONTROLS --FOR TESTING ONLY!!!---
//allow camera controls to update
control camera using arrowkeys 0,1,1
//further control over camera Y position
if controlkey()
position camera camera position x(),camera position y()-1,camera position z()
endif
if shiftkey()
position camera camera position x(),camera position y()+1,camera position z()
endif
remend
//test make camera follow happy
//Really cruddy way of doing it, but it works
position camera object position x(1)+300,object position y(1)+500,object position z(1)
point camera object position x(1),object position y(1),object position z(1)
remstart
This is an attempt to make happy controllable.
It shall be crappy! Woot!
Remend
//move up if up is pressed
if upkey()
position object 1,object position x(1)-1,object position y(1),object position z(1)
endif
//check for a collision
if object collision(2,1)
position object 1,object position x(1)+1,object position y(1),object position z(1)
endif
//move down if down is pressed
if downkey()
position object 1,object position x(1)+1,object position y(1),object position z(1)
endif
//once again, check if down caused a collision
if object collision(2,1)
position object 1,object position x(1)-1,object position y(1),object position z(1)
endif
//move left if left is pressed
if leftkey()
position object 1,object position x(1),object position y(1),object position z(1)-1
endif
//check for collision with leftkey
if object collision(2,1)
position object 1,object position x(1),object position y(1),object position z(1)+1
endif
//move right if right key is pressed
if rightkey()
position object 1,object position x(1),object position y(1),object position z(1)+1
endif
//check if moving right caused a collision
if object collision(2,1)
position object 1,object position x(1),object position y(1),object position z(1)-1
endif
rem end of happy's movement along the x and z using the arrow keys.
remstart
Really dirty gravity code
version 1.0
rem While loop to check if the object hit the ground.
while object collision(2,1)=0
position object 1,object position x(1),object position y(1)-1,object position z(1)
endwhile
rem Move the object up 1 so that it's flush with the ground instead of inside it.
position object 1,object position x(1),object position y(1)+1,object position z(1)
remend
Remstart
NEW gravity code that uses a variable to move him
remend
rem First add the current Gravity rate to his speed. This simulates the pull of gravity.
Inc happySpeedY#,Gravity#
rem Gravity doesn't let him fall more then a certain speed, so if his speed is greater then his mass should allow, set it back to his max fall speed.
if happySpeedY>happyMass
happySpeedY=happyMass
endif
rem Before moving him, let's set a couple of flags so we know if he hits the roof or floor while moving.
hitFloor=0
hitRoof=0
//we need to check if the y movement is positive or negative to set up the for loop to move him without infinitly counting loops.
if happySpeedY>0
rem If it's positive, we can repeatedly move happy till we've moved him as much as happySpeedY says to move him this loop.
for fallv=0 to happySpeedY step 1
if object collision(2,1)=0
position object 1,object position x(1),object position y(1)-1,object position z(1)
endif
rem If he hits a floor, set a flag, move him out of the floor.
if object collision(2,1)=1
hitFloor=1
position object 1,object position x(1),object position y(1)+1,object position z(1)
endif
next fallv
Rem If it was not positive, it must be negative or 0. If it was negative, or below 0, then we can do the same operation, except this time we move him down for each negative count.
else
if happySpeedY<0
for fallv=0 to happySpeedY step -1
if object collision(2,1)=0
position object 1,object position x(1),object position y(1)+1,object position z(1)
endif
rem If he hits a Roof, set a flag, move him out of the Roof.
if object collision(2,1)=1
hitRoof=1
position object 1,object position x(1),object position y(1)-1,object position z(1)
endif
next fallv
endif
rem Now we need to check and reverse his y speed based on if he hit anything while moving.
if hitRoof=1 or hitFloor=1
happySpeedY=0-happySpeedY
endif
LOOP
The last line is marked as an error, even though I think it should line up with the DO at the top of the loop, right?
I'm still a bit confused how DB handles embedded loops. The documentation unfortunetly doesn't seem to say anything about it either. What determines which "close this loop" command is attached to which "start this loop" command?
Again, thanks for your time, and for helping this new goofball of a DB coder learn a thing or two.