2
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
11
* The laser is the visible laser beam from one point to another.
13
class Laser extends GameObject
15
var image : ui.Widget;
18
var remainTime : Float;
21
public function new( game : Game, from : Point2, to : Point2 )
25
this.from = from.clone();
28
remainTime = 2.0 * Global.laserSpeed;
31
//we just cover the whole surface and draw a single line in it.
32
at = Point2.at( 0, 0 );
33
image = ui.DrawBox.scaled( drawLaser, Point2.at( 1, 1 ) );
34
game.actionDisplay.addActor( image );
35
game.actionDisplay.placeActor( image, at );
36
//must be sized last, since a draw will actually occur and we need to be initialized
37
game.actionDisplay.sizeActor( image, Point2.at( 1, 1 ) );
40
override public function stepTime( elapsed : Float )
42
remainTime -= elapsed;
49
if( remainTime <= Global.laserSpeed )
50
image.getNative().alpha = remainTime / Global.laserSpeed;
52
//TODO: could optimize to stop drawing after surge is gone, but we
53
//need to ensure that it acutally reaches the maximum distance...
54
surgeAt += elapsed / Global.laserSpeed;
59
override function destroy()
62
game.actionDisplay.removeActor( image );
65
function drawLaser( gfx : draw.GraphicsX )
67
var seg = to.sub( from );
68
var sb = Math.max( 0, Math.min( 1, surgeAt - 0.1 ) );
69
var se = Math.min( 1, surgeAt );
72
gfx.use( Pen.solid( 2, Color.rgb( 0.5, 0.8, 1.0 ), 0.5 ) );
73
gfx.drawLinePt( from, from.add( seg.mul( se ) ) );
75
//draw surge moving along the line
76
gfx.use( Pen.solid( 3, Color.rgb( 1, 1, 1 ) ) );
77
gfx.drawLinePt( from.add( seg.mul( sb ) ), from.add( seg.mul( se ) ) );