This site requires JavaScript, please enable it in your browser!
Greenfoot back
dev4ltar
dev4ltar wrote ...

2018/12/26

Rotating canon from the end

1
2
3
danpost danpost

2018/12/27

#
dev4ltar wrote...
if i delete && direction < 0 and && direction > 0, why it can't rotate?
Because the initial rotation is "360" and direction will be set to 0 without the added condition that the value of direction be 1 (or greater than zero). That is, without the condition 'direction > 0', if oldRot is 360, then even if the value of direction was -1 (which is okay when oldRot is 360), it will still be set to 0 and the angle will not be changed.
dev4ltar dev4ltar

2018/12/27

#
1. oldRot == 360 && direction > 0 then it set the direction to 0, it can't have direction = 1, only 0 and -1 so set rotation 360 + (0/-1) 2. oldRot == 360 (direction = -1/0/1) then it set the direction to 0, the direction will always set to 0 so set rotation 360+0 so this (&& direction > 0) will keep the Rot on 359 so it able to change direction, is it right?
danpost danpost

2018/12/27

#
dev4ltar wrote...
so this (&& direction > 0) will keep the Rot on 359 so it able to change direction, is it right?
(&& direction > 0) will keep rotation at 360 (as 361, which is 1, is not a valid angle); and (&& direction < 0) will keep rotation at 300 (as 299 is not a valid angle). Think of it this way -- you are allowed to change the angle one degree in both direction in all cases of rotation between 301 and 359. The only times you cannot change the angle is when (angle is 360 #AND# angle is to increase -- direction is positive) and when (angle is 300 #AND# angle is to decrease -- direction is negative). For these two cases, no change in angle can be made, so direction (of change) is set to zero.
dev4ltar dev4ltar

2018/12/27

#
owh right (oldRot == 360 (direction = -1/0/1)) it always set the direction to 0, unable to change direction to -1 so these (&& direction > 0) and (&& direction < 0) like left and right steer on car right?
danpost danpost

2018/12/27

#
dev4ltar wrote...
owh right, if i delete (&& direction > 0), it become 2. oldRot == 360 make i unable to change direction to -1 because it set to 0 so these (&& direction > 0) and (&& direction < 0) like a left and right steer on car right?
No. The two changes that we cannot allow are when (a) cannon is up to max AND we want to raise it more; and (b) cannon is down to min AND we try to lower it further. What we have in the if statement are those conditions exactly. Angle is 300 and direction is up, for the first set of conditions; and angle is 360 and direction is down, for the other set. If either (OR, '||") set of conditions is true, do not change angle. This is the core of line 15.
dev4ltar dev4ltar

2018/12/27

#
yes, so on rot 360 it can't have direction = 1 or having Rot = 361, only direction = 0 or -1 so the rotation is 360 or 359- and so does 300 can't have direction = -1 or having Rot = 299, only direction = 0 or 1 so the rotation is 300 or 301+ thank you very much
You need to login to post a reply.
1
2
3