Sign in with
Sign up | Sign in
Your question

Koli's Curse - J2ME Game with problems

Last response: in Applications
Share
August 12, 2010 6:21:01 PM

Hello.

I have a college game project for J2me - Java Mobile. It's actually in Portuguese now, but I plan on doing the english version in the end (who knows, if I find people to translate it, it can have even more...).

Thing is, it's kinda ready. For those who know programming (I don't do a lot, but oh well...), what I am trying to do is to offload the classes off the main game class. I succeed in parts.

Why? Well, I was able to offload the monster class, and it works, but the image is not being shown, so there's monsters on the screen, but they are invisible. You can hit them, kill them and go to the next stage, but you can't see them at all.

I don't know if I should post the code here, since it's over 1000 lines... But I will anyway so you guys can help me...

MaldicaoKoli.txt - This is the game.

Spoiler
  1. import javax.microedition.lcdui.game.GameCanvas;
  2. import javax.microedition.lcdui.game.Sprite;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.rms.*;
  5. import java.io.IOException;
  6.  
  7. /*
  8. * @author José.Ricardo.Carvalho.Prado.de.Almeida
  9. */
  10. public class MaldicaoKoli extends GameCanvas implements Runnable {
  11.  
  12. public MKSetUp midlet;
  13. //
  14. static Sprite superZombies[];
  15. static Sprite zombies[]=new Sprite[6];
  16. Sprite fogofim;
  17. static Sprite protex;
  18. Sprite heroi;
  19. Sprite mira;
  20. Sprite fogo;
  21. //
  22. //
  23. static int contempo = 0;
  24. static int contvidaH = 1600, contvida, zMorteQt, zMorte, hstate;
  25. static int qtdeZumbiM, qtdeSZumbiM, ResultadoSZ, SzMorte, SzMorteQt;
  26. //
  27. int xMira, yMira, contSair;
  28. int contMorte, pstate, tipoZumbi;
  29. int i, cRun, contFogo, tipoProtex;
  30. static int numOndasT, numFase, qtdeZumbi;
  31. int contH, ResultadoZ, qtdeSuperZumbi;
  32. //
  33. int xH = 5, yH = 160;
  34. int xMiraMax = 5, xMiraMax1 = 320;
  35. int yHmin = 142, numOndas = 1, yHmax = 175;
  36. //
  37. static int contaFrameSZ[];
  38. static int contaFrame[];
  39. static int condicaoSZ[];
  40. static int condicao[];
  41. static int c_setSZ[];
  42. static int c_set[];
  43. static int xSZ[];
  44. static int ySZ[];
  45. static int xZ[];
  46. static int yZ[];
  47. static int Sx[];
  48. static int x[];
  49. //
  50. //
  51. boolean rodando = true;
  52. boolean vidaFim, fimVence, vidaFogo, zumbiSet;
  53. static boolean set[], passou[], setSZ[], passouSZ[], fez = false;
  54. //
  55. Zumbis monstro = new Zumbis();
  56. //
  57. String fase;
  58. //
  59. //
  60. int shot = contH = contFogo = ResultadoZ = 0;
  61. int contH1 = i = hstate = contMorte = pstate = contSair = 0;
  62. int contaTiro = qtdeZumbiM = qtdeSZumbiM = ResultadoSZ = zMorte = SzMorte = zMorteQt = SzMorteQt = 0;
  63. //
  64. boolean fim = vidaFim = fimVence = vidaFogo = zumbiSet = false;
  65. //
  66. //
  67. Graphics g = getGraphics();
  68.  
  69. public MaldicaoKoli(MKSetUp midlet) {
  70. super(true);
  71. this.midlet = midlet;
  72. }
  73.  
  74. public void run() {
  75.  
  76. setFullScreenMode(true);
  77. contaFrameSZ = new int[qtdeZumbi];
  78.  
  79. contaFrame = new int[qtdeZumbi];
  80. condicaoSZ = new int[qtdeZumbi];
  81. condicao = new int[qtdeZumbi];
  82. c_setSZ = new int[qtdeZumbi];
  83. c_set = new int[qtdeZumbi];
  84. xSZ = new int[qtdeZumbi];
  85. ySZ = new int[qtdeZumbi];
  86. xZ = new int[qtdeZumbi];
  87. yZ = new int[qtdeZumbi];
  88. Sx = new int[qtdeZumbi];
  89. x = new int[qtdeZumbi];
  90. set = new boolean[qtdeZumbi];
  91. passou = new boolean[qtdeZumbi];
  92.  
  93. Image fundo = carregar_img("/BackGround.png");
  94. Image chao = carregar_img("/Chao.png");
  95. Image stats = carregar_img("/Status.png");
  96. Image gameover = carregar_img("/GameOver.png");
  97. Image gamewon = carregar_img("/GameWon.png");
  98.  
  99. Image zumbi = carregar_img("/zumbi.png");
  100. for (i = 0; i < qtdeZumbi; i++) {
  101. zombies[i] = new Sprite(zumbi, 48, 48);
  102. }
  103.  
  104. Image target = carregar_img("/mira.png");
  105. mira = new Sprite(target, 12, 12);
  106.  
  107. Image hero = carregar_img("/hero.png");
  108. heroi = new Sprite(hero, 48, 48);
  109.  
  110. Image torre = carregar_img("/carro.png");
  111. protex = new Sprite(torre, 52, 48);
  112.  
  113. Image fire = carregar_img("/Fogo.png");
  114. fogo = new Sprite(fire, 48, 48);
  115.  
  116. Image firefim = carregar_img("/FogoFim.png");
  117. fogofim = new Sprite(firefim, 55, 52);
  118.  
  119. protex.setPosition(20, 50);
  120. protex.paint(g);
  121.  
  122. xMira = 66;
  123. yMira = 162;
  124.  
  125. while (rodando) {
  126.  
  127. if ((fim == false) && (fimVence == false)) {
  128. verificarTeclas();
  129. }
  130.  
  131. g.drawImage(fundo, 0, 0, 0);
  132. g.drawImage(chao, 0, 190, 0);
  133. g.drawImage(stats, 0, 217, 0);
  134.  
  135. g.setColor(255, 255, 255);
  136. g.drawString(zMorteQt + "/" + qtdeZumbi, 265, 225, 0);
  137. g.drawString(numOndas + "/" + numOndasT, 195, 225, 0);
  138. g.drawString("" + numFase, 152, 225, 0);
  139.  
  140. desenharHeroi();
  141.  
  142. desenharProtecao();
  143. if (qtdeZumbi != 0) {
  144. monstro.desenharZombie(qtdeZumbi);
  145. }
  146.  
  147. if (zMorte == qtdeZumbi) {
  148. hstate = 5;
  149. zMorte = 0;
  150. }
  151.  
  152. if (qtdeSuperZumbi != 0) {
  153. monstro.desenharSuperZombie(i, qtdeSuperZumbi);
  154. //}
  155. if (SzMorte == superZombies.length) {
  156. hstate = 5;
  157. SzMorte = 0;
  158. }
  159. }
  160.  
  161. desenharVida();
  162.  
  163. desenharVidaH();
  164.  
  165. mira.setPosition(xMira, yMira);
  166. mira.paint(g);
  167.  
  168. if (fim == true) {
  169. g.drawImage(gameover, 160, 120, Graphics.HCENTER | Graphics.VCENTER);
  170. if (contSair < 6) {
  171. contSair++;
  172. } else if (contSair == 6) {
  173.  
  174. contSair = 0;
  175. calculaRecorde(contvidaH, contvida, qtdeZumbiM, qtdeSZumbiM, contaTiro);
  176. }
  177.  
  178. } else if (fimVence == true) {
  179. g.drawImage(gamewon, 160, 120, Graphics.HCENTER | Graphics.VCENTER);
  180. if (contSair < 6) {
  181. contSair++;
  182. } else if (contSair == 6) {
  183.  
  184. contSair = 0;
  185. calculaRecorde(contvidaH, contvida, qtdeZumbiM, qtdeSZumbiM, contaTiro);
  186. }
  187. }
  188.  
  189. flushGraphics();
  190.  
  191. try {
  192. Thread.sleep(100);
  193. } catch (InterruptedException e) {
  194. }
  195. }
  196. }
  197.  
  198. public void iniciar() {
  199. Thread t = new Thread(this);
  200. t.start();
  201. }
  202.  
  203. public static Image carregar_img(String nomeArquivo) {
  204. try {
  205.  
  206. Image img = Image.createImage(nomeArquivo);
  207. return img;
  208.  
  209. } catch (IOException e) {
  210. return null;
  211. }
  212. }
  213.  
  214. public void desenharHeroi() {
  215.  
  216. int hrun[] = {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29};
  217. int hdie[] = {30, 31, 32, 33, 34, 35, 36, 37, 38};
  218. int hwalk[] = {7, 8, 9, 10, 11, 12};
  219. int hprerun[] = {16, 17, 18};
  220. int hmove[] = {2, 3, 4, 5};
  221. int hattack[] = {0};
  222. int hnull[] = {38};
  223. int hstop[] = {1};
  224. //
  225. if (yH < yHmin) {
  226. yH += 6;
  227. } else if (yH > yHmax) {
  228. yH -= 6;
  229. }
  230.  
  231. heroi.setPosition(xH, yH);
  232.  
  233. switch (hstate) {
  234. case 0:
  235. heroi.setFrameSequence(hstop);
  236. break;
  237.  
  238. case 1:
  239. heroi.setFrameSequence(hattack);
  240. hstate = 0;
  241. break;
  242.  
  243. case 2:
  244. if (contH >= 1) {
  245. heroi.setFrameSequence(hmove);
  246. contH = 0;
  247. }
  248.  
  249. contH1++;
  250.  
  251. if (contH1 == 4) {
  252. heroi.setFrameSequence(hattack);
  253. contH1 = 0;
  254. }
  255. break;
  256.  
  257. case 3:
  258. heroi.setFrameSequence(hdie);
  259. hstate = 4;
  260. break;
  261.  
  262. case 4:
  263. if (contMorte < 7) {
  264. contMorte++;
  265.  
  266. } else if (contMorte >= 7) {
  267. heroi.setFrameSequence(hnull);
  268. contMorte = 0;
  269. fim = true;
  270. }
  271. break;
  272.  
  273. case 5:
  274. heroi.setFrameSequence(hprerun);
  275. hstate = 6;
  276. break;
  277.  
  278. case 6:
  279. if (cRun < 3) {
  280. cRun++;
  281. xH += 5;
  282. } else if (cRun >= 3) {
  283. heroi.setFrameSequence(hrun);
  284. hstate = 7;
  285. }
  286. break;
  287.  
  288. case 7:
  289. xH += 15;
  290. if (xH > 320) {
  291. fimVence = true;
  292. }
  293. break;
  294. }
  295.  
  296. heroi.nextFrame();
  297. heroi.paint(g);
  298. }
  299.  
  300. public void desenharProtecao() {
  301.  
  302. int fire1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  303. int fire2[] = {12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
  304. int firefinal[] = {0, 1, 2, 3, 4, 5};
  305. int fireNull[] = {5};
  306.  
  307. protex.setPosition(45, 160);
  308. protex.paint(g);
  309.  
  310. if (contvida <= 400) {
  311.  
  312. if ((protex.isVisible() == false) && (vidaFogo == false)) {
  313.  
  314. fogo.setVisible(false);
  315. fogofim.setPosition(45, 160);
  316.  
  317. switch (pstate) {
  318. case 0:
  319. pstate = 1;
  320. fogofim.setFrameSequence(firefinal);
  321. break;
  322.  
  323. case 1:
  324. if (contFogo < 6) {
  325. contFogo++;
  326. } else if (contFogo == 6) {
  327. contFogo = 0;
  328. }
  329. pstate = 2;
  330. break;
  331.  
  332. case 2:
  333. fogofim.setFrameSequence(fireNull);
  334. fogofim.setVisible(false);
  335. vidaFogo = true;
  336. break;
  337. }
  338.  
  339. fogofim.nextFrame();
  340. fogofim.paint(g);
  341.  
  342. } else if (vidaFogo == false) {
  343. fogo.setPosition(45, 140);
  344.  
  345. if (contFogo <= 14) {
  346. contFogo++;
  347.  
  348. } else if (contFogo == 14) {
  349. fogo.setFrameSequence(fire2);
  350. contFogo++;
  351.  
  352. } else if ((contFogo >= 15) && (contFogo <= 29)) {
  353. contFogo++;
  354.  
  355. } else if (contFogo > 29) {
  356. fogo.setFrameSequence(fire1);
  357. contFogo = 0;
  358. }
  359.  
  360. fogo.nextFrame();
  361. fogo.paint(g);
  362. }
  363. }
  364. }
  365.  
  366. public void verificarTeclas() {
  367. int teclas = getKeyStates();
  368.  
  369. if ((teclas & GameCanvas.LEFT_PRESSED) != 0) {
  370. xMira -= 6;
  371. }
  372.  
  373. if ((teclas & GameCanvas.RIGHT_PRESSED) != 0) {
  374. xMira += 6;
  375. }
  376.  
  377. if ((teclas & GameCanvas.UP_PRESSED) != 0) {
  378. yMira -= 6;
  379. hstate = 2;
  380. contH = 1;
  381. yH -= 6;
  382. }
  383.  
  384. if ((teclas & GameCanvas.DOWN_PRESSED) != 0) {
  385. yMira += 6;
  386. hstate = 2;
  387. contH = 1;
  388. yH += 6;
  389. }
  390.  
  391. if ((teclas & GameCanvas.FIRE_PRESSED) != 0) {
  392.  
  393. contaTiro++;
  394. if (qtdeZumbi != 0) {
  395. if ((xMira >= xMiraMax) && (xMira <= xMiraMax1)) {
  396. if ((mira.collidesWith(Zumbis.zombies[0], true)) == true) {
  397. shot++;
  398. contaTiro -= 3;
  399. if (shot == 3) {
  400. Zumbis.condicao[0] = 4;
  401. shot = 0;
  402. }
  403. hstate = 1;
  404. }
  405.  
  406. if ((mira.collidesWith(Zumbis.zombies[1], true)) == true) {
  407. shot++;
  408. if (shot == 3) {
  409. Zumbis.condicao[1] = 4;
  410. shot = 0;
  411. }
  412. hstate = 1;
  413. }
  414. try {
  415. if ((mira.collidesWith(Zumbis.zombies[2], true)) == true) {
  416. shot++;
  417. if (shot == 3) {
  418. Zumbis.condicao[2] = 4;
  419. shot = 0;
  420. }
  421. hstate = 1;
  422. }
  423.  
  424. if ((mira.collidesWith(Zumbis.zombies[3], true)) == true) {
  425. shot++;
  426. if (shot == 3) {
  427. Zumbis.condicao[3] = 4;
  428. shot = 0;
  429. }
  430. hstate = 1;
  431. }
  432. } catch (Exception e) {
  433. }
  434. try {
  435. if ((mira.collidesWith(Zumbis.zombies[4], true)) == true) {
  436. shot++;
  437. if (shot == 3) {
  438. Zumbis.condicao[4] = 4;
  439. shot = 0;
  440. }
  441. hstate = 1;
  442. }
  443.  
  444. if ((mira.collidesWith(Zumbis.zombies[5], true)) == true) {
  445. shot++;
  446. if (shot == 3) {
  447. Zumbis.condicao[5] = 4;
  448. shot = 0;
  449. }
  450. hstate = 1;
  451. }
  452. } catch (Exception e) {
  453. }
  454. }
  455.  
  456. if (qtdeSuperZumbi != 0) {
  457. try {
  458. if ((mira.collidesWith(Zumbis.superZombies[0], true)) == true) {
  459. shot++;
  460. contaTiro -= 3;
  461. if (shot == 3) {
  462. Zumbis.condicaoSZ[0] = 4;
  463. shot = 0;
  464. }
  465. hstate = 1;
  466. }
  467. if ((mira.collidesWith(Zumbis.superZombies[1], true)) == true) {
  468. shot++;
  469. if (shot == 3) {
  470. Zumbis.condicaoSZ[1] = 4;
  471. shot = 0;
  472. }
  473. hstate = 1;
  474. }
  475.  
  476. if ((mira.collidesWith(Zumbis.superZombies[2], true)) == true) {
  477. shot++;
  478. if (shot == 3) {
  479. Zumbis.condicaoSZ[2] = 4;
  480. shot = 0;
  481. }
  482. hstate = 1;
  483. }
  484.  
  485. if ((mira.collidesWith(Zumbis.superZombies[3], true)) == true) {
  486. shot++;
  487. if (shot == 3) {
  488. Zumbis.condicaoSZ[3] = 4;
  489. shot = 0;
  490. }
  491. hstate = 1;
  492. }
  493. if ((mira.collidesWith(Zumbis.superZombies[4], true)) == true) {
  494. shot++;
  495. if (shot == 3) {
  496. Zumbis.condicaoSZ[4] = 4;
  497. shot = 0;
  498. }
  499. hstate = 1;
  500. }
  501.  
  502. if ((mira.collidesWith(Zumbis.superZombies[5], true)) == true) {
  503. shot++;
  504. if (shot == 3) {
  505. Zumbis.condicaoSZ[5] = 4;
  506. shot = 0;
  507. }
  508. hstate = 1;
  509. }
  510. } catch (Exception e) {
  511. }
  512. }
  513. }
  514. }
  515. }
  516.  
  517. public void desenharVida() {
  518.  
  519. g.setColor(0, 0, 0);
  520. g.drawRect(88, 230, (400 * 39 / 500) + 1, 5);
  521.  
  522. g.setColor(255, 0, 0);
  523. g.fillRect(89, 231, ((contvida / 4) * 39 / 500), 5);
  524.  
  525. if (contvida <= 0) {
  526. g.setColor(255, 255, 0);
  527. protex.setVisible(false);
  528. }
  529. }
  530.  
  531. public void desenharVidaH() {
  532.  
  533. g.setColor(0, 0, 0);
  534. g.drawRect(45, 230, (400 * 39 / 500) + 1, 5);
  535.  
  536. g.setColor(0, 255, 0);
  537. g.fillRect(46, 231, ((contvidaH / 4) * 39 / 500), 5);
  538.  
  539. if (contvidaH <= 0) {
  540. g.setColor(255, 255, 0);
  541. if (vidaFim == false) {
  542. hstate = 3;
  543. vidaFim = true;
  544. }
  545. }
  546. }
  547.  
  548. public void calculaRecorde(int vidaH, int vidaP, int numeroZM, int numeroSZM, int tiroD) {
  549. int Resultado = 0;
  550. calcRecord score = new calcRecord();
  551. tiroD = tiroD - (3 * numeroZM);
  552.  
  553. if (qtdeZumbi != 0) {
  554. ResultadoZ = (vidaH / 16) + (vidaP / 16) + (numeroZM / qtdeZumbi) - tiroD;
  555. }
  556.  
  557. if (qtdeSuperZumbi != 0) {
  558. ResultadoSZ = (vidaH / 16) + (vidaP / 16) + (numeroSZM / qtdeSuperZumbi) - tiroD;
  559. }
  560.  
  561. Resultado = ResultadoZ + ResultadoSZ;
  562.  
  563. score.gravaRecorde(Resultado);
  564. Sair();
  565. }
  566.  
  567. public void Reset() {
  568.  
  569. try {
  570.  
  571. RecordStore rs = RecordStore.openRecordStore(MKSetUp.Fase, true);
  572. String temp = new String(rs.getRecord(1));
  573.  
  574. if (temp.equals("A")) {
  575. contvida = 1600;
  576. numOndasT = 1;
  577. numFase = 1;
  578. qtdeZumbi = 2;
  579. // chefe Zumbi Agua
  580.  
  581. } else if (temp.equals("B")) {
  582. contvida = 1600;
  583. numOndasT = 1;
  584. numFase = 1;
  585. qtdeZumbi = 2;
  586. // chefe Acheman
  587.  
  588. } else if (temp.equals("C")) {
  589. contvida = 1600;
  590. numOndasT = 1;
  591. numFase = 1;
  592. qtdeZumbi = 2;
  593. // chefe Wraith+Magic
  594. } else {
  595.  
  596. switch (temp.charAt(0)) {
  597.  
  598. case '0':
  599. contvida = 1600;
  600. numOndasT = 1;
  601. numFase = 1;
  602. qtdeZumbi = 2;
  603. // 1 onda, 2 zumbis, zumbi normal
  604. break;
  605.  
  606. case '1':
  607. contvida = 1600;
  608. numOndasT = 1;
  609. numFase = 2;
  610. qtdeZumbi = 4;
  611. // 1 onda, 4 zumbis, zumbi normal
  612. break;
  613.  
  614. case '2':
  615. contvida = 1600;
  616. numOndasT = 1;
  617. numFase = 3;
  618. qtdeZumbi = 6;
  619. // 1 onda, 6 zumbis, zumbi normal
  620. break;
  621.  
  622. case '3':
  623. contvida = 1600;
  624. numOndasT = 2;
  625. numFase = 4;
  626. qtdeZumbi = 6;
  627. // 2 ondas, 6 zumbis, zumbi normal
  628. break;
  629.  
  630. case '4':
  631. contvida = 1600;
  632. numOndasT = 3;
  633. numFase = 5;
  634. qtdeSuperZumbi = 6;
  635. // 3 ondas, 6 zumbis, super zumbi
  636. break;
  637.  
  638. case '5':
  639. contvida = 1600;
  640. numOndasT = 4;
  641. numFase = 6;
  642. qtdeSuperZumbi = 6;
  643. // 4 ondas, 6 zumbis, super zumbi
  644. break;
  645.  
  646. case '6':
  647. contvida = 1600;
  648. numOndasT = 5;
  649. numFase = 7;
  650. qtdeSuperZumbi = 6;
  651. // 5 ondas, 6 zumbis, super zumbi
  652. break;
  653.  
  654. case '7':
  655. contvida = 1600;
  656. numOndasT = 6;
  657. numFase = 8;
  658. qtdeSuperZumbi = 6;
  659. // 6 ondas, 6 zumbis, super zumbi
  660. break;
  661.  
  662. case '8':
  663. contvida = 1600;
  664. numOndasT = 7;
  665. numFase = 9;
  666. qtdeSuperZumbi = 6;
  667. // 7 ondas, 6 zumbis, super zumbi
  668. break;
  669. }
  670. }
  671. } catch (Exception e) {
  672. }
  673.  
  674. yH = 160;
  675. xMiraMax1 = 320;
  676. xH = xMiraMax = 5;
  677. yHmin = 142;
  678. yHmax = 170;
  679. contvidaH = 1600;
  680.  
  681. contaTiro = qtdeZumbiM = 0;
  682. contempo = shot = contH = contFogo = ResultadoZ = zMorteQt = 0;
  683. contH1 = i = hstate = contMorte = pstate = contSair = zMorte = 0;
  684.  
  685. fim = vidaFim = fimVence = vidaFogo = false;
  686.  
  687. rodando = true;
  688. iniciar();
  689. }
  690.  
  691. public void Sair() {
  692.  
  693. try {
  694.  
  695. RecordStore rs = RecordStore.openRecordStore(MKSetUp.Fase, true);
  696. if (fim == true) {
  697.  
  698. fase = "0";
  699. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  700.  
  701. } else if (fimVence == true) {
  702. String temp = new String(rs.getRecord(1));
  703.  
  704. if (temp.equals("A")) {
  705.  
  706. fase = "3";
  707. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  708.  
  709. } else if (temp.equals("B")) {
  710.  
  711. fase = "6";
  712. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  713.  
  714. } else if (temp.equals("C")) {
  715.  
  716. fase = "0";
  717. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  718. } else {
  719.  
  720. switch (temp.charAt(0)) {
  721.  
  722. case '0':
  723. fase = "1";
  724. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  725. break;
  726.  
  727. case '1':
  728. fase = "2";
  729. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  730. break;
  731.  
  732. case '2':
  733. fase = "A";
  734. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  735. break;
  736.  
  737. case '3':
  738. fase = "4";
  739. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  740. break;
  741.  
  742. case '4':
  743. fase = "5";
  744. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  745. break;
  746.  
  747. case '5':
  748. fase = "B";
  749. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  750. break;
  751.  
  752. case '6':
  753. fase = "7";
  754. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  755. break;
  756.  
  757. case '7':
  758. fase = "8";
  759. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  760. break;
  761.  
  762. case '8':
  763. fase = "C";
  764. rs.setRecord(1, fase.getBytes(), 0, fase.getBytes().length);
  765. break;
  766. }
  767. }
  768. }
  769. } catch (Exception e) {
  770. }
  771.  
  772. rodando = false;
  773. MenuRecord.funfar = true;
  774. midlet.recordesShow();
  775. }
  776. }



Zumbis.txt - This is the monster class.

Spoiler
  1. import java.io.IOException;
  2. import javax.microedition.lcdui.Graphics;
  3. import javax.microedition.lcdui.Image;
  4. import javax.microedition.lcdui.game.*;
  5.  
  6. /**
  7. *
  8. * @author jose.prado
  9. *
  10. */
  11. public class Zumbis extends GameCanvas {
  12. //
  13.  
  14. static int i;
  15. Image zumbi = carregar_img("/zumbi.png");
  16. static int contvidaH = 1600;
  17. static int hstate = MaldicaoKoli.hstate;
  18. static int contvida = MaldicaoKoli.contvida;
  19. static int contempo = MaldicaoKoli.contempo;
  20. static boolean setUpZ;
  21. static int condicao[];
  22. static int condicaoSZ[];
  23. //
  24. static Sprite zombies[] = MaldicaoKoli.zombies;
  25. static Sprite superZombies[];
  26. static Sprite protex = MaldicaoKoli.protex;
  27. Graphics g = getGraphics();
  28. int qtdeSuperZumbi;
  29.  
  30. public Zumbis() {
  31. super(true);
  32. }
  33.  
  34. public void desenharZombie(int qtdeZumbi) {
  35.  
  36. if (MaldicaoKoli.fez == false) {
  37. for (i = 0; i < 6; i++) {
  38. zombies[i] = new Sprite(MaldicaoKoli.carregar_img("/zumbi.png"), 48, 48);
  39. }
  40. MaldicaoKoli.fez=true;
  41. }
  42. //
  43. int j;
  44. int zMorte = MaldicaoKoli.zMorte;
  45. int zMorteQt = MaldicaoKoli.zMorteQt;
  46. int qtdeZumbiM = MaldicaoKoli.qtdeZumbiM;
  47. //
  48. //
  49. int x[] = MaldicaoKoli.x;
  50. int xZ[] = MaldicaoKoli.xZ;
  51. int yZ[] = MaldicaoKoli.yZ;
  52. int c_set[] = MaldicaoKoli.c_set;
  53. int contaFrame[] = MaldicaoKoli.contaFrame;
  54.  
  55. condicao = MaldicaoKoli.condicao;
  56. //
  57. boolean set[] = MaldicaoKoli.set;
  58. boolean passou[] = MaldicaoKoli.passou;
  59. //
  60.  
  61. if (setUpZ == false) {
  62.  
  63. for (j = 0; j < qtdeZumbi; j++) {
  64.  
  65. try {
  66. zombies[j] = new Sprite(MaldicaoKoli.carregar_img("/zumbi.png"), 48, 48);
  67. } catch (Exception e) {
  68. }
  69.  
  70. condicao[j] = 0;
  71. x[j] = 285;
  72. yZ[j] = 160;
  73. set[j] = false;
  74. }
  75.  
  76. setUpZ = true;
  77. }
  78.  
  79. for (i = 0; i < qtdeZumbi; i++) {
  80.  
  81. //i = cont;
  82.  
  83. for (j = 0; j < qtdeZumbi; j++) {
  84. xZ[j] = x[j];
  85. }
  86.  
  87. if (set[i] == false) {
  88. if (c_set[i] < 2) {
  89. c_set[i]++;
  90. } else {
  91. set[i] = true;
  92. }
  93. }
  94.  
  95. int zdie[] = {7, 8, 9, 10, 11, 12, 13};
  96. int zattack[] = {0, 1, 2, 3, 4, 5, 6};
  97. int zborn[] = {14, 15, 16, 17, 18, 6};
  98. int zwalk[] = {0, 1, 2, 3, 4, 5, 6};
  99. int znull[] = {19};
  100. int zstop[] = {6};
  101.  
  102. //
  103.  
  104. if (hstate >= 3) {
  105. zombies[i].setFrameSequence(zstop);
  106. }
  107.  
  108. try {
  109. zombies[0].setPosition(xZ[0], yZ[0]);
  110. } catch (Exception e) {
  111. }
  112.  
  113. try {
  114. zombies[1].setPosition(xZ[1] - 20, yZ[1]);
  115. } catch (Exception e) {
  116. }
  117.  
  118. if (qtdeZumbi > 2) {
  119. try {
  120. zombies[2].setPosition(xZ[2] - 5, yZ[0]);
  121. zombies[3].setPosition(xZ[3] - 25, yZ[1]);
  122. zombies[4].setPosition(xZ[4] - 10, yZ[0]);
  123. zombies[5].setPosition(xZ[5] - 30, yZ[1]);
  124. } catch (Exception e) {
  125. }
  126. }
  127.  
  128. switch (condicao[i]) {
  129. case 0:
  130. zombies[i].setFrameSequence(zborn);
  131. condicao[i] = 1;
  132. break;
  133.  
  134. case 1:
  135. if (contaFrame[i] < 4) {
  136. contaFrame[i]++;
  137. } else if (contaFrame[i] == 4) {
  138. contaFrame[i] = 0;
  139. zombies[i].setFrameSequence(zwalk);
  140. condicao[i] = 2;
  141. }
  142. break;
  143.  
  144. case 2:
  145. if (xZ[0] <= 80) {
  146. zombies[0].setFrameSequence(zattack);
  147. condicao[0] = 3;
  148. } else {
  149. xZ[0] -= 1;
  150. x[0] = xZ[0];
  151. MaldicaoKoli.x[0] = x[0];
  152. }
  153.  
  154. if (xZ[1] <= 100) {
  155. zombies[1].setFrameSequence(zattack);
  156. condicao[1] = 3;
  157. } else {
  158. xZ[1] -= 1;
  159. x[1] = xZ[1];
  160. MaldicaoKoli.x[1] = x[1];
  161. }
  162.  
  163. if (zombies.length > 2) {
  164. try {
  165. if (xZ[2] <= 85) {
  166. zombies[2].setFrameSequence(zattack);
  167. condicao[2] = 3;
  168. } else {
  169. xZ[2] -= 1;
  170. x[2] = xZ[2];
  171. MaldicaoKoli.x[2] = x[2];
  172. }
  173.  
  174. if (xZ[3] <= 105) {
  175. zombies[3].setFrameSequence(zattack);
  176. condicao[3] = 3;
  177. } else {
  178. xZ[3] -= 1;
  179. x[3] = xZ[3];
  180. MaldicaoKoli.x[3] = x[3];
  181. }
  182. if (xZ[4] <= 85) {
  183. zombies[4].setFrameSequence(zattack);
  184. condicao[4] = 3;
  185. } else {
  186. xZ[4] -= 1;
  187. x[4] = xZ[4];
  188. MaldicaoKoli.x[4] = x[4];
  189. }
  190.  
  191. if (xZ[5] <= 105) {
  192. zombies[5].setFrameSequence(zattack);
  193. condicao[5] = 3;
  194. } else {
  195. xZ[5] -= 1;
  196. x[5] = xZ[5];
  197. MaldicaoKoli.x[5] = x[5];
  198. }
  199.  
  200. } catch (Exception e) {
  201. }
  202. }
  203. break;
  204.  
  205. case 3:
  206. if (contempo < 10) {
  207. contempo++;
  208. } else if (contempo >= 10) {
  209. contvida -= 300;
  210. contempo = 0;
  211.  
  212. MaldicaoKoli.contvida = contvida;
  213. }
  214. break;
  215.  
  216. case 4:
  217. zombies[i].setFrameSequence(zdie);
  218. qtdeZumbiM++;
  219. condicao[i] = 5;
  220. MaldicaoKoli.qtdeZumbiM = qtdeZumbiM;
  221. break;
  222.  
  223. case 5:
  224. if (contaFrame[i] < 5) {
  225. contaFrame[i]++;
  226. } else if (contaFrame[i] >= 5) {
  227. contaFrame[i] = 0;
  228. zombies[i].setFrameSequence(znull);
  229. xZ[i] = 285;
  230. x[i] = xZ[i];
  231. zMorte++;
  232. zMorteQt++;
  233. condicao[i] = 8;
  234.  
  235. MaldicaoKoli.x[i] = x[i];
  236. MaldicaoKoli.zMorte = zMorte;
  237. MaldicaoKoli.zMorteQt = zMorteQt;
  238. }
  239. break;
  240.  
  241. case 6:
  242. if (xZ[i] <= 27) {
  243. condicao[i] = 7;
  244. contempo = 0;
  245. } else {
  246. xZ[i] -= 5;
  247. x[i] = xZ[i];
  248. MaldicaoKoli.x[i] = x[i];
  249. }
  250. break;
  251.  
  252. case 7:
  253. if (contempo < 10) {
  254. contempo++;
  255. } else if (contempo >= 10) {
  256. contvidaH -= 300;
  257. contempo = 0;
  258.  
  259. MaldicaoKoli.contvidaH = contvidaH;
  260. }
  261. break;
  262.  
  263. case 8:
  264. zombies[i].setFrameSequence(znull);
  265. break;
  266. }
  267.  
  268. if ((MaldicaoKoli.protex.isVisible() == false) && (passou[i] == false)) {
  269. condicao[i] = 6;
  270. passou[i] = true;
  271. }
  272. zombies[i].nextFrame();
  273. zombies[i].paint(g);
  274.  
  275. MaldicaoKoli.zMorte = zMorte;
  276. MaldicaoKoli.zMorteQt = zMorteQt;
  277. MaldicaoKoli.qtdeZumbiM = qtdeZumbiM;
  278. //
  279. //
  280. MaldicaoKoli.xZ[i] = xZ[i];
  281. MaldicaoKoli.yZ[i] = yZ[i];
  282. MaldicaoKoli.c_set[i] = c_set[i];
  283. MaldicaoKoli.condicao[i] = condicao[i];
  284. MaldicaoKoli.contaFrame[i] = contaFrame[i];
  285. //
  286. MaldicaoKoli.set[i] = set[i];
  287. MaldicaoKoli.passou[i] = passou[i];
  288. }
  289. }
  290.  
  291. public void desenharSuperZombie(int cont, int qtdeSuperZumbi) {
  292.  
  293. boolean setUpSZ = false;
  294. int SzMorte = MaldicaoKoli.SzMorte;
  295. int SzMorteQt = MaldicaoKoli.SzMorteQt;
  296. int qtdeSZumbiM = MaldicaoKoli.qtdeSZumbiM;
  297. //
  298. //
  299. int Sx[] = new int[qtdeSuperZumbi];
  300. int xSZ[] = new int[qtdeSuperZumbi];
  301. int ySZ[] = new int[qtdeSuperZumbi];
  302. int c_setSZ[] = new int[qtdeSuperZumbi];
  303. condicaoSZ = new int[qtdeSuperZumbi];
  304. int contaFrameSZ[] = new int[qtdeSuperZumbi];
  305. //
  306. boolean setSZ[] = new boolean[qtdeSuperZumbi];
  307. boolean passouSZ[] = new boolean[qtdeSuperZumbi];
  308. //
  309. superZombies = new Sprite[qtdeSuperZumbi];
  310.  
  311. if (setUpSZ == false) {
  312. for (i = 0; i < superZombies.length; i++) {
  313. superZombies[i] = new Sprite(MaldicaoKoli.carregar_img("/zumbi.png"), 48, 48);
  314. condicaoSZ[i] = 0;
  315. Sx[i] = 285;
  316.  
  317. for (i = 0; i < ySZ.length; i++) {
  318. ySZ[i] = 160;
  319. setSZ[i] = false;
  320. }
  321. }
  322. setUpSZ = true;
  323. }
  324.  
  325. i = cont;
  326.  
  327. //for (i = 0; i < qtdeSuperZumbi; i++) {
  328.  
  329. xSZ[i] = Sx[i];
  330.  
  331. if (setSZ[i] == false) {
  332. if (c_setSZ[i] < 2) {
  333. c_setSZ[i]++;
  334. } else {
  335. setSZ[i] = true;
  336. }
  337. }
  338.  
  339. int Szdie[] = {0};
  340. int Szattack[] = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
  341. int Szborn[] = {0};
  342. int Szwalk[] = {1, 2, 3, 4, 5, 6};
  343. int Sznull[] = {0};
  344. int Szstop[] = {0};
  345.  
  346. //
  347.  
  348. if (hstate >= 3) {
  349. superZombies[i].setFrameSequence(Szstop);
  350. }
  351.  
  352. superZombies[0].setPosition(xSZ[0], ySZ[0]);
  353. superZombies[1].setPosition(xSZ[1] - 20, ySZ[1]);
  354.  
  355. if (superZombies.length == 4) {
  356. try {
  357. superZombies[2].setPosition(xSZ[2] - 5, ySZ[0]);
  358. superZombies[3].setPosition(xSZ[3] - 25, ySZ[1]);
  359. } catch (Exception e) {
  360. }
  361. try {
  362. superZombies[4].setPosition(xSZ[4] - 10, ySZ[0] + 5);
  363. superZombies[5].setPosition(xSZ[5] - 30, ySZ[1] + 10);
  364. } catch (Exception e) {
  365. }
  366. }
  367.  
  368. switch (condicaoSZ[i]) {
  369. case 0:
  370. superZombies[i].setFrameSequence(Szborn);
  371. condicaoSZ[i] = 1;
  372. break;
  373.  
  374. case 1:
  375. if (contaFrameSZ[i] < 4) {
  376. contaFrameSZ[i]++;
  377. } else if (contaFrameSZ[i] == 4) {
  378. contaFrameSZ[i] = 0;
  379. superZombies[i].setFrameSequence(Szwalk);
  380. condicaoSZ[i] = 2;
  381. }
  382. break;
  383.  
  384. case 2:
  385. if (xSZ[0] <= 80) {
  386. superZombies[0].setFrameSequence(Szattack);
  387. condicaoSZ[0] = 3;
  388. } else {
  389. xSZ[0] -= 1;
  390. Sx[0] = xSZ[0];
  391. }
  392.  
  393. if (xSZ[1] <= 100) {
  394. superZombies[1].setFrameSequence(Szattack);
  395. condicaoSZ[1] = 3;
  396. } else {
  397. xSZ[1] -= 1;
  398. Sx[1] = xSZ[1];
  399. }
  400.  
  401. if (superZombies.length == 4) {
  402. try {
  403. if (xSZ[2] <= 85) {
  404. superZombies[2].setFrameSequence(Szattack);
  405. condicaoSZ[2] = 3;
  406. } else {
  407. xSZ[2] -= 1;
  408. Sx[2] = xSZ[2];
  409. }
  410.  
  411. if (xSZ[3] <= 105) {
  412. superZombies[3].setFrameSequence(Szattack);
  413. condicaoSZ[3] = 3;
  414. } else {
  415. xSZ[3] -= 1;
  416. Sx[3] = xSZ[3];
  417. }
  418.  
  419. } catch (Exception e) {
  420. }
  421. }
  422. break;
  423.  
  424. case 3:
  425. if (contempo < 10) {
  426. contempo++;
  427. } else if (contempo >= 10) {
  428. contvida -= 300;
  429. contempo = 0;
  430.  
  431. MaldicaoKoli.contvida = contvida;
  432. }
  433. break;
  434.  
  435. case 4:
  436. superZombies[i].setFrameSequence(Szdie);
  437. qtdeSZumbiM++;
  438. condicaoSZ[i] = 5;
  439.  
  440. MaldicaoKoli.qtdeSZumbiM = qtdeSZumbiM;
  441. break;
  442.  
  443. case 5:
  444. if (contaFrameSZ[i] < 5) {
  445. contaFrameSZ[i]++;
  446. } else if (contaFrameSZ[i] >= 5) {
  447. contaFrameSZ[i] = 0;
  448. superZombies[i].setFrameSequence(Sznull);
  449. xSZ[i] = 285;
  450. Sx[i] = xSZ[i];
  451. SzMorte++;
  452. SzMorteQt++;
  453. condicaoSZ[i] = 8;
  454.  
  455. MaldicaoKoli.SzMorte = SzMorte;
  456. MaldicaoKoli.SzMorteQt = SzMorteQt;
  457. }
  458. break;
  459.  
  460. case 6:
  461. if (xSZ[i] <= 27) {
  462. condicaoSZ[i] = 7;
  463. contempo = 0;
  464. } else {
  465. xSZ[i] -= 5;
  466. Sx[i] = xSZ[i];
  467. }
  468. break;
  469.  
  470. case 7:
  471. if (contempo < 10) {
  472. contempo++;
  473. } else if (contempo >= 10) {
  474. contvidaH -= 300;
  475. contempo = 0;
  476.  
  477. MaldicaoKoli.contvidaH = contvidaH;
  478. }
  479. break;
  480.  
  481. case 8:
  482. superZombies[i].setFrameSequence(Sznull);
  483. break;
  484. }
  485.  
  486. if ((protex.isVisible() == false) && (passouSZ[i] == false)) {
  487. condicaoSZ[i] = 6;
  488. passouSZ[i] = true;
  489. }
  490.  
  491. superZombies[i].nextFrame();
  492. superZombies[i].paint(g);
  493.  
  494. //}
  495. }
  496.  
  497. public static Image carregar_img(String nomeArquivo) {
  498. try {
  499. Image img = Image.createImage(nomeArquivo);
  500. return img;
  501. } catch (IOException e) {
  502. return null;
  503. }
  504. }
  505. }


If you look at the code, you'll see that I'm not posting all the classes in the game. Simply because they're not needed to run the game (actually, they are, but there's no problem with them). If you think I should put them here too, tell me, OK?

Also, I would like to kindly ask anyone who download my code(s) NOT to do anything with it unless I say so. This was made by scratch by me, so I own it.

Thanks, all.
a b L Programming
August 12, 2010 11:08:02 PM

I am assuming that those object names, etc are in Portuguese? That, coupled with the fact that there are no comments or method headers in any of the code would make it a right pain in the arse to go through and understand all of this code...

Some general advice I could think of right off hand is:
1. Are you sure the picture files are in the correct directory? (could you try using a full link to the picture to insure this works?)
2. Have you used a debugger to step through the code that is supposed to display the picture? Any info on what is happening there?
m
0
l
August 13, 2010 1:56:29 AM


Forget the help guys!

I was able to do it on my own. It was just a matter of returning the sprite to the game and make the game change the frames and paint the sprite.

I'm am now trying to make this game a little more object oriented, since it is Java-based anyway.

Thanks for trying, and I'm sorry I couldn't ask in a better way.
m
0
l
!