Besenham's LineDraw & speed !
BlitzMax Forums/BlitzMax Beginners Area/Besenham's LineDraw & speed !
| ||
Hi ! Need some help here ! From the code archive, posted by angel daniel : I use this method to move my ennemy along a line (point by point). It works fine. Now I'm trying to adapt this to move at speed 3 or more ! It should be easy to do but i've some difficulties to do this little thing in my game code ! i've modified these lines If X1<X2 Then XStep=1*Speed Else XStep=-1*Speed 'Direction If Y1<Y2 Then YStep=1*Speed Else YStep=-1*Speed 'Direction but not work ! Could you help me ! Thanks ! |
| ||
It wont work if speed is greater than the difference between x and y .. or in other words, bresenhams works by constantly `counting` an index by adding the step to it, and when the index gets over a certain value it `wraps around` like a modulo. Adding 1*Speed is probably not wrapping around properly. You probably would need to run the loop 3 times and THEN draw on the third time? ie If Counter Mod 3=0 Then Draw |
| ||
ok thanks ! |
| ||
I personally prefer using sin and cosin: dirx# = cos(angle) diry# = sin(angle) speed# = 2.0 while angle not changed . . x# = x#+dirx#*speed# y# = y#+diry#*speed# plot x#,y# . . wend and sence most predefined BM commands are in floats then I don't have to worry about casting problems. I hope is of use to somebody. no harm intended. |