~extremepopcorn/dhlib/dhlib_ep

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package fortress;

import mathx.MatrixUtil;
import mathx.MathUtil;
import mathx.Geometry;
import mathx.Point2;

import flash.display.Sprite;

class BouncerObject extends AttackingLiveObject
{
	var image : Sprite;
	
	public function new( gd : GameDriver )
	{
		super( gd, gd.global.bouncerFireSpeed, Point2.at( 2.5, 2.5 ) );
		
		speed = gameDriver.global.bouncerSpeed;
		maxHP = hp = gameDriver.global.bouncerHP;
		
		image = new IClipBouncer();
		image.width = GConst.gridSizeX * size.x;
		image.height = GConst.gridSizeY * size.y;
		image.x = -GConst.gridSizeX*size.x/2;
		image.y = -GConst.gridSizeY*size.y/2;
		addChild( image );
		
		draw();
	}
	
	override public function getScoreFactor() : Float
	{
		return 1.25;
	}
	
	override private function draw()
	{
/*		graphics.clear();
		
		graphics.beginFill( 0x808040 );
		graphics.drawEllipse( -(GConst.gridSizeX*size.x)/2, -(GConst.gridSizeY*size.y)/2,
			GConst.gridSizeX*size.x, GConst.gridSizeY*size.y );
		graphics.endFill();
		
		graphics.beginFill( 0x204020 );
		graphics.drawEllipse( -(GConst.gridSizeX*size.x)/4, -(GConst.gridSizeY*size.y)/3,
			GConst.gridSizeX*size.x/2, GConst.gridSizeY*size.y/4 );
		graphics.endFill();*/
		
	}
	
	override function stepMove( elapsed : Float )
	{
		//bounce off any edges or land mass (use shore dist > 0 to ensure no collisions...)
		var xFront = gameDriver.data.map.index( at.add( Point2.at( dir.x * speed * elapsed, 0 ) ) );
		if( gameDriver.data.map.shoreDistMap.def_get( xFront.x, xFront.y, 0 ) <= 0 )
			dir.x = -dir.x;
		
		var yFront = gameDriver.data.map.index( at.add( Point2.at( 0, dir.y * speed * elapsed ) ) );
		if( gameDriver.data.map.shoreDistMap.def_get( yFront.x, yFront.y, 0 ) <= 0 )
			dir.y = -dir.y;
			
		orient = Geometry.xAxisAngleV( dir ) + Math.PI/2;
		at = at.add( dir.mul( speed * elapsed ) );
	}
			
	override function stepFire()
	{		
		//closest wall between here and target (start from middle)
		var wall = gameDriver.data.map.getClosestCannon( at );
		if( wall == null )
			wall = gameDriver.data.map.getClosestOwnedTower( at );
		if( wall == null )
			return;	//just do nothing, player has lost at this point anyways...
		fireCannonAt( wall );
	}
	
	override private function added()
	{
		var initTarget = gameDriver.data.map.getClosestOwnedTower( at );
		Assert.notNull( initTarget );
		dir = at.unitVectorTo( initTarget );
		orient = Geometry.xAxisAngleV( dir ) + Math.PI/2;
	}
	
}