/
main.as
89 lines (79 loc) · 1.88 KB
/
main.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
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
package
{
import flash.display.*;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.TimerEvent;
public class main extends MovieClip
{
//Hier achter variabelen!!
public var myPlayer: Player;
public var myArena: arena;
public var bulletList:Array;
public var enemyList:Array;
public var EnemySpawning:Timer = new Timer(2000, 0);
//public var enemyList: Array = [5];
public var myEnemy: MovieClip;
public function main()
{
bulletList = new Array;
enemyList = new Array;
//New objects
myArena = new arena();
myPlayer = new Player();
myPlayer.myArena = myArena;
myEnemy = new Enemy(this);
myEnemy.x = 200;
myEnemy.y = 200;
this.addChild(myArena);
myArena.x = 1280 / 2;
myArena.y = 720 / 2;
this.addChild(myPlayer);
myPlayer.x = 100;
myPlayer.y = 100;
EnemySpawning.start();
//this.addChild(myEnemy);
this.addEventListener(Event.ENTER_FRAME, _Update);
EnemySpawning.addEventListener(TimerEvent.TIMER, spawning);
}
public function _Update(E: Event){
for(var a=0;a<bulletList.length;a++){
bulletList[a].update();
if(bulletList[a].parent==null){
bulletList.splice(a, 1);
a--;
}
}
for (var i=0;i<enemyList.length;i++)
{
enemyList[i].update();
for (a=0;a<bulletList.length;a++)
{
if (enemyList[i].hitTestObject(bulletList[a]))
{
removeChild(enemyList[i]);
enemyList.splice(i, 1);
//enemyList[i]=null;
removeChild(bulletList[a]);
bulletList.splice(a, 1);
//bulletList[a]=null;
break;
}
}
}
}
public function getPlayer(): Player
{
return this.myPlayer;
}
public function spawning(E:Event){
myEnemy = new Enemy(this);
myEnemy.x = 200;
myEnemy.y = 200;
addChild(myEnemy);
enemyList.push(myEnemy);
}
}
}