Allegro.cc Forums » Programming Questions » Drawing line frame by frame

Credits go to Arthur Kalliokoski and SiegeLord for helping out!
 Arthur Kalliokoski Second in Command February 2005 CrimsonV said: an uni project. Quote: the line is drawn from the cursor to the turret, rather than the opposite, and reversing it is proving harder than it actually seemed. A university student can't swap a pair of 2d variables? Drink a Pepsi and try again.Wikipedia entry on Bresenham's line algorithm shows this (among others) ```plotLine(x0,y0, x1,y1) dx=x1-x0 dy=y1-y0 D = 2*dy - dx plot(x0,y0) y=y0 for x from x0+1 to x1 if D > 0 y = y+1 plot(x,y) D = D + (2*dy-2*dx) else plot(x,y) D = D + (2*dy) ``` So change the first line from plotLine(x0,y0, x1,y1) to plotLine(x1,y1, x0,y0)? They all watch too much MSNBC... they get ideas.
 SiegeLord Member #7,827 October 2006 CrimsonV said: No need to be sassy about it. Arthur is the resident sass-master.So I'm confused why you don't do something like this (if I understand your task correctly):```auto dx = end_x - start_x; auto dy = end_y - start_y; auto ratio = (game_time - start_time) / beam_duration; al_draw_line(start_x, start_y, ratio * dx + start_x, ratio * dy + start_y, ...); ``` That will draw a line that slowly increases in length from start to finish. Alternatively (and equivalently), you could do something like this too:```al_draw_line(spawn_x, spawn_y, cur_x, cur_y, ...); ``` Where each game tick, you update cur_x and cur_y:```cur_x += dt * vel_x; cur_y += dt * vel_y; ``` Although I don't think it is the right tool for this task, A5 actually does have a do_line equivalent: al_draw_soft_line. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]