
Tiene más errores de los que veo, según una IA.
Por ejemplo:
- Al destruir a un enemigo, puede que se destruya otro debido a un error. Desde que puse esto al final
LdeProfundidadesDisponibles.push(LdeProfundidadesDisponibles.length+1);
- El mecanismo de agregar enemigos parece estar funcionando mal, es como que el máximo siempre es 10, pero debería aumentar. Creo que se requiere la línea esa que mencioné, pero no sirvió parece.
- En el loop de mover enemigos, puede que se apliquen acciones a enemigos inexistentes. Habría que asignarles nombres mejor, pero la idea de usar los números finales (de la lista de profundidades disponibles) me la había dado una IA.
- Una IA insiste en que mi método de chequear colisiones puede mejorarse, en el sentido de que se puede hacer break antes o algo así. Le dije que si un disparo toca un área de un enemigo eso no significa que deba ser eliminado aún, pues otra área podría estar tocando al jugador, hay que revisar todas las áreas. Dice que entonces revise 1ero las áreas del jugador. Le digo que hago todo en un mismo loop, sino tendría que usar 2 (revisar si área 1 toca al jugador, si área 2, 3, luego otro loop: Revisar si área 1 toca al disparo, si área 2...), pero sigue insistiendo no sé qué, es tanto entrevero que ni mirar quiero.
Código
fscommand ("fullscreen", "true"); // ////////////////////////////////////////////// // ////////////////// mAvatar ////////////////// // ////////////////////////////////////////////// // Disparos suyos en pantalla: AvatarShots = 0; attachMovie("sGalaxianShip", "mAvatar", 0); mAvatar._x = 160; mAvatar._y = 230; // Para que las áreas de contacto no se vean: Area = 0; do { Area++; mAvatar["Area"+Area]._visible = false; } while (Area<8); delete Area; AvatarSpeed = 0.75; function ControlAvatar () { if (Key.isDown(37)) { // Izquierda: mAvatar._x = Math.max(13, mAvatar._x-AvatarSpeed); } else if (Key.isDown(39)) { // Derecha: mAvatar._x = Math.min(307, mAvatar._x+AvatarSpeed); } if (Key.isDown(83) && AvatarShots == 0) { // S, shot: AvatarShots = 1; attachMovie("sGalaxianShot", "mAvatarShot", 1000); mAvatarShot._x = mAvatar._x; mAvatarShot._y = mAvatar._y-10; mAvatar.gotoAndStop(2); } } // ///////////////////////////////////////////// // ////////////////// Shots ////////////////// // ///////////////////////////////////////////// function MoveShots () { if (AvatarShots>0) { mAvatarShot._y = mAvatarShot._y-2; if (mAvatarShot._y<-2) { AvatarShots = 0; mAvatarShot.removeMovieClip(); mAvatar.gotoAndStop(1); } } } // ////////////////////////////////////////////// // ///////////////// Enemigos ///////////////// // ////////////////////////////////////////////// // Cuando llega a 100 puede que se inserte un enemigo: EnemigosTurn = 0; // Determina qué tan rápido aumenta EnemigosTurn y... // la máxima cantidad de enemigos: EnemigosRate = 10; MinEnemigoSpeed = 0.1; // MaxEnemigoSpeed = 0.2; EnemigosBestEffect = 0; EnemigosMinEffect = 0; // EnemigosMaxEffect = 0; EnemigosIA = 0; // Para saber qué depth asignar cuando se debe insertar un enemigo: LdeProfundidadesDisponibles = []; do { LdeProfundidadesDisponibles.push(LdeProfundidadesDisponibles.length+1); } while (LdeProfundidadesDisponibles.length<EnemigosRate); function AddEnemigos () { EnemigosTurn = EnemigosTurn+EnemigosRate; while (LdeProfundidadesDisponibles.length>0 && EnemigosTurn>=100) { EnemigosTurn = EnemigosTurn-100; // Se le asigna la última profundidad disponible porque... // asignar la 1era implica mover hacia ella a las posteriores: LastProfundidadDisponible = LdeProfundidadesDisponibles[LdeProfundidadesDisponibles.length-1]; Name = "mEnemigo"+LastProfundidadDisponible; attachMovie("sDKBarril", Name, LastProfundidadDisponible); // Referencia más directa: Name = _root[Name]; Name._x = Math.random()*320; // Para zigzaguear: Name.MinX = Name._x-Math.random()*EnemigosRate; Name.MaxX = Name._x+Math.random()*EnemigosRate; Name._y = -50; // ojo esto depende del tipo de enemigo Name.Area1._visible = false; Name.Area2._visible = false; Name.Area3._visible = false; Name.SpeedX = Math.random()*MinEnemigoSpeed*(random(2)*2-1); Name.SpeedY = Math.random()*MinEnemigoSpeed+MinEnemigoSpeed; // Borra el último elemento de la lista: LdeProfundidadesDisponibles.pop(); } } function MoveEnemigos () { EnemigoaMover = 0; while (EnemigoaMover<EnemigosRate) { EnemigoaMover++; Name = _root["mEnemigo"+EnemigoaMover]; Name._x = Name._x+Name.SpeedX; if (Name._x<-50 or Name._x>370) { removeMovieClip ("mEnemigo"+EnemigoaMover); LdeProfundidadesDisponibles.push(EnemigoaMover); } else { if (Name._x<Name.MinX) { Name._x = Name.MinX; Name.SpeedX = Name.SpeedX*-1; } else if (Name._x>Name.MaxX) { Name._x = Name.MaxX; Name.SpeedX = Name.SpeedX*-1; } Name._y = Name._y+Name.SpeedY; if (Name._y>290) { removeMovieClip ("mEnemigo"+EnemigoaMover); LdeProfundidadesDisponibles.push(EnemigoaMover); } else { // Se verá si un área enemiga toca algo relevante: TocaDisparo = "No"; NroDeAreaEnemiga = 1; do { AreaaChequear = Name["Area"+NroDeAreaEnemiga]; // Al avatar (a alguna de sus áreas): NroDeAreaDeAvatar = 1; do { if (mAvatar["Area"+NroDeAreaDeAvatar].hitTest(AreaaChequear) == true) { trace ("NroDeAreaEnemiga "+NroDeAreaEnemiga+" tocó "+NroDeAreaDeAvatar); // Game over: NroDeAreaDeAvatar = 9; NroDeAreaEnemiga = 4; gotoAndStop (3); } NroDeAreaDeAvatar++; } while (NroDeAreaDeAvatar<9); // Al disparo del avatar: if (mAvatarShot.hitTest(AreaaChequear) == true) { trace ("NroDeAreaEnemiga "+NroDeAreaEnemiga+" tocó "+mAvatarShot); TocaDisparo = "Sí"; } NroDeAreaEnemiga++; } while (NroDeAreaEnemiga<4); if (TocaDisparo == "Sí") { removeMovieClip ("mEnemigo"+EnemigoaMover); LdeProfundidadesDisponibles.push(EnemigoaMover); EnemigosRate++; MinEnemigoSpeed = MinEnemigoSpeed+0.01; LdeProfundidadesDisponibles.push(LdeProfundidadesDisponibles.length+1); } } } } }





Autor



En línea
