home *** CD-ROM | disk | FTP | other *** search
- function initGame()
- {
- nextBulletTime = 0;
- nextBullet = 0;
- bullets = [];
- score = 0;
- level = 1;
- px = 10;
- px2 = 10;
- speedx = 3;
- speedy = 3;
- numdeballs = 0;
- currentballs = numdeballs;
- speedbat = 5;
- _root.medidor._x = 19;
- _root.medidor._y = 12;
- vida = 19;
- _root.attachMovie("rayo","proyectil",numdeballs + 100);
- _root.proyectil._x = 0;
- _root.proyectil._y = -10;
- lastlevel = 15;
- }
- function startTimer()
- {
- levelTime = getTimer();
- batTime = levelTime + 30000;
- }
- function extralife()
- {
- _root.attachMovie("bat","xtralife",1000);
- _root.xtralife._x = -20;
- _root.xtralife._y = 50 + int(Math.random() * 15);
- }
- function moveXtraLife()
- {
- _root.xtralife._x += speedbat;
- if(420 < _root.xtralife._x)
- {
- bat = 0;
- _root.xtralife.removeMovieClip();
- }
- }
- function checkXtraLife()
- {
- levelTime = getTimer();
- if(batTime < levelTime)
- {
- extralife();
- bat = 1;
- startTimer();
- }
- if(bat == 1)
- {
- moveXtraLife();
- }
- }
- function newballs()
- {
- startTimer();
- i = 0;
- while(i < numdeballs)
- {
- attachMovie("bola","reloj" + i,i);
- _root["reloj" + i].watch.gotoAndPlay(framewatch);
- _root["reloj" + i]._x = 20 + int(Math.random() * 300);
- _root["reloj" + i]._y = 47 + int(Math.random() * 60);
- valor = int(Math.random() * 2);
- if(valor == 0)
- {
- _root["reloj" + i].dx = - (speedx + int(Math.random() * 5));
- }
- else
- {
- _root["reloj" + i].dx = speedx + int(Math.random() * 5);
- }
- _root["reloj" + i].dy = speedy + int(Math.random() * speedy);
- _root["reloj" + i].tamano = 3;
- i++;
- }
- }
- function termino()
- {
- if(currentballs == 0)
- {
- _root.pepe._y = -10;
- _root.pepe._x = 150;
- bat = 0;
- _root.xtralife.removeMovieClip();
- pausa();
- }
- }
- function pausa()
- {
- contador++;
- if(5 < contador)
- {
- cambiarfondo();
- nivel = "LEVEL " + level;
- }
- if(40 < contador)
- {
- nivel = " ";
- }
- if(50 < contador)
- {
- _root.pepe._y = 293;
- newlevel2();
- }
- }
- function cambiarfondo()
- {
- if(7 >= level)
- {
- _root.fondo.gotoAndPlay("fondo" + level);
- }
- else
- {
- fondillo = level - 7;
- _root.fondo.gotoAndPlay("fondo" + fondillo);
- }
- }
- function newlevel2()
- {
- if(level == 1)
- {
- framewatch = 2;
- speedbat = 5;
- speedy = 4;
- contador = 0;
- numdeballs = 1;
- currentballs = 1;
- newballs();
- }
- if(level == 2)
- {
- framewatch = 2;
- speedbat = 6;
- speedy = 4;
- contador = 0;
- numdeballs = 2;
- currentballs = 2;
- newballs();
- }
- if(level == 3)
- {
- framewatch = 2;
- speedbat = 6;
- speedy = 4;
- contador = 0;
- numdeballs = 3;
- currentballs = 3;
- newballs();
- }
- if(level == 4)
- {
- framewatch = 1;
- speedbat = 7;
- speedy = 6;
- contador = 0;
- numdeballs = 1;
- currentballs = 1;
- newballs();
- }
- if(level == 5)
- {
- framewatch = 1;
- speedbat = 9;
- speedy = 7;
- contador = 0;
- numdeballs = 2;
- currentballs = 2;
- newballs();
- }
- if(level == 6)
- {
- framewatch = 3;
- speedbat = 8;
- speedy = 7;
- contador = 0;
- numdeballs = 3;
- currentballs = 3;
- newballs();
- }
- if(level == 7)
- {
- framewatch = 3;
- speedbat = 8;
- speedy = 7;
- contador = 0;
- numdeballs = 4;
- currentballs = 4;
- newballs();
- }
- if(level == 8)
- {
- framewatch = 2;
- speedbat = 9;
- speedy = 7;
- contador = 0;
- numdeballs = 1;
- currentballs = 1;
- newballs();
- }
- if(level == 9)
- {
- framewatch = 2;
- speedbat = 9;
- speedy = 8;
- contador = 0;
- numdeballs = 2;
- currentballs = 2;
- newballs();
- }
- if(level == 10)
- {
- framewatch = 2;
- speedbat = 9;
- speedy = 8;
- contador = 0;
- numdeballs = 3;
- currentballs = 3;
- newballs();
- }
- if(level == 11)
- {
- framewatch = 1;
- speedbat = 6;
- speedy = 9;
- contador = 0;
- numdeballs = 1;
- currentballs = 1;
- newballs();
- }
- if(level == 12)
- {
- framewatch = 1;
- speedbat = 7;
- speedy = 8;
- contador = 0;
- numdeballs = 2;
- currentballs = 2;
- newballs();
- }
- if(level == 13)
- {
- framewatch = 3;
- speedbat = 7;
- speedy = 8;
- contador = 0;
- numdeballs = 3;
- currentballs = 3;
- newballs();
- }
- if(level == 14)
- {
- framewatch = 3;
- speedbat = 8;
- speedy = 8;
- contador = 0;
- numdeballs = 5;
- currentballs = 5;
- newballs();
- }
- }
- function explodeball()
- {
- boomsound();
- attachMovie("bola","reloj" + numdeballs,numdeballs);
- _root["reloj" + numdeballs].watch.gotoAndPlay(framewatch);
- currentballs += 1;
- _root["reloj" + numdeballs].gotoAndPlay("split");
- _root["reloj" + numdeballs].tamano = _root["reloj" + pelotasacada].tamano;
- _root["reloj" + numdeballs]._xscale = _root["reloj" + pelotasacada]._xscale;
- _root["reloj" + numdeballs]._yscale = _root["reloj" + pelotasacada]._yscale;
- _root["reloj" + numdeballs]._x = _root["reloj" + pelotasacada]._x + 20;
- _root["reloj" + numdeballs]._y = _root["reloj" + pelotasacada]._y + 20;
- _root["reloj" + pelotasacada].dy = - Math.abs(_root["reloj" + pelotasacada].dy);
- _root["reloj" + numdeballs].dy = - Math.abs(_root["reloj" + pelotasacada].dy);
- _root["reloj" + numdeballs].dx = - _root["reloj" + pelotasacada].dx;
- numdeballs += 1;
- }
- function moveClocks()
- {
- i = 0;
- while(i < numdeballs)
- {
- _root["reloj" + i]._x += _root["reloj" + i].dx;
- _root["reloj" + i]._y += _root["reloj" + i].dy;
- diametro = _root["reloj" + i]._height / 2;
- diametro2 = _root["reloj" + i]._width / 2;
- if(380 < _root["reloj" + i]._x + diametro2)
- {
- _root["reloj" + i].dx = - _root["reloj" + i].dx;
- _root["reloj" + i]._x -= diametro / 2;
- }
- if(_root["reloj" + i]._x < 20)
- {
- _root["reloj" + i].dx = - _root["reloj" + i].dx;
- }
- if(300 < _root["reloj" + i]._y)
- {
- _root["reloj" + i].dy = - _root["reloj" + i].dy;
- }
- if(_root["reloj" + i]._y - diametro < 37)
- {
- _root["reloj" + i].dy = - _root["reloj" + i].dy;
- _root["reloj" + i]._y += diametro / 2;
- }
- i++;
- }
- }
- function boomsound()
- {
- s = new Sound();
- s.attachSound("boom");
- s.start();
- }
- function lasersound()
- {
- if(currentballs != 0)
- {
- s = new Sound();
- s.attachSound("laser");
- s.start();
- }
- }
- function electricsound()
- {
- s = new Sound();
- s.attachSound("electricity");
- s.start();
- }
- function batsound()
- {
- s = new Sound();
- s.attachSound("batpoom");
- s.start();
- }
- function hayContacto()
- {
- if(_root["reloj" + pelotasacada].tamano == 1)
- {
- _root["reloj" + pelotasacada].gotoAndPlay("split2");
- score += 50;
- currentballs--;
- boomsound();
- if(currentballs == 0)
- {
- level++;
- if(level == lastlevel)
- {
- endgame();
- }
- }
- }
- if(_root["reloj" + pelotasacada].tamano == 2)
- {
- _root["reloj" + pelotasacada].gotoAndPlay("split");
- _root["reloj" + pelotasacada].tamano = 1;
- _root["reloj" + pelotasacada]._xscale = 50;
- _root["reloj" + pelotasacada]._yscale = 50;
- score += 75;
- explodeball();
- }
- if(_root["reloj" + pelotasacada].tamano == 3)
- {
- _root["reloj" + pelotasacada].gotoAndPlay("split");
- _root["reloj" + pelotasacada].tamano = 2;
- _root["reloj" + pelotasacada]._xscale = 75;
- _root["reloj" + pelotasacada]._yscale = 75;
- score += 100;
- explodeball();
- }
- }
- function dispara()
- {
- if(nextBulletTime < getTimer())
- {
- lasersound();
- protagonista.gotoAndPlay("fire2");
- _root.attachMovie("rayo","proyectil" + nextBullet,nextBullet + 100);
- if(px2 == 10)
- {
- _root["proyectil" + nextBullet]._x = _root.pepe._x + 12;
- _root["proyectil" + nextBullet]._y = _root.pepe._y - 35;
- _root["proyectil" + nextBullet]._xscale = 15;
- _root["proyectil" + nextBullet]._yscale = 30;
- }
- else if(px2 == -10)
- {
- _root["proyectil" + nextBullet]._x = _root.pepe._x - 12;
- _root["proyectil" + nextBullet]._y = _root.pepe._y - 35;
- _root["proyectil" + nextBullet]._xscale = 15;
- _root["proyectil" + nextBullet]._yscale = 30;
- }
- bullets.push(nextBullet);
- nextBullet++;
- nextBulletTime = getTimer() + 500;
- }
- }
- function mueveProyectil()
- {
- i = bullets.length - 1;
- while(i >= 0)
- {
- bullet = _root["proyectil" + bullets[i]];
- bullet._y -= 15;
- if(bullet._y < 45)
- {
- bullet.removeMovieClip();
- bullets.splice(i,1);
- }
- else if(chequeaChoque(bullet))
- {
- bullet.removeMovieClip();
- bullets.splice(i,1);
- }
- i--;
- }
- }
- function chequeaChoque(bullet)
- {
- if(bat == 1)
- {
- d = _root.xtralife;
- if(d.hitTest(bullet))
- {
- batsound();
- score += 99;
- vida = 19;
- showvida();
- d.removeMovieClip();
- bat = 0;
- }
- }
- it = 0;
- while(it < numdeballs)
- {
- a = _root["reloj" + it];
- if(a.hitTest(bullet))
- {
- pelotasacada = it;
- hayContacto();
- return true;
- }
- it++;
- }
- return false;
- }
- function muevePepe()
- {
- protagonista = _root.pepe;
- if(Key.isDown(Key.LEFT))
- {
- px = -10;
- protagonista._xscale = - Math.abs(protagonista._xscale);
- px2 = px;
- }
- else if(Key.isDown(Key.RIGHT))
- {
- px = 10;
- px2 = px;
- protagonista._xscale = Math.abs(protagonista._xscale);
- }
- else
- {
- px = 0;
- }
- protagonista._x += px;
- if(px == 0 and protagonista._currentFrame != 1)
- {
- protagonista.gotoAndPlay("fire");
- }
- else if(px != 0 and protagonista._currentFrame == 1)
- {
- protagonista.gotoAndPlay("left");
- }
- if(protagonista._x >= 350)
- {
- protagonista._x = 350;
- }
- if(30 >= protagonista._x)
- {
- protagonista._x = 30;
- }
- if(Key.isDown(Key.SPACE))
- {
- _root.dispara();
- }
- }
- function showvida()
- {
- if(100 < vida)
- {
- endgame();
- vida = 19;
- }
- _root.medidor._x = vida;
- }
- function endgame()
- {
- it = 0;
- while(it < numdeballs)
- {
- a = _root["reloj" + it];
- a.removeMovieClip();
- it++;
- }
- i = bullets.length - 1;
- while(i >= 0)
- {
- bullet = _root["proyectil" + bullets[i]];
- bullet.removeMovieClip();
- i--;
- }
- if(level == lastlevel)
- {
- gotoAndPlay(12);
- }
- else
- {
- gotoAndPlay(11);
- }
- }
- function TuddHurt()
- {
- prot = _root.pepe;
- it = 0;
- while(it < numdeballs)
- {
- a = _root["reloj" + it];
- if(distance(_root.pepe,_root["reloj" + it]) < 35)
- {
- electricsound();
- vida += 2;
- showvida();
- prot.gotoAndPlay("humo");
- }
- it++;
- }
- }
- function distance(clip1, clip2)
- {
- tx = clip1._x - clip2._x;
- ty = clip1._y - clip2._y;
- return Math.sqrt(tx * tx + ty * ty);
- }
- Mouse.hide();
- stop();
-