Este artigo descreve o código-fonte de lutador cósmico de mini-jogos JS e é compartilhado com você para sua referência. A introdução específica é a seguinte:
1. Introdução ao jogo:
Este é um jogo de tiro voador, vertical, com um total de seis níveis.
2. Requisitos de jogo:
1. O lutador pode disparar balas e as balas podem ser atualizadas com a obtenção de adereços.
2. O lutador pode ser colocado em bombas, e o número de adereços pode ser obtido pode ser aumentado.
3. Os jatos de caça podem acumular poder para atacar.
4. Existem três tipos de canais, a saber, atualizar as balas, aumentar o número de bombas e aumentar o número de caças.
5. Cada nível tem música diferente.
6. O jato de caça é abatido e depois entra no campo de batalha e está em um estado protegido.
7. Aeronaves inimigas AI Design.
O jogo é executado como mostrado na figura abaixo:
Clique aqui para baixar o código de exemplo completo .
3. JavaScript Código Fonte Parte:
/** Fighter Cosmic* Autor: FDIPZONE* Data: 2013-02-12* Ver: 1.0*/window.onload = function () {var gameImg = ['Images/Fighter.png', 'Images/Fighter_p.png', 'imagens/fighter_sg','.s/fighter_pter_p.png ', imagens/fighter_sg','.s/fighter_pter_p ',' imagens/fighter_sng ','. 'Images/Fighter_s.png', 'Images/Shot.png', 'Images/Destroy.png', 'Images/Destroy.png', 'Images/Enemy.png', 'Images/Bullet.png', 'Images/Gift.png', 'Images/Bomb.png', 'imagens/boss/boss1.p.nng'g', imagens/bomba ',' imagens/boss/boss1.png'g ',' imagens/bomba ',' imagens/boss/boss1.png'g ',' imagens/bomb.png ',' imagens/boss/boss1.p.nng'g ',' imagens/bomb.png ',' imagens/boss/boss1.p.nng; var de chamada var = function () {var planela = $ ('jogo de jogo'); Fighter.init (); Fighter.bgmove (plano de jogo); } img_preload (gameImg, retorno de chamada);};/** classe de caça*/var caça = (function () {var hiscore = 10000; // a pontuação mais alta var score = 0; // a pontuação atual var ft = 3; // o número de fighting/bombnum = 3; Iniciado var keypriority = {}; // The conflict key priority var gamekey = [37,38,39,40,83,65]; // The game's key var scoretag = [0,20,30,40,50,60,500]; // The score of different enemy aircraft var level = 1; // The level var power = 1; // The power of the fighter bullet var cheatcode = []; // Record cheat falha de entrada var = 0; 'STEP': 30}, {'armadura': 2500, 'esquerda': 136, 'top':-169, 'step': 30}, {'armadura': 3000, 'esquerda': 136, 'top':-169, 'step': 30},]; // a aeronave inimiga que aparece varia de dados inimigos do inimigo = []; // O chefe var curboss aparece atualmente var curboss = null; // Level data var map = [ // level 1 { 'ms50':[[3, 680, 1, -50, 10, 10],[3, 680, 1, -50, 290, 10]], 'ms2500':[[3, 800, 2, 200, 450, -10]], 'ms8000':[[1, 10, 12, -23, 190, 10]], 'MS9500': [[[3, 800, 2, 200, 450, -10]], 'ms8000': [[1, 10, 11, -23, 100, 10]], 'ms9500': [[3, 800: 2, 200, 450, -10], 'ms8000': [[1, 10, 11, 200, 100, -23, 450, -10], 'MS8000': [[1, 10, 11, 200, 100, -23, 450, -10], 'ms8000': [[1, 10, 11, 200, 100, -23, 450, -10], 'ms8000': [[1, 10, 11, 200, 100, -23, 450, -10], 'ms8000': [[1, 10, 11, 200, 100, -23, 450, -10], 'MS8000': [[1, 10, 11, 200, 100, -450, -10], 'MS8000': -50, 10]], 'MS11500': [[3, 800, 2, 200, 450, -10]], 'MS13500': [[[3, 800, 2, 100, -50, 10]], 'MS15500': [3, 800, 3, 3, 30, 10]], 'MS2500': 'ms20000':[[3, 800, 3, -50, 90, 10]], 'ms25000':[[1, 10, 4, 150, -50, 280, 10]], 'ms25000':[[1, 10, 4, 150, -50, 280, 10]], 'ms25000':[[1, 10, 4, 150, -50, 10],[1, 10, 4, 250, 400, -10],[1, 10, 4, 100, 400, -10]], 'ms30000':[[3, 800, 5, 692, 90, -10],[3, 800, 5, 692, 280, -10]], 'ms35000':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms38000':[[1, 10, 11, -23, 10, 10]], 'ms40000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms42500':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'MS45500': [[3, 800, 2, 150, 450, -10]], 'MS49500': [[3, 800, 2, 50, -50, 10]], 'MS51500': [3, 800, 2, 150, 450, -10], 'MS4900': 'ms51500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 3, -50, 90, 10],[3, 800, 3, -50, 280, 10]], 'ms60000':[[3, 800, 3, -50, 30, 10]], 'ms65000':[[3, 800, 3, -50, 30, 10]], 'ms65000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms68000':[[3, 800, 5, 692, 110, -10],[3, 800, 5, 692, 260, -10]], 'ms71000':[[1, 10, 13, -23, 220, 10]], 'ms76000':[] }, // level 2 { 'ms50':[[3, 680, 1, -50, 10, 10],[3, 680, 1, -50, 290, 10]], 'ms2500':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms3500':[[1, 10, 12, -23, 190, 10]], 'ms5500':[[3, 800, 2, 100, -50, 10]], 'ms7500':[[3, 800, 2, 200, 450, -10]], 'ms8000':[[1, 10, 11, -23, 100, 10]], 'ms9500':[[3, 800, 2, 100, -50, 10]], 'ms11500':[[3, 800, 2, 200, 450, -10]], 'ms13500':[[3, 800, 2, 100, -50, 10]], 'ms15500':[[3, 800, 3, -50, 30, 10],[3, 800, 3, -50, 340, 10]], 'ms20000':[[3, 800, 3, -50, 90, 10], [3, 800, 3, -50, 280, 10]], 'ms35000': [[[1, 10, 4, 150, -50, 10], [1, 10, 4, 250, 400, -10]], 'MS30000': [[3, 800, 5, 692, 90], –10], 'ms3': -10]], 'ms35000': [[3, 680, 1, -50, 70, 10], [3, 680, 1, -50, 220, 10]], 'ms45500': [[1, 10, 11, -23, 10, 10], 'MS4500': 'ms42500':[[3, 680, 1, -50, 70, 10], 'ms45500':[[3, 680, 1, -50, 70, 10]], 'ms45500':[[3, 800, 2, 50, -50, 10]], 'ms47500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 50, -50, 10]], 'ms51500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 3, -50, 90, 10]], 'ms60000':[[3, 800, 3, -50, 30, 10]], 'ms65000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms68000':[[3, 800, 5, 692, 110, -10],[3, 800, 5, 692, 260, -10]], 'ms71000':[[1, 10, 13, -23, 220, 10]], 'ms76000':[] }, // level 3 { 'ms50':[[3, 680, 1, -50, 10, 10],[3, 680, 1, -50, 10]], 'ms2500':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms3500':[[1, 10, 12, -23, 190, 10]], 'ms5500':[[3, 800, 2, 100, -50, 10]], 'ms7500':[[3, 800, 2, 200, 450, -10]], 'ms8000':[[1, 10, 11, -23, 100, 10]], 'ms9500':[[3, 800, 2, 100, -50, 10]], 'ms11500':[[3, 800, 2, 200, 450, -10]], 'ms13500':[[3, 800, 2, 100, -50, 10]], 'ms15500':[[3, 800, 3, -50, 30, 10]], 'ms20000':[[3, 800, 3, -50, 90, 10]], 'ms25000':[[1, 10, 4, 150, -50, 10],[1, 10, 4, 250, 400, -10],[1, 10, 4, 100, 400, -10]], 'ms30000':[[3, 800, 5, 692, 90, -10],[3, 800, 5, 692, 280, -10]], 'ms35000':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms38000':[[1, 10, 11, -23, 10, 10]], 'ms40000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms42500':[[3, 800, 2, 50, -50, 10]], 'ms42500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 50, -50, 10]], 'ms51500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 2, 50, -50, 10]], 'ms51500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 3, -50, 90, 10],[3, 800, 3, -50, 280, 10]], 'ms60000':[[3, 800, 3, -50, 30, 10], 'ms65000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms68000':[[3, 800, 5, 692, 110, -10],[3, 800, 5, 692, 260, -10]], 'ms71000':[[1, 10, 13, -23, 220, 10]], 'ms76000':[] }, // level 4 { 'ms50':[[3, 680, 1, -50, 10, 10],[3, 680, 1, -50, 290, 10]], 'ms2500':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms3500':[[1, 10, 12, -23, 190, 10]], 'ms5500':[[3, 800, 2, 100, -50, 10]], 'ms7500':[[3, 800, 2, 200, 450, -10]], 'ms13500':[[3, 800, 2, 100, -50, 10]], 'ms15500':[[3, 800, 2, 100, -50, 10]], 'MS15500': [[3, 800, 2, 100, -50, 10]], 'MS15500': [[3, 800, 3, -50, 30, 10]], 'MS11500': [[3, 800, 3, -50, 340, 10], MS11500 ': [[3, 800, 3, -50, 340, 10], ms 800, 3, -50, 280, 10]], 'MS35000': [[1, 10, 4, 150, -50, 10], [1, 10, 4, 250, 400, -10], 'MS30000': [3, 800, 5, 692, 90, -10]], 'MS35000': 'ms35000':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms45500':[[1, 10, 11, -23, 10, 10]], 'ms40000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms42500':[[3, 680, 1, -50, 70, 10], 'ms45500':[[3, 680, 1, -50, 220, 10]], 'ms45500':[[3, 800, 2, 50, -50, 10]], 'ms47500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 50, -50, 10]], 'ms51500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 3, -50, 90, 10]], 'ms60000':[[3, 800, 3, -50, 30, 10]], 'ms65000':[[3, 800, 3, -50, 30, 10]], 'ms65000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms68000':[[3, 800, 5, 692, 110, -10],[3, 800, 5, 692, 260, -10]], 'ms71000':[[1, 10, 13, -23, 220, 10]], 'ms76000':[] }, // level 5 { 'ms50':[[3, 680, 1, -50, 10],[3, 680, 1, -50, 290, 10]], 'ms2500':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'MS3500': [[[1, 10, 12, -23, 190, 10]], 'MS5500': [[3, 800, 2, 100, -50, 10]], 'ms7500': [[[3, 800, 2, 200, 450, -10], 'ms8000': [[[1, 10, 11, 2, 200, 100, -10], 'ms8000': [[1, 10, 11, 2, 2, 200, -450, -10], 'Ms8000': 100, -50, 10]], 'ms11500':[[3, 800, 2, 200, 450, -10]], 'ms13500':[[3, 800, 2, 100, -50, 10]], 'ms15500':[[3, 800, 3, -50, 30, 10],[3, 800, 3, -50, 340, 10]], 'ms20000':[[3, 800, 3, -50, 90, 10], 'ms25000':[[1, 10, 4, 150, -50, 10],[1, 10, 4, 250, 400, -10],[1, 10, 4, 100, 400, -10]], 'ms30000':[[3, 800, 5, 692, 90, -10],[3, 800, 5, 692, 280, -10]], 'ms35000':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms38000':[[1, 10, 11, -23, 10, 10]], 'ms40000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms42500':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'ms45500':[[3, 800, 2, 50, -50, 10]], 'ms47500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 50, -50, 10]], 'ms51500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 3, -50, 90, 10],[3, 800, 3, -50, 280, 10]], 'ms60000':[[3, 800, 3, -50, 30, 10],[3, 800, 3, -50, 340, 10]], 'ms65000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms68000':[[3, 800, 5, 692, 110, -10],[3, 800, 5, 692, 260, -10]], 'ms71000':[[1, 10, 13, -23, 220, 10]], 'ms76000':[] }, // level 6 { 'ms50':[[3, 680, 1, -50, 10, 10],[3, 680, 1, -50, 290, 10]], 'ms7500':[[3, 680, 1, -50, 70, 10],[3, 680, 1, -50, 220, 10]], 'MS3500': [[[1, 10, 12, -23, 190, 10]], 'MS5500': [[3, 800, 2, 100, -50, 10]], 'ms7500': [[[3, 800, 2, 200, 450, -10], 'ms8000': [[[1, 10, 11, 2, 200, 100, -10], 'ms8000': [[1, 10, 11, 2, 2, 200, -450, -10], 'Ms8000': 100, -50, 10]], 'ms11500':[[3, 800, 2, 200, 450, -10]], 'ms13500':[[3, 800, 2, 100, -50, 10]], 'ms15500':[[3, 800, 3, -50, 30, 10]], 'ms20000':[[3, 800, 3, -50, 90, 10]], 'ms15500':[[3, 800, 3, -50, 30, 10]], 'ms20000':[[3, 800, 3, -50, 90, 10]], 'ms15500':[[3, 800, 3, -50, 30, 10]], 'ms20000':[[3, 800, 3, -50, 90, 10],[3, 800, 3, -50, 280, '],' Ms35000 ': [[1, 10, 4, 150, -50, 10], [1, 10, 4, 250, 400, -10], [1, 10, 4, 100, 400, -10]],' MS30000 ': [[3, 800, 5, 692, 90, -10] -MS300': [[3, 800, 5, 692, 90, -10], MS300 ': 10],[3, 680, 1, -50, 220, 10]], 'ms42500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 150, 450, -10]], 'ms49500':[[3, 800, 2, 50, -50, 10]], 'ms51500':[[3, 800, 2, 150, 450, -10]], 'ms55500':[[3, 800, 3, -50, 90, 10],[3, 800, 3, -50, 280, 10]], 'ms60000':[[3, 800, 3, -50, 30, 10]], 'ms65000':[[1, 10, 4, 100, 400, -10],[1, 10, 4, 300, -50, 10]], 'ms68000':[[3, 800, 5, 692, 110, -10],[3, 800, 5, 692, 260, -10]], 'MS71000': [[[1, 10, 13, -23, 220, 10]], 'MS76000': []}]; // inicialize init = function () {ft = $ ('lightter'); reiniciar(); key_event (); } // Inicie o jogo start = function () {is_clear = 0; is_protect = 0; disp (ft.id, 'show'); reset_fighter (); reset_pile (); processo(); bgsound (nível, verdadeiro); bgchange (nível); Fightter_init (); } // Definir event key_event = function () {document.onkeydown = function (e) {var e = e || Window.Event; varkey = e.KeyCode || e. Qual || E.Charcode; if (is_start == 0) {if (Cheatcode.Length> 12) {Cheatcode.shift (); } Cheatcode.push (Curkey); // Registre a entrada do Cheatcode pelo usuário} if (is_start == 1 && in_array (CURKEY, GAMEKEY)) {if (ackey [CUKEKY.TOSTRING ()] == 0 || Typeof (ACKEKY [CURKY.ToString ()]) == '' Underfil ackey [curkey.toString ()] = 1; // Salvar o comutador de chave para baixo (CURKY) {Caso 37: Caso 39: keypriority.left = CURKY; // pausa esquerda à direita; Caso 38: Caso 40: KeyPriority.top = Curkey; // rura para baixo; }} else {return false; }} if (curkey == 13 || is_start == 1 && is_lock == 0) {// jogo é inicial ou key = 13 switch (curke) {case 13: // enter if (is_start == 0) {is_start = 1; disp ('op', 'hide'); msg_show (); setTimeout (function () {msg_hide (); Cheat (); start ();}, 1500); } quebrar; caso 83: // tiro de tiro (); quebrar; caso 65: // bomba -bomba (); quebrar; }}} document.onKeyup = function (e) {var e = e || Window.Event; varkey = e.KeyCode || e. Qual || E.Charcode; if (is_start == 1 && in_array (CURKY, GameKey)) {ackey [CURKEY.TOSTRING ()] = 0; // Chave de liberação para baixo if (CURKY == 83) {// Libere o ataque de energia if (is_pile == 1) {pile_shot (); } reset_pile (); }}}} // ação executada por loop = function () {var movSeStep = 5; // Mover tamanho da etapa var et = setInterval (function () {if (is_start == 0 || is_lock == 1) {clearInterval (et);} // mova if (ackey ['37 '] == 1 && (Ackey ['39'] == 0 || keyPriority.Left == 37) {prioridade ['39 '] == 0 | if (getPosition (ft, 'esquerda') <Movestep) {setPosition (ft, 'esquerda', 0); if (getPosition (ft, 'top') <Movestep) {setPosition (ft, 'top', 0); if (400- (getPosition (ft, 'esquerda') + 50) <MoveStep) {setPosition (ft, 'esquerda', 350); ||. }} // Charge Attack if (ackey ['83 '] == 1) {if (pilenum <1000) {pipeline = pipelineum + 20; } else if (is_pile == 0) {is_pile = 1; if (is_protect == 1) {setClass (ft, 'fighther_s'); } else {setClass (ft, 'lightter_s'); }}}}}}}}}}}}, 20); } // tiro de caça tiro = function () {// crie bullet var bullet = document.createElement ('div'); var offsetx; switch (power) {case 1: offsetx = 20; quebrar; Caso 2: offsetx = 15; quebrar; Caso 3: offsetx = 10; quebrar; Caso 4: offsetx = 4; quebrar; } setClass (Bullet, 'Shot' + Power); // Defina a posição inicial do setPosition (Bullet, 'Top', GetPosition (ft, 'top')-30); setPosition (Bullet, 'Left', GetPosition (ft, 'Esquerda') + OffsetX); ft.parentnode.appendChild (bala); // defina o movimento da bala var et = setInterval (function () {if (getPosition (bala, 'top') <=-30 || is_lock == 1) {clearInterval (et); ft.parentnode.removeChild (bala); // libere bullet} para (var i = 0; i <inimigo (inimigo. se inimigo [i]! if (Curboss! 'top')-15); setClass (PileBullet, 'Pilhot'); // Defina a posição inicial da Bullet SetPosition (PileBullet, 'Top', GetPosition (ft, 'top')-30); setPosition (pilebullet, 'esquerda', getPosition (ft, 'esquerda')); ft.parentnode.appendChild (pilebullet); var et = setInterval (function () {if (getPosition (pilebullet, 'top') <=-85 || is_lock == 1) {clearInterval (et); ft.parentnode.removeChild (pilebullet); // libere o bullet} para (var i = 0; i <iniMydata. se (inimigo, [i]! if (Impact (PileBullet, Curboss ['obj'])) {// Hit The Boss Curboss ['Armour'] = Parseint (Curboss ['armadura']-100; 'top')-20); bombnum -; Sethtml ('Bombnum', Bombnum); // decremento em 1 var opacidade = 100; Setopacity ($ ('bomba'), opacidade); disp ('bomba', 'show'); // limpe todos os aviões inimigos e balas inimigas is_clear = 1; // ataque de ataque if (curboss! = Null) {curboss ['armadura'] = parseint (curboss ['armadura'])-300; } var step = 0; var et = setInterval (function () {// bomba efeito if (etapa <11) {setbgPosition ($ ('bomba'), 0, etapa*(-280));} else {clearInterval (et); disp ('bomba', 'hide'); is_bombing = 0; is_clear = 0;} step ++;}; }} // Process de jogo Process = function () {var LevelData = map [Nível 1], Processado = 0, Etapa = 10; var niveSTep = 0; // limpe 0 para cada nível var et = setInterval (function () {if (is_lock == 0) {processado+= step; if (attCount (nívelData)> nívelSTep) {// este nível não foi concluído se (niveldata ['ms'+processado]) {para (var i = 0; NívelData ['MS'+Processado] [i]; }/* Crie elementos de nível/* msData: {num: o número de ocorrências intervalo: intervalo: intervalo: tipo: tipo superior: coordenada superior original esquerda: etapa da coordenada esquerda original: distância do movimento}*/create = function (msData) {var num = msData [0], interval = msdata [1], tipo = type = msDA = msData [0], interval = msData [1], TIPO) {VAR msData [4], Step = msData [5]; var et = setInterval (function () {if (num> 0) {var enft = document.createElement ('div'); setClass (enft, 'elemento' + tipo); enft.type = tipo; setPosition (ENFT, 'top', top); setPosition (ENFT, esquerda ', esquerda); Ft.ParnNeN, Enemydata.push (enft); } // Rota de trilha de movimento do elemento = função (ENFT, tipo, etapa) {var et = null; switch (type) {case 1: // curve var count = 0; et = setInterval (function () {if (node_exist (ENFT)) {setPosition (ENFT, 'top', getPosition (ENFT, 'top')+math.abs (step)); setPosition (ENFT, 'esquerda', getPosition (enft, 'esquerd')+step); 'Top')> 640 ||. quebrar; Caso 2: // Horizontal var count = 0; ET = setInterval (function () {if (node_exist (ENFT)) {setPosition (ENFT, 'esquerda', getPosition (ENFT, 'esquerda')+etapa); contagem <9? count ++: (count = 0, ataque (ENFT, 1,17,47); se (getPosition (ENFT (fet '> 400 400 400 e 1,17,47); if (getPosition (ENFT (LEFT') Etapa <0 ||. quebrar; Caso 3: // Var vertical contagem = 0; et = setInterval (function () {if (node_exist (enft)) {setPosition (enft, 'top', getPosition (enft, 'top')+etapa); count <9? count ++: (count = 0, Attack (ENFT, 1,17,47); se (inft (inft), 1. ClearInterval (ET); quebrar; Caso 4: // Ataque de movimento do loop esquerdo e direito Var count = 0; ET = setInterval (function () {if (node_exist (ENFT)) {setPosition (ENFT, 'esquerda', getPosition (ENFT, 'esquerda')+etapa); count <10? count ++: (count = 0, ataque (ENFT, 4,17,31); && Etapa <0) {Etapa*=-1; quebrar; Caso 5: // ataque por trás de var count = 0; et = setInterval (function () {if (node_exist (enft)) {setPosition (enft, 'top', getPosition (enft, 'top')+etapa); count <9? count ++: (count = 0, ataque (inft, 1,17, -17); ClearInterval (ET); quebrar; Caso 11: // Power Gift Var count = 0; et = setInterval (function () {if (node_exist (ENFT)) {setPosition (ENFT, 'top', getPosition (ENFT, 'top')+math.abs (step)); setPosition (ENFT, 'esquerda', getPosition (enft, 'esquerd')+step); 'Top')> 640 ||. ClearInterval (ET);}}, 80); quebrar; Caso 12: // Bomb Gift Var count = 0; et = setInterval (function () {if (node_exist (ENFT)) {setPosition (ENFT, 'top', getPosition (ENFT, 'top')+math.abs (step)); setPosition (ENFT, 'esquerda', getPosition (enft, 'esquerd')+step); 'Top')> 640 ||. ClearInterval (ET);}}, 80); quebrar; Caso 13: // Presente de caça var count = 0; et = setInterval (function () {if (node_exist (ENFT)) {setPosition (ENFT, 'top', getPosition (ENFT, 'top')+math.abs (step)); setPosition (ENFT, 'esquerda', getPosition (enft, 'esquerd')+step); 'Top')> 640 ||. ClearInterval (ET);}}, 80); quebrar; }} // Destrut Destroy = function (DOBJ) {// DOBJ: O objeto destruído var dest = document.createElement ('div'); setclass (dest, 'destruir'); setPosition (dest, 'top', getPosition (Dobj, 'top')); setPosition (dest, 'esquerda', getPosition (Dobj, 'Esquerda')); ft.parentnode.appendChild (dest); if (Dobj.id == 'Fighter') {// O lutador foi atingido disp (Dobj.id, 'Hide'); potência = 1; bombnum = 3; Fightnum--; Sethtml ('Fightternum', Fightnum); Sethtml ('Bombnum', Bombnum); is_lock = 1; } else {Dobj.parentnode.removeChild (Dobj); } var step = 0; var et = setInterval (function () {if (etapa <11) {setBgPosition (dest, etapa*(-48), 0); passo ++;} else {if (DOBJ.id == 'Fighter') {Settimeout (function () {if (Fighttern> 0) {LevelContinue ();}; Curboss [obj ']; } // Boss War Bosswar = function () {var Boss = BossData [Nível 1]; var bossft = document.createElement ('div'); setClass (Bossft, 'Boss' + nível); setPosition (Bossft, 'Esquerda', Boss ['Esquerda']); setPosition (Bossft, 'Top', Boss ['top']); ft.parentnode.appendChild (Bossft); curboss = {"armadura": chefe ['armadura'], "obj": bossft}; Switch (nível) {Caso 1: // Boss 1 Caso 2: // Boss 2 Caso 3: // Boss 3 Caso 4: // Boss 4 Caso 5: // Boss 5 Caso 6: // Boss 6 Var Etapa = -3; var count = 0; var et = setInterval (function () {if (getPosition (bossft, 'top') <50) {// boss insere setPosition (bossft, 'top', getPosition (bossft, 'top')+5);} elsen) {if (curboss ['Armor'] <= 0) {// chefe do clearInterval (et); (GetPosition (Bossft, 'Esquerda')> 10) {setPosition (Bossft, 'Esquerda', GetPosition (Bossft, 'Esquerda')+Etapa); } else {step*=-1; count%100 == 0) {ataque (Bossft, 3, 60, 92); quebrar; }} / * ataque * Obj aeronave inimiga * Tipo de ataque * Bullet esquerda Inicial esquerda * Bullet superior superior * / ataque = função (obj, tipo, esquerda, topo) {if (is_lock == 1) {return false; // Se bloqueado, não atire} var oleft = getPosition (obj, 'esquerda')+esquerda; var top = getPosition (obj, 'top')+top; switch (type) {case 1: // Attack no lutador // A posição inicial da bala e a posição do lutador var oppoint = {x: oleft+7, y: otop+7}; var dpoint = {x: getPosition (ft, 'esquerda')+25, y: getPosition (ft, 'top')+25}; var p = vetor (opoint, dpoint, 8); enftbullet ('bala', oleft, top, p [0], p [1], 35); quebrar; caso 2: // ataque reto var num = 3; var st = setInterval (function () {if (num> 0) {enftbullet ('bullet', oleft, top, 0, 8, 35); num -;} else {ClearInterval (st);}}, 150); quebrar; caso 3: // ataque de dispersão var num = 3; var st = setInterval (function () {if (num> 0) {switch (num) {case 1: enftbullet ('sbullet', oleft, top, 0, 8, 35); quebra; case 2: enftbullet ('sbullet', oleft, topop, 3, 8, 35); quebra; 8, 35); quebrar; Caso 4: // Ataque de dispersão pequena var num = 3; var st = setInterval(function(){ if(num>0){ switch(num){ case 1: enftbullet('bullet', oleft, topop, 0, 8, 35); break; case 2: enftbullet('bullet', oleft, top, 3, 8, 35); break; case 3: enftbullet('bullet', oleft, top, -3, 8, 35); break; } num -; quebrar; }} / * ENFT Bullet * Tipo Bullet Tipo * OLEFT, Posição inicial da bala superior * esquerda, bala superior * velocidade * / enftbullet = function (type, oleft, topo, esquerda, superior, velocidade) {var bullet = document.createElement ('div'); setClass (bala, tipo); setPosition (Bullet, 'Esquerda', Oleft); setPosition (Bullet, 'Top', Top); ft.parentnode.appendChild (bala); var et = setInterval (function () {setPosition (bala, 'top', getPosition (bullet, 'top')+topo); setPosition (Bullet, 'Esquerda', GetPosition (Bullet, 'Esquerda')+Esquerda); if (getPosition (Bullet, 'esquerda')> 400 || getPoition (Topo ') <fret) <-30h. getPosition (Bullet, 'Top')> 640 ||. } // Boss Over Boss = function () {obj = Curboss ['obj']; obj.parentnode.removeChild (obj); pontuação (6); // Pontuação do chefe var dest = document.createElement ('div'); setClass (dest, 'DestroyBoss'); setPosition (dest, 'top', getPosition (obj, 'top')); setPosition (dest, 'esquerda', getPosition (obj, 'esquerda')); ft.parentnode.appendChild (dest); var stage = 0; var et = setInterval (function () {if (etapa <21) {setBgPosition (dest, etapa*(-150), 0);} else if (step == 21) {dest.parentnode.removeChild (dest);} else if (step == 50) {clearinterval (et); Levelup ();}; } // Continue LevelContinue = function () {reset_fighter (); disp (ft.id, 'show'); setProtect (); Fightter_init (); } // passa nível de nível = function () {keypriority = {}; Enemydata = []; curboss = nulo; nível ++; bgsound ('passa', falso); var processado = 0; var et = setInterval (function () {is_lock = 1; processado = processado + 15; if (getPosition (ft, 'top')>-50) {setPosition (ft, 'top', getPosition (ft, 'top')-15);} if (processado> = 2500) {clearInterval (et); bgchange (0); } // update scoreup = function (type) {if (typeof (scoretag [type])! = 'indefinido') {score = score + scoretag [tipo] * nível; Sethtml ('Score', Score); if (pontuação> hiscore) {hiscore = score; sethtml ('hiscore', hiscore); }}} // Upgrade de bala PowerUp = function () {Power = Power+1> 4? 4: potência+1; } // bomba aumente bombop = function () {bombnum ++; Sethtml ('Bombnum', Bombnum); } // Fighter aumenta o lutador up = function () {fighternum ++; Sethtml ('Fightternum', Fightern); } // status de proteção setProtect = function () {is_protect = 1; if (is_pile == 1) {setClass (ft, 'fighther_sp'); } else {setClass (ft, 'fighter_p'); } setTimeout (function () {is_Protect = 0; if (is_pile == 1) {setClass (ft, 'lighther_s');} else {setClass (ft, 'lightter');}}, 3000)} // Processamento de colisão IFF (FUNHANDLE = (FUNÇÃO (OBJ, et)} {3000)} // Processamento de colisão; is_lock == 0) {// colisão gerada if (is_protect == 0) {Destroy (ft); ClearInterval (ET); ft.parentnode.removeChild (obj); }}} // Toda a liberação gameclear = function () {is_over = 1; disp ('gameclear', 'show'); Sethtml ('ClearCon', 'Game Clear' + '<br>' + 'Score:' + pontuação); bgsound ('claro', falso); bgchange ('claro'); setTimeout (function () {bgsound (); init ();}, 16000); } // final do jogo gameover = function () {is_over = 1; disp ('gameover', 'show'); sethtml ('overcon', 'nível:' + nível + '<br>' + 'pontuação:' + pontuação); bgsound ('sobre', falso); BGCHANGE ('Over'); FailTimes ++; setTimeout (function () {if (FailTimes == 3) {alert ('digite ↑ ↑ icionça ← → ← → Asaas, inicie o jogo novamente e haverá surpresas^_^');} bgSound (); init ();}, 8000); } // Mostrar mensagem msg_show = function () {sethtml ('nível', 'nível -' + nível); disp ('nível', 'show'); is_lock = 1; } // ocultar mensagem msg_hide = function () {disp ('nível', 'hide'); } // redefinir reset = function () {is_start = 0; is_bombing = 0; is_lock = 1; is_over = 0; is_clear = 0; is_protect = 0; nível = 1; potência = 1; ackey = {}; keypriority = {}; Enemydata = []; pontuação = 0; Fightenum = 3; bombnum = 3; sethtml ('hiscore', hiscore); Sethtml ('Score', Score); Sethtml ('Fightternum', Fightenum); Sethtml ('Bombnum', Bombnum); reset_fighter (); reset_pile (); disp ('op', 'show'); disp ('gameover', 'hide'); disp ('gameclear', 'hide'); bgchange (0); } // Redefinir a posição do lutador reset_fighter = function () {setPosition (ft, 'top', 640); setPosition (ft, 'esquerda', 175); setClass (ft, 'lutador'); } // Redefinir carregamento reset_pile = function () {is_pile = 0; pilenum = 0; if (is_protect == 1) {setClass (ft, 'fighther_p'); } else {setClass (ft, 'lutador'); }} // Fighter Inicialização Fighter_init = function () {var et = setInterval (function () {if (getPosition (ft, 'top')> 400) {setPosition (ft, 'top', getPosition (ft, 'top')-12);}; } // Habilidade secreta 30 Life Cheat = function () {if (Cheatcode.join (',') == '38,38,40,40,37,39,37,39,65,83,65,83,13') {Fightenum = 30; Sethtml ('Fighternum', Fightnum); } Cheatcode = []; } // Controle de fundo bgmove = function (obj) {var step = 1; var et = setInterval (function () {var bgpos = getBgPosition (obj); if (bgpos ['top'] == 640) {setBgPosition (obj, 0, 0); // reset} else {setBgPosition (obj, bgpos ['left'], bgpos ['top' '' '' '};' top '' '' '' '};' '' '' '' '{'); '} mais {SetbgPosition (obj, bgpos [' left '], bgpos [' top '' '' '' '};'); } // comutação de fundo bgChange = function (arquivo) {var obj = $ ('jogo de jogo'); setClass (obj, 'jogo bg'+arquivo); } // Music Control bgsound = function (arquivo, loop) {var id = 'AudioPlayer'; if (typeof (file)! = 'indefinido') {if (typeof (loop) == 'indefinido') {loop = false; } var Audiofile = []; audiofile ['mp3'] = 'music/' file + '.mp3'; Audiofile ['Ogg'] = 'Music/' File + '.Ogg'; AudioPlayer (ID, Audiofile, Loop); } else {Audioplayer (id); }} return th This;}) ();相信本文所述对大家javascript游戏设计有一定的借鉴价值。