-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.as
51 lines (46 loc) · 1.07 KB
/
Enemy.as
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
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import fl.motion.MotionEvent;
public class Enemy extends MovieClip {
var timer:Timer = new Timer(1000 , 1);
var Destroyed:Boolean = true;
static var score:Number=0;
static var scoretext:Score;
public function Enemy(S:Score, GameTimer:Timer) {
// constructor code
var randomTime = Math.random() * 2000 + 1000;
scoretext=S;
timer.delay = randomTime;
timer.addEventListener(TimerEvent.TIMER_COMPLETE , Destroy);
this.addEventListener(MouseEvent.CLICK , AddScore);
GameTimer.addEventListener(TimerEvent.TIMER_COMPLETE , END);
timer.start();
}
function Destroy(e:TimerEvent)
{
if(Destroyed)
{
stage.removeChild(this);
Destroyed = false;
}
}
function AddScore(e:MouseEvent)
{
Destroyed=false;
score++;
scoretext.AddScore(score);
stage.removeChild(this);
}
function END(E:TimerEvent)
{
if(Destroyed)
{
stage.removeChild(this);
Destroyed = false;
}
}
}
}