-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.as
200 lines (151 loc) · 4.83 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import com.greensock.TweenLite;
import com.greensock.plugins.ColorMatrixFilterPlugin;
import com.greensock.plugins.TweenPlugin;
import flash.display.Shape;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
TweenPlugin.activate([ColorMatrixFilterPlugin]);
public class Main extends MovieClip {
private var timer:Timer;
private var puntaje_txt:TextField;
private var vidas_txt:TextField;
private var puntos:int;
private var vidas:int;
private var inicio:MovieClip;
private var sndMuere:Sound;
private var sndBala:Sound;
public function Main() {
inicio = new Home() as MovieClip;
inicio.y = -inicio.height;
TweenLite.to(inicio, 0.5, {y:0});
addChild(inicio);
inicio.botonJugar.addEventListener(MouseEvent.CLICK, btnJugarClick);
inicio.botonJugar.buttonMode = true;
var fondo:Shape = new Shape();
fondo.graphics.beginFill(0xFFFFFF);
fondo.graphics.drawRect(0,0,800,600);
fondo.graphics.endFill();
addChildAt(fondo, 0);
sndMuere = new Sound();
sndMuere.load(new URLRequest("sounds/62386__fons__eng-1.mp3"));
sndBala = new Sound();
sndBala.load(new URLRequest("sounds/220612__senitiel__pistol2.mp3"));
}
private function btnJugarClick(e:MouseEvent):void{
TweenLite.to(inicio, 0.5, {y:-inicio.height, onComplete:iniciaJuego});
}
private function iniciaJuego(){
removeChild(inicio);
var sndFondo:Sound = new Sound();
sndFondo.load(new URLRequest("sounds/hell-Mike_Koenig-144950046.mp3"));
//var chnFondo:SoundChannel = sndFondo.play();
crearTimer();
crearCarteles();
stage.addEventListener(Event.ENTER_FRAME, mover);
}
private function crearTimer(){
timer = new Timer(1500);
timer.addEventListener(TimerEvent.TIMER, crearMonstruos);
timer.start();
}
private function crearCarteles(){
vidas = 100;
puntos = 0;
puntaje_txt = new TextField;
puntaje_txt.opaqueBackground = true;
puntaje_txt.defaultTextFormat = new TextFormat("Arial", 16);
puntaje_txt.text = "Puntaje: 0";
puntaje_txt.textColor = 0xFFFFFF;
puntaje_txt.height = puntaje_txt.textHeight * 1.5;
vidas_txt = new TextField;
vidas_txt.opaqueBackground = true;
vidas_txt.defaultTextFormat = new TextFormat("Arial", 16);
vidas_txt.text = "Vidas: 3";
vidas_txt.textColor = 0xFFFFFF;
vidas_txt.height = puntaje_txt.textHeight * 1.5;
vidas_txt.x = stage.stageWidth - vidas_txt.width;
addChild(puntaje_txt);
addChild(vidas_txt);
}
private function mover(e:Event):void{
var hijos:int = numChildren;
if(hijos > 0){
for(var i:int = 0; i < hijos; i++){
var mc:MovieClip = getChildAt(i) as MovieClip;
if(mc){
mc.x += 1;
if(mc.x >= stage.stageWidth){
vidas--;
vidas_txt.text = "Vidas: " + vidas.toString();
removeChild(mc);
TweenLite.to(this, 0.5, {colorMatrixFilter:{colorize:0xff0000, amount:0.5}, onComplete:regresarEstado});
hijos--
if(vidas == 0){
trace("Acabó");
stage.removeEventListener(Event.ENTER_FRAME, mover);
timer.stop();
}
}
}
}
}
}
private function crearMonstruos(e:TimerEvent):void{
var mod:int = timer.currentCount%3;
var enemigo:MovieClip
if(mod == 0){
enemigo = new cuadrado();
enemigo.tabIndex = 4;
enemigo.name = "enemigo1";
}
else{
enemigo = new triangulo();
enemigo.tabIndex = 2;
enemigo.name = "enemigo2";
}
enemigo.y = Math.random() * stage.stageHeight;
enemigo.x = 0;
enemigo.addEventListener(MouseEvent.CLICK, matar);
addChild(enemigo);
}
private function matar(e:MouseEvent):void{
var mc:MovieClip = e.currentTarget as MovieClip;
var nombre:String = mc.name;
//trace(mc.tabIndex);
mc.tabIndex--;
if(mc.tabIndex == 0){
//removeChild(mc);
mc.removeEventListener(MouseEvent.CLICK, matar);
TweenLite.to(mc, 0.5, {alpha:0, scaleX:0, scaleY:0, onComplete:removeChild, onCompleteParams:[mc]});
puntos++;
puntaje_txt.text = "Puntaje: " + puntos.toString();
sndMuere.play();
}
else{
sndBala.play();
if(nombre == "enemigo1"){
mc.scaleX = 0.5;
mc.scaleY = 0.5;
TweenLite.to(mc, 0.3, {y:"+10", scaleX:1, scaleY:1});
}
else{
mc.scaleX = 0.5;
mc.scaleY = 0.5;
TweenLite.to(mc, 0.3, {rotation:"+30", scaleX:1, scaleY:1 });
}
}
}
private function regresarEstado(){
TweenLite.to(this, 0.5, {colorMatrixFilter:{colorize:0xff0000, amount:0}});
}
}
}