1
- package { import flash.events.*; import flash.display.*; import GameTheater.gtObjects.*; import GameTheater.gtObjects.gtBehaviors.*; import GameTheater.gtSystems.*; import GameTheater.gtSystems.gtSystemObjects.*; import GameTheater.gtTools.*; import PinStriper.psObjects.*; import PinStriper.psSystems.*; import PinStriper.psTools.*; public dynamic class snrZombieGrunt extends gtBehavior { public var playerTarget = null; public function snrZombieGrunt() { m_name = "gob"; } public override function Awake() { gameObject.content = new Zombie_Grunt(); gameObject.actor.Attach(psEasel.GetCanvas("game_space")); /* var side = (int)(Math.random() * 3); if(side == 0) { // top gameObject.x = (Math.random() * 750) - 350; gameObject.y = -275; } else if (side == 1) { // right gameObject.y = (Math.random() * 550) - 250; gameObject.x = 375; } else if (side == 2) { // bottom gameObject.x = (Math.random() * 750) - 350; gameObject.y = 275; } else if (side == 3) { //left gameObject.y = (Math.random() * 550) - 250; gameObject.x = -375; } //*/ gameObject.y = 300; states.Add("Front", Front, "Targeting").Update(); states.Add("Left", Left, "Targeting").Update(); states.Add("Right", Right, "Targeting").Update(); } public override function Start() { var ang = Math.atan2((gameObject.y - playerTarget.y),(gameObject.x - playerTarget.x)); gameObject.rotation = (ang * 180 / Math.PI) - 90; states.Activate("Front"); } public function Front(s:int) { if(s == gtState.INIT) { } else if(s == gtState.UPDATE) { var ang = ((Math.atan2((gameObject.y - playerTarget.y),(gameObject.x - playerTarget.x))) * 180 / Math.PI) - 90; gameObject.rotation = ang; } else if(s == gtState.EXIT) { } } public function Left(s:int) { if(s == gtState.INIT) { } else if(s == gtState.UPDATE) { } else if(s == gtState.EXIT) { } } public function Right(s:int) { if(s == gtState.INIT) { } else if(s == gtState.UPDATE) { } else if(s == gtState.EXIT) { } } } }
1
+ package
2
+ {
3
+ import flash.events.* ;
4
+ import flash.display.* ;
5
+ import GameTheater.gtObjects.* ;
6
+ import GameTheater.gtObjects.gtBehaviors.* ;
7
+ import GameTheater.gtSystems.* ;
8
+ import GameTheater.gtSystems.gtSystemObjects.* ;
9
+ import GameTheater.gtTools.* ;
10
+ import PinStriper.psObjects.* ;
11
+ import PinStriper.psSystems.* ;
12
+ import PinStriper.psTools.* ;
13
+ import flash.geom.Point ;
14
+
15
+ public dynamic class snrZombieGrunt extends gtBehavior
16
+ {
17
+ public var playerTarget = null ;
18
+ public var index: int ;
19
+
20
+ public static var enemies: Array ;
21
+
22
+ public var m_vx = 0 ;
23
+ public var m_vy = 0 ;
24
+ public var m_rotationSpeed = 120 ;
25
+ public var m_speed = 1000 ;
26
+
27
+ public function snrZombieGrunt ()
28
+ {
29
+ m_name = "gob" ;
30
+
31
+ if (enemies == null )
32
+ {
33
+ enemies = new Array ();
34
+ }
35
+
36
+ index = enemies. count ;
37
+
38
+ enemies. push (gameObject);
39
+ }
40
+
41
+ public override function Awake ()
42
+ {
43
+ gameObject. content = new Zombie_Grunt();
44
+
45
+ gameObject. actor. Attach(psEasel. GetCanvas("game_space" ));
46
+
47
+ /*
48
+ var side = (int)(Math.random() * 3);
49
+
50
+ if(side == 0)
51
+ {
52
+ // top
53
+ gameObject.x = (Math.random() * 750) - 350;
54
+ gameObject.y = -275;
55
+ }
56
+ else if (side == 1)
57
+ {
58
+ // right
59
+ gameObject.y = (Math.random() * 550) - 250;
60
+ gameObject.x = 375;
61
+ }
62
+ else if (side == 2)
63
+ {
64
+ // bottom
65
+ gameObject.x = (Math.random() * 750) - 350;
66
+ gameObject.y = 275;
67
+ }
68
+ else if (side == 3)
69
+ {
70
+ //left
71
+ gameObject.y = (Math.random() * 550) - 250;
72
+ gameObject.x = -375;
73
+ }
74
+ //*/
75
+
76
+ gameObject. y = 100 ;
77
+
78
+ states . Add("Front" , Front, "Targeting" ). Update();
79
+ states . Add("Left" , Left, "Targeting" ). Update();
80
+ states . Add("Right" , Right, "Targeting" ). Update();
81
+ }
82
+
83
+ public override function Start ()
84
+ {
85
+ checkTarget();
86
+
87
+ states . Activate("Front" );
88
+ }
89
+
90
+ public function checkTarget ()
91
+ {
92
+ var ang = Math . atan2 ((gameObject. y - playerTarget. y ),(gameObject. x - playerTarget. x ));
93
+ gameObject. rotation = (ang * 180 / Math . PI ) - 90 ;
94
+
95
+ var testRotate = playerTarget. rotation - gameObject. rotation ;
96
+
97
+ trace (testRotate);
98
+
99
+ if (testRotate < 0 && testRotate > - 80 )
100
+ {
101
+
102
+ }
103
+
104
+ /*
105
+ if ( testRotate <= -100 && testRotate >= 100)
106
+ {
107
+ states.Activate("Front");
108
+ trace("front");
109
+ }
110
+ else if( testRotate > -100 && testRotate <=0)
111
+ {
112
+ states.Activate("Left");
113
+ trace("Left");
114
+ }
115
+ else if (testRotate > 100 && testRotate < 0)
116
+ {
117
+ states.Activate("Right");
118
+ trace("Right");
119
+ }
120
+ */
121
+ }
122
+
123
+ public function Front (s :int )
124
+ {
125
+ if (s == gtState. INIT )
126
+ {
127
+
128
+ }
129
+ else if (s == gtState. UPDATE )
130
+ {
131
+ var p = playerTarget. localToGlobal (new Point (0 , - 25 ));
132
+
133
+ var dx: Number = (p. x ) - (gameObject. x );
134
+ var dy: Number = (p. y ) - (gameObject. y );
135
+
136
+ var targetAngle: Number = (Math . atan2 (dy, dx) * 180 / Math . PI ) - 90 ;
137
+ var delta : Number = m_rotationSpeed * gtTime. deltaT;
138
+
139
+ if (targetAngle < - 180 )
140
+ targetAngle += 360 ; // shortest route
141
+ if (targetAngle > 180 )
142
+ targetAngle -= 360 ;
143
+ if (targetAngle > delta )
144
+ targetAngle = delta ; // cap turn speed
145
+ else if (targetAngle < - delta )
146
+ targetAngle = - delta ;
147
+
148
+ angle += targetAngle;
149
+
150
+ var angleRad: Number = angle * Math . PI / 180 ; // convert to radians
151
+ var cosa: Number = Math . cos (angleRad);
152
+ var sina: Number = Math . sin (angleRad);
153
+ m_vx += (cosa * m_speed) * gtTime. deltaT;
154
+ m_vy += (sina * m_speed) * gtTime. deltaT;
155
+ //if (velocity.x > maxThrust)
156
+ //velocity.x = maxThrust; // cap
157
+ //else if (velocity.x < -maxThrust) velocity.x = -maxThrust;
158
+ //if (velocity.y > maxThrust) velocity.y = maxThrust;
159
+ //else if (velocity.y < -maxThrust) velocity.y = -maxThrust;
160
+
161
+ //trace(p);
162
+
163
+ gameObject. x += m_vx;
164
+ gameObject. y += m_vy;
165
+
166
+ checkTarget();
167
+ }
168
+ else if (s == gtState. EXIT )
169
+ {
170
+
171
+ }
172
+ }
173
+
174
+ public function Left (s :int )
175
+ {
176
+ if (s == gtState. INIT )
177
+ {
178
+
179
+ }
180
+ else if (s == gtState. UPDATE )
181
+ {
182
+ checkTarget();
183
+ }
184
+ else if (s == gtState. EXIT )
185
+ {
186
+
187
+ }
188
+ }
189
+
190
+ public function Right (s :int )
191
+ {
192
+ if (s == gtState. INIT )
193
+ {
194
+
195
+ }
196
+ else if (s == gtState. UPDATE )
197
+ {
198
+
199
+
200
+ checkTarget();
201
+ }
202
+ else if (s == gtState. EXIT )
203
+ {
204
+
205
+ }
206
+ }
207
+ }
208
+ }
0 commit comments