|
Post by aKa on Jun 12, 2004 2:55:34 GMT -5
I just started coding in Basic4GL. I'm quite a beginner, see. I whipped up code that ran in my mind and this is the result. It's supposed to make you move the 0 around. Can you help me?
The code:
Struc General Dim x, y, MaxX, MaxY EndStruc Dim General p1 Dim Start
p1.x = 20: p1.y = 12.5: p1.MaxX = 40: p1.MaxY = 25 Print "0" Start = 1 Locate 20, 12.5
While Start = 1 If ScanKeyDown(VK_UP) Then If p1.y < p1.MaxY Then Locate p1.x, p1.y - 1 CLS: Print "0" Endif Endif If ScanKeyDown(VK_LEFT) Then If p1.x < p1.MaxX Then Locate p1.x - 1, p1.y CLS: Print "0" Endif Endif If ScanKeyDown(VK_RIGHT) Then If p1.x < p1.MaxX Then Locate p1.x + 1, p1.y CLS: Print "0" Endif Endif If ScanKeyDown(VK_DOWN) Then If p1.y < p1.MaxY Then Locate p1.x, p1.y + 1 CLS: Print "0" Endif Endif Wend
|
|
|
Post by NovaGene on Jun 12, 2004 6:31:54 GMT -5
Try removing all the CLS commands and have only 1 CLS just below the "While Start = 1" statement. If your idea is to move it continuously till it reaches the boundary, do something like this:- p1.y=p1.y - 1 Locate p1.x, p1.y Print "0" And not, Locate p1.x, p1.y-1 Print "0" Do it for the other axis as well. You shld use the more elegant "While true" instead of "While Start = 1". Take a look at the snakedemo.gb. You can acquire tips on how to avoid the flickering, delay timer, etc. Have fun! - Lucas Tan -
|
|
|
Post by AHBanen on Jun 12, 2004 6:39:43 GMT -5
You made two fundamental errors: 1) putting CLS after Locate 2) not updating the p1.x and p1.y location values - you only varied them +1 / -1 from their starting position when you used Locate.
I've corrected these and also made several code changes to make your code more practical and provided better conditions when your character would otherwise become located outside the boundaries set (0..p1.MaxX and 0..p1.MaxY). I hope you find tehresult still understandable...
Struc General Dim x, y, MaxX, MaxY EndStruc
Dim General p1 Dim Start Dim Step Dim update Dim Character$
p1.x = 20: p1.y = 12: p1.MaxX = 40: p1.MaxY = 25 Character$ = "0" Step = 1 Locate p1.x, p1.y Print Character$ Start = true While Start If ScanKeyDown(VK_UP) Then If p1.y > 0 and p1.y <= p1.MaxY Then update = true p1.y = p1.y - Step Endif Endif
If ScanKeyDown(VK_LEFT) Then If p1.x > 0 and p1.x <= p1.MaxX Then update = true p1.x = p1.x - Step Endif Endif
If ScanKeyDown(VK_RIGHT) Then If p1.x >= 0 and p1.x < p1.MaxX Then update = true p1.x = p1.x + Step Endif Endif
If ScanKeyDown(VK_DOWN) Then If p1.y >= 0 and p1.y < p1.MaxY Then update = true p1.y = p1.y + Step Endif Endif
if update Then CLS: Locate p1.x, p1.y Print Character$ update = false Endif
Wend
Have fun programming in Basic4GL!
André
|
|