Boolean Parameter
Author |
Message |
Mr. T
![](http://www.madpaintballer.com/images/purepwnage.gif)
|
Posted: Mon Jun 12, 2006 11:07 pm Post subject: Boolean Parameter |
|
|
I tried setting up a boolean parameter in the hopes that I could make the box continue by itself in the direction pressed, but to no avail. I understand where the problem lies...in the fact that the boolean is only true the instant the key is down...but I can't think of any solutions. I know could fix the problem by eliminating the procedure move, but I want to keep it in. So any ideas how I can solve my problem?
code: | View.Set ("offscreenonly")
var a, b : int := 0
proc ball (x, y : int)
drawfillbox (x, y, x + 10, y + 10, red)
end ball
procedure move (move1, move2, move3, move4 : boolean)
if move1 = true then
%a = 0
b += 10
elsif move2 = true then
a += 10
%b = 0
elsif move3 = true then
a -= 10
%b = 0
elsif move4 = true then
%a = 0
b -= 10
end if
end move
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
move (true, false, false, false)
end if
if chars (KEY_RIGHT_ARROW) then
move (false, true, false, false)
end if
if chars (KEY_LEFT_ARROW) then
move (false, false, true, false)
end if
if chars (KEY_DOWN_ARROW) then
move (false, false, false, true)
end if
ball (a, b)
View.Update
delay (50)
cls
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
NikG
|
Posted: Tue Jun 13, 2006 12:18 am Post subject: (No subject) |
|
|
Well, the move proc seems really pointless... but if you insist on keeping it, you can add a string variable called direction or whatever. Have the value of it change when there's a key press.
Meanwhile, just insert another if statement above your ball proc and pass your booleans to move based on the value of direction (although the better solution is to just get rid of move and use that new if statement above ball to change the a/b values). |
|
|
|
|
![](images/spacer.gif) |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Tue Jun 13, 2006 6:13 am Post subject: (No subject) |
|
|
code: |
move(chars(KEY_UP_ARROW),chars(KEY_RIGHT_ARROW),chars(KEY_LEFT_ARROW),chars(KEY_DOWN_ARROW))
|
The handy thing about Input.KeyDown is it is an array char of boolean. if you noticed, in your if statements, your actually checking to see if that specific char is true, so why not directly call move with chars? Also, You shouldn't use global variables. Pass the ball's co-ordinates (I'm going to assume "a" and "b") as variable parameters. |
|
|
|
|
![](images/spacer.gif) |
TheOneTrueGod
![](http://www.drmcninja.com/images/mcninjab3.jpg)
|
Posted: Tue Jun 13, 2006 6:15 am Post subject: (No subject) |
|
|
Sorry for the double post, but I remembered something else that I should mention. Doing it this way (in a procedure) is actually better, because it makes it so you don't have to hard code the movement values as much, and so you can have two balls being controlled by separate keys, but with one procedure (assuming you pass the co-ordinates as variables).
This also makes things like getting user opted controls fairly easier. |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Tue Jun 13, 2006 9:00 am Post subject: (No subject) |
|
|
Well in a comment a little more related to your problem, if you want to have the ball continuously travelling in a specific direction, then set yourself up some vector maths. You could create a ball type:
code: |
type ball :
record
x, y : int
dX, dY : int
end record
|
And in your movement proc, set the values of (dX, dY) to whatever you need. During your draw_ball proc, you'd add dX to x and dY to y, creating the necassary movement. |
|
|
|
|
![](images/spacer.gif) |
Mr. T
![](http://www.madpaintballer.com/images/purepwnage.gif)
|
Posted: Tue Jun 13, 2006 12:16 pm Post subject: Alex's Opinion |
|
|
TheOneTrueGod wrote: code: |
move(chars(KEY_UP_ARROW),chars(KEY_RIGHT_ARROW),chars(KEY_LEFT_ARROW),chars(KEY_DOWN_ARROW))
|
The handy thing about Input.KeyDown is it is an array char of boolean. if you noticed, in your if statements, your actually checking to see if that specific char is true, so why not directly call move with chars? Also, You shouldn't use global variables. Pass the ball's co-ordinates (I'm going to assume "a" and "b") as variable parameters.
Here's my new code. I've been unable to implement both your suggestions. Can you show me how I might be able to both because I would like to eliminate the number of boolean vars, and I would like to eliminate as many global vars as possible.
code: | View.Set ("offscreenonly")
var a, b : array 1 .. 10 of int
for i : 1 .. 10
a (i) := maxx div 2
b (i) := maxy div 2
end for
var moveBoolean1, moveBoolean2, moveBoolean3, moveBoolean4 : boolean := false
proc ball (x, y : array 1 .. 10 of int)
for i : 1 .. 10
drawfillbox (x (i), y (1), x (i) + 10, y (i) + 10, red)
end for
end ball
procedure move (move1, move2, move3, move4 : boolean)
for i : 1 .. 10
if move1 = true then
%a (i) = 0
b (i) += 10
elsif move2 = true then
a (i) += 10
%b (i) = 0
elsif move3 = true then
a (i) -= 10
%b (i) = 0
elsif move4 = true then
%a (i) = 0
b (i) -= 10
end if
end for
end move
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
moveBoolean1 := true
moveBoolean2 := false
moveBoolean3 := false
moveBoolean4 := false
end if
if chars (KEY_RIGHT_ARROW) then
moveBoolean1 := false
moveBoolean2 := true
moveBoolean3 := false
moveBoolean4 := false
end if
if chars (KEY_LEFT_ARROW) then
moveBoolean1 := false
moveBoolean2 := false
moveBoolean3 := true
moveBoolean4 := false
end if
if chars (KEY_DOWN_ARROW) then
moveBoolean1 := false
moveBoolean2 := false
moveBoolean3 := false
moveBoolean4 := true
end if
move (moveBoolean1, moveBoolean2, moveBoolean3, moveBoolean4)
ball (a, b)
View.Update
delay (50)
cls
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Tue Jun 13, 2006 4:45 pm Post subject: (No subject) |
|
|
just eliminate all of the boolean values being set to whatever and go with TOTG's idea, after your Input.Key down just do this
code: |
loop
Input.KeyDown(chars)
move (chars(KEY_UP_ARROW),chars(KEY_DOWN_ARROW),chars(KEY_LEFT_ARROW),chars(KEY_RIGHT_ARROW)
end loop
|
and have a global variable that controls which key was pressed in your if statements in your move proc, or something along those lines |
|
|
|
|
![](images/spacer.gif) |
|
|