|
Post by Wayne Rayner on Sept 16, 2010 19:37:07 GMT -5
Ok so basically I have this code it works perfectly fine for goin up, down, left and right. As soon as you have a combination of 2 it has a very random effect as I have rotation. The thing that might make it easier is a only want the movement to be left, right, up and down and if they are clicking a combination it makes it so that it only is going one direction and not diagonally.
code
player = NewSprite (Tex(1)) SprSetSize(32,32)
while true SprSetPos(posX,PosY) if ScanKeyDown(VK_UP) then PosY = PosY - 5 SprSetAngle(0) endif if ScanKeyDown(VK_DOWN) then PosY = PosY + 5 SprSetAngle(180) endif if ScanKeyDown(VK_LEFT) then PosX = PosX - 5 SprSetAngle(270) endif if ScanKeyDown(VK_RIGHT) then PosX = PosX + 5 SprSetAngle(90) endif animatesprites() wend
if you understand what I'm trying to say can you please help me if you can.
regards Wayne Rayner
|
|
|
Post by DJLinux on Sept 16, 2010 21:57:02 GMT -5
dim PosX,PosY dim player = NewSprite(1)
SprSetSize(32,32)
while true SprSetPos(posX,PosY) if ScanKeyDown(VK_UP) then PosY = PosY - 5 SprSetAngle(0) elseif ScanKeyDown(VK_DOWN) then PosY = PosY + 5 SprSetAngle(180) elseif ScanKeyDown(VK_LEFT) then PosX = PosX - 5 SprSetAngle(270) elseif ScanKeyDown(VK_RIGHT) then PosX = PosX + 5 SprSetAngle(90) endif animatesprites() wend
|
|
|
Post by Wayne Rayner on Sept 20, 2010 7:00:02 GMT -5
well I didn't quite explain myself. it works perfectly well at least in the engine as a copy and pasted the code from the movement section. It only happens that the variables are all loaded in the main section, so the variables isn't what I meant. I only want four way movement. As in left, right, up, down. If you press say 'both up and left' in it's current state it would do something retarted with the angles, so therefore if you pressed the up and down it would make it so that a key over rules and makes it go only up. I hope I'm getting this explaianed properly The engine is avliable below basic4gl.proboards.com/index.cgi?board=demo&action=display&thread=3311regards Wayne Rayner
|
|
|
Post by shadow008 on Sept 21, 2010 13:37:09 GMT -5
*sigh*
Such a simple solution:
Instead of using: if...then.....endif Use: if...then...ELSEIF
That way the first button will take priority over the second which will take priority over the third, ect.
This post just explains DJLinux's post, cuz hes got the right idea (But he didnt explain it XD)
|
|
|
Post by Wayne Rayner on Sept 25, 2010 4:36:52 GMT -5
DJLinux - I am very sorry for not looking at the code you gave properly.
Thanks for explaining the post that DJLinux posted it helps me a lot, and I'm sorry I had to make you explain because of my negligence.
regards Wayne Rayner
|
|