~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
87
88
89
90
91
92
93
94
95
96
97
98
package fortress;

import mathx.Point2;

class GraftTitle extends GraftTitleBase
{
	var waveAng : Float;
	var monsterAng : Float;
	var towerPos : Float;
	var frogAng : Float;
	
	public function new()
	{
		super();
		enableAnimation = true;
		
		waveAng = 0;
		monsterAng = 0;
		towerPos = 0.5;
		frogAng = 3 * Math.PI/2;
		
		autoUpdate = false;
		_animate( 0 );	//ensure starting posistions
	}
	
	override function _animate( elapsed : Float )
	{
		//TODO: try to get more of this into the Graft logic itself
		
		//odd multiples are to ensure nothing is insync
		waveAng = mathx.Geometry.normalizeAngle( waveAng + elapsed*0.98 );
		monsterAng = mathx.Geometry.normalizeAngle( monsterAng - elapsed*0.87 );
		frogAng = mathx.Geometry.normalizeAngle( frogAng + elapsed*1.01 );
		towerPos = Math.max( 0, towerPos - elapsed/9.56 );
		
		//move waves
		var scaleA = Point2.at( 0.05, 0.01 );
		var wOff = Point2.fromAngle( waveAng ).scale( scaleA );
		waves_left_1.offsetGS = wOff;
		
		wOff = Point2.fromAngle( waveAng + Math.PI ).scale( scaleA );
		waves_right_1.offsetGS = wOff;
		
		wOff = Point2.fromAngle( waveAng + Math.PI/2 ).scale( scaleA );
		waves_left_2.offsetGS = wOff;
		
		wOff = Point2.fromAngle( waveAng -  Math.PI/2 ).scale( scaleA );
		waves_right_2.offsetGS = wOff;
		
		//move monster
		var mOff = Point2.fromAngle( monsterAng ).mul( 0.25 );
		monster.offsetGS = mOff;
		monster.orient = -2*monsterAng;	 
		
		//raise tower
		tower.offsetGS = Point2.at( 0, towerPos );
		
		//frog bouncing
		var frogTitle = frogAng > Math.PI/2 && frogAng < 3*Math.PI/2;
		var squishH = frogTitle ? 0.0 : 0.10;
		var frogY = (-0.35-squishH) * Math.abs( Math.sin( frogAng ) ) + squishH;
		frog.offsetGS = Point2.at( 
		   frogTitle ? title.posGS.x-frog.posGS.x : 0, 
			Math.min( 0, frogY )
			);
			
		if( !frogTitle && frogY > 0 )
			frog.scale = Point2.at( 1, 1.0 - frogY/squishH * 0.5 );
		else
			frog.scale = Point2.at( 1,1 );
			
		//adjust title for frog stepping on it
		var to;
		if( frogTitle )
			to = Math.max( 0, (frog.posGS.y + frog.offsetGS.y) - title.posGS.y );
		else
			to = 0.0;
		title.offsetGS = Point2.at( 0, to );
		
		//finally update the scene
		update();
	}
	
	override function _resize( w : Float, h : Float )
	{
		gfx.clear();
		gfx.use( draw.Brush.linearGradient( 
			0,
			[ draw.Color.rgb( 1, 1,1 ), draw.Color.rgb( 0.4, 0.8, 0.8 )  ],
			[ 0.1, w*0.9, w ],
			null,
			Point2.at( -w/2, 0 )
			) 
			);
		gfx.drawRect( -w/2, -h/2,  w, h );
		super._resize(w,h);
	}
}