sync on : sync rate 1 : set display mode desktop width(), desktop height(), 32
Global targetX AS INTEGER
Global targetY AS INTEGER
Global diffX AS INTEGER
Global diffY AS INTEGER
Global newX AS INTEGER
Global newY AS INTEGER
Global plr AS THEPLAYER
Global q#
Global qq#
type THEPLAYER
x AS INTEGER
y AS INTEGER
targetX AS INTEGER
targetY AS INTEGER
diffX AS INTEGER
diffY AS INTEGER
newX AS INTEGER
newY AS INTEGER
endtype
make object cube 1, 25
position camera 0, 500, 0
point camera 0,0,0
plr.y = 0.0
plr.x = 0.0
do
while upkey()=1 : endwhile
movementkeys()
plrmove()
handleUI()
sync
loop
function movementkeys()
plr.targetX = 0.0
plr.targetY = 0.0
if keystate(17)=1
if keystate(31)=1
plr.targetY = 0.0
else
plr.targetY = 1.0
endif
endif
if keystate(31)=1
if keystate(17)=1
plr.targetY = 0.0
else
plr.targetY = -1.0
endif
endif
if keystate(30)=1
if keystate(32)=1
plr.targetX = 0.0
else
plr.targetX = -1.0
endif
endif
if keystate(32)=1
if keystate(30)=1
plr.targetX = 0.0
else
plr.targetX = 1.0
endif
endif
endfunction
function plrmove()
plr.diffX = (plr.targetX - plr.x)
plr.diffY = (plr.targetY - plr.y)
if plr.diffX > 0
q# = (plr.x + (0.1 * cos(atan(plr.diffY/plr.diffX))))
qq# = (plr.y + (0.1 * sin(atan(plr.diffY/plr.diffX))))
endif
endfunction
function handleUI()
text 0,0,"Target X: " + str$(plr.targetX)
text 0,25,"Target Y: " + str$(plr.targetY)
text 0,50,"X: " + str$(plr.x)
text 0,75,"Y: " + str$(plr.y)
text 0,100,"newX: " + str$(q#)
text 0,125,"newY: " + str$(qq#)
text 0,150,"diffX: " + str$(plr.diffX)
text 0,175,"diffY: " + str$(plr.diffY)
endfunction
^ #Notes: While loops so I can pause loop with upkey, I know it will divide by 0 if only the W key is pressed; press D before W for a full test.
When you press the D then the W key, my function works as intended and gives value via the code above. But if
q# = (plr.x + (0.1 * cos(atan(plr.diffY/plr.diffX))))
is changed to
plr.newX = (plr.x + (0.1 * cos(atan(plr.diffY/plr.diffX))))
, the value is NOT saved to that type. I do not seem to see why, as my other types in the same function saves just fine. Is this user error or a nasty bug? Because it's really annoying.
Ventures of the worlds around us are only limited by imagination.