Hero.java
上传用户:qinghua
上传日期:2022-06-06
资源大小:523k
文件大小:11k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.midlet.*;
  2. import javax.microedition.lcdui.*;
  3. public class Hero
  4. {
  5. public static int bally,walky;
  6. public byte wr,wl,t,cu,cd,a,direction,hb;
  7. public int standy,pow;
  8. public int panru[]=new int[]{-830,-1325,-2220};
  9.     public int panlu[]=new int[]{-190,-1115,-1715,-1105};
  10. public int panrd[]=new int[]{-340,-1005,-1610,-2440};
  11.     public int panld[]=new int[]{-70,-940,-1430,-2320};
  12. public static boolean panlflag,panrflag;
  13. public void  walkright(Graphics g)
  14. {
  15. //System.out.print("PANX: ");
  16. //System.out.println((HauntedCastle.panx -70));
  17. //System.out.print("PANY: ");
  18. //System.out.println(HauntedCastle.pany);
  19. //************************TO STOP PANNING*******************************
  20. if(HauntedCastle.right==true && HauntedCastle.pany == 0)
  21. {
  22. panrflag = true;
  23. for(int i=0;i<panrd.length;i++)
  24. {
  25. if((HauntedCastle.panx-70) == panrd[i])
  26. {
  27. panrflag = false;
  28. }
  29. }
  30. if(panrflag)
  31. {
  32. HauntedCastle.panx-=5;
  33. }
  34. }
  35.     
  36. if(HauntedCastle.right==true && HauntedCastle.pany !=0)
  37. {
  38. panrflag = true;
  39. for(int i=0;i<panru.length;i++){
  40. if((HauntedCastle.panx-70) == panru[i])
  41. {
  42. panrflag = false;
  43. }
  44. }
  45. if(panrflag)
  46. {
  47. HauntedCastle.panx-=5;
  48. }
  49. }
  50.     
  51. //***********************************************************************
  52. if(HauntedCastle.pany!=0)
  53. walky=62;
  54. else
  55. walky=158;
  56. if(HauntedCastle.right==true)
  57. {
  58. if(wr==0)
  59. {
  60. g.drawImage(HauntedCastle.hero2,70,walky,Graphics.TOP|Graphics.LEFT );
  61. wr++;
  62. }
  63. else if(wr==1)
  64. {
  65. g.drawImage(HauntedCastle.hero3,70,walky,Graphics.TOP|Graphics.LEFT );
  66. wr++;
  67. }
  68. else if(wr==2)
  69. {
  70. g.drawImage(HauntedCastle.hero4,70,walky,Graphics.TOP|Graphics.LEFT );
  71. wr++;
  72. }
  73. else if(wr==3)
  74. {
  75. g.drawImage(HauntedCastle.hero5,70,walky,Graphics.TOP|Graphics.LEFT );
  76. wr=0;
  77. }
  78. }
  79. }
  80. public void  walkleft(Graphics g)
  81. {
  82. if(HauntedCastle.pany!=0)
  83. walky=62;
  84. else
  85. walky=158;
  86. // System.out.println((HauntedCastle.panx -70));
  87. if(HauntedCastle.left==true && HauntedCastle.pany == 0)
  88. {
  89. panlflag = true;
  90. for(int i=0;i<panld.length;i++)
  91. {
  92. if((HauntedCastle.panx-70) == panld[i])
  93. {
  94. panlflag = false;
  95. }
  96. }
  97. if(panlflag)
  98. {
  99. HauntedCastle.panx+=5;
  100. }
  101. }   
  102. if(HauntedCastle.left==true && HauntedCastle.pany != 0)
  103. {
  104. panlflag = true;
  105. for(int i=0;i<panlu.length;i++)
  106. {
  107. if((HauntedCastle.panx-70) == panlu[i])
  108. {
  109. panlflag = false;
  110. }
  111. }
  112. if(panlflag)
  113. {
  114. HauntedCastle.panx+=5;
  115. }   
  116. }   
  117. if(HauntedCastle.action==HauntedCastle.MOVELEFT)
  118.     {
  119. if(wl==0)
  120. {
  121. g.drawImage(HauntedCastle.hero2f,70,walky,Graphics.TOP|Graphics.LEFT );
  122. wl++;
  123. }
  124. else if(wl==1)
  125. {
  126. g.drawImage(HauntedCastle.hero3f,70,walky,Graphics.TOP|Graphics.LEFT );
  127. wl++;
  128. }
  129. else if(wl==2)
  130. {
  131. g.drawImage(HauntedCastle.hero4f,70,walky,Graphics.TOP|Graphics.LEFT );
  132. wl++;
  133. }
  134. else if(wl==3)
  135. {
  136. g.drawImage(HauntedCastle.hero5f,70,walky,Graphics.TOP|Graphics.LEFT );
  137. wl=0;
  138. }
  139. }
  140. }
  141. public void standright(Graphics g)
  142. {
  143. if (HauntedCastle.pany==0)
  144. g.drawImage(HauntedCastle.hero1,70,158,Graphics.TOP|Graphics.LEFT );
  145.     else
  146.      g.drawImage(HauntedCastle.hero1,70,62,Graphics.TOP|Graphics.LEFT );
  147. }
  148. public void standleft(Graphics g)
  149. {
  150. if (HauntedCastle.pany==0)
  151. g.drawImage(HauntedCastle.hero1f,70,158,Graphics.TOP|Graphics.LEFT );
  152.     else
  153.      g.drawImage(HauntedCastle.hero1f,70,62,Graphics.TOP|Graphics.LEFT );
  154. }
  155. public void climbupright(Graphics g)
  156. {
  157.    
  158.    
  159.     if(cu==0)
  160. {
  161. g.drawImage(HauntedCastle.hero6,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  162. cu++;
  163. HauntedCastle.pany-=5;
  164. HauntedCastle.panx-=5;
  165. }
  166. else if(cu==1)
  167. {
  168. g.drawImage(HauntedCastle.hero5,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  169. cu++;
  170. HauntedCastle.pany-=5;
  171. HauntedCastle.panx-=5;
  172. }
  173.      else if(cu==2)
  174. {
  175. g.drawImage(HauntedCastle.hero7,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  176. cu++;
  177. HauntedCastle.pany-=5;
  178. HauntedCastle.panx-=5;
  179.      else if(cu==3)
  180. {
  181. g.drawImage(HauntedCastle.hero5,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  182. cu=0;
  183. HauntedCastle.pany-=5;
  184. HauntedCastle.panx-=5;
  185. }
  186. }
  187. public void climbupleft(Graphics g)
  188. {
  189.     if(cu==0)
  190. {
  191. g.drawImage(HauntedCastle.hero6f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  192. cu++;
  193. HauntedCastle.pany-=5;
  194. HauntedCastle.panx+=5;
  195. }
  196. else if(cu==1)
  197. {
  198. g.drawImage(HauntedCastle.hero5f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  199. cu++;
  200. HauntedCastle.pany-=5;
  201. HauntedCastle.panx+=5;
  202. }
  203.      else if(cu==2)
  204. {
  205. g.drawImage(HauntedCastle.hero7f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  206. cu++;
  207. HauntedCastle.pany-=5;
  208. HauntedCastle.panx+=5;
  209.      else if(cu==3)
  210. {
  211. g.drawImage(HauntedCastle.hero5f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  212. cu=0;
  213. HauntedCastle.pany-=5;
  214. HauntedCastle.panx+=5;
  215. }
  216.        
  217. }
  218. public void climbdownright(Graphics g)
  219. {
  220. if(cd==0)
  221. {
  222. g.drawImage(HauntedCastle.hero8,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  223. cd++;
  224. HauntedCastle.pany+=5;
  225. HauntedCastle.panx-=5;
  226. }
  227. else if(cd==1)
  228. {
  229. g.drawImage(HauntedCastle.hero5,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  230. cd++;
  231. HauntedCastle.pany+=5;
  232. HauntedCastle.panx-=5;
  233. }
  234. else if(cd==2)
  235. {
  236. g.drawImage(HauntedCastle.hero9,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  237. cd++;
  238. HauntedCastle.pany+=5;
  239. HauntedCastle.panx-=5;
  240. }
  241.      else if(cd==3)
  242. {
  243. g.drawImage(HauntedCastle.hero5,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  244. cd=0;
  245. HauntedCastle.pany+=5;
  246. HauntedCastle.panx-=5;
  247. }
  248. }
  249. public void climbdownleft(Graphics g)
  250. {
  251. if(cd==0)
  252. {
  253. g.drawImage(HauntedCastle.hero8f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  254. cd++;
  255. HauntedCastle.pany+=5;
  256. HauntedCastle.panx+=5;
  257. }
  258. else if(cd==1)
  259. {
  260. g.drawImage(HauntedCastle.hero5f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  261. cd++;
  262. HauntedCastle.pany+=5;
  263. HauntedCastle.panx+=5;
  264. }
  265. else if(cd==2)
  266. {
  267. g.drawImage(HauntedCastle.hero9f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  268. cd++;
  269. HauntedCastle.pany+=5;
  270. HauntedCastle.panx+=5;
  271. }
  272.      else if(cd==3)
  273. {
  274. g.drawImage(HauntedCastle.hero5f,70,158+HauntedCastle.pany,Graphics.TOP|Graphics.LEFT );
  275. cd=0;
  276. HauntedCastle.pany+=5;
  277. HauntedCastle.panx+=5;
  278. }
  279. }
  280. public void blink(Graphics g)
  281. {
  282. if(HauntedCastle.pany!=0)
  283. {
  284.     walky=62;
  285. }
  286. else
  287. {
  288. walky=158;
  289. }
  290. if(hb==0||hb==2||hb==4){
  291. hb++;
  292. if(HauntedCastle.rightflag==true)
  293. {
  294. g.drawImage(HauntedCastle.hero1,70,walky,Graphics.TOP|Graphics.LEFT );
  295. }
  296. else if(HauntedCastle.leftflag==true)
  297. {
  298. g.drawImage(HauntedCastle.hero1f,70,walky,Graphics.TOP|Graphics.LEFT );
  299. }
  300. }
  301. else  if(hb==1||hb==3||hb==5){ hb++;}
  302. if(hb==6){
  303. hb=0;
  304. HauntedCastle.action = HauntedCastle.STAND;
  305. }
  306. }
  307. public void duck(Graphics g)
  308. {
  309. if(HauntedCastle.pany!=0)
  310. {
  311.     walky=62;
  312. }
  313. else
  314. {
  315. walky=158;
  316. }
  317. if(HauntedCastle.rightflag==true)
  318. {
  319. g.drawImage(HauntedCastle.hero10,70,walky,Graphics.TOP|Graphics.LEFT );
  320. }
  321. else if(HauntedCastle.leftflag==true)
  322. {
  323. g.drawImage(HauntedCastle.hero10f,70,walky,Graphics.TOP|Graphics.LEFT );
  324. }
  325. }
  326. public void charge(Graphics g)
  327. {
  328.     if(HauntedCastle.pany!=0)
  329. {
  330.     walky=62;bally=68; 
  331. }
  332. else
  333. {
  334. walky=158;bally=167;
  335. }
  336. if(HauntedCastle.rightflag==true)
  337. {
  338. g.drawImage(HauntedCastle.hero11,70,walky,Graphics.TOP|Graphics.LEFT );
  339. g.drawImage(HauntedCastle.firepower1,68,bally,Graphics.TOP|Graphics.LEFT );
  340. }
  341. else if(HauntedCastle.leftflag==true)
  342. {
  343. g.drawImage(HauntedCastle.hero11f,70,walky,Graphics.TOP|Graphics.LEFT );
  344. g.drawImage(HauntedCastle.firepower1,90,bally,Graphics.TOP|Graphics.LEFT );
  345. }
  346. }
  347. public void attack(Graphics g)
  348. {
  349. if(HauntedCastle.pany!=0)
  350. {
  351.     walky=62;bally=68; 
  352. }
  353. else
  354. {
  355. walky=158;bally=167;
  356. }
  357. if(HauntedCastle.rightflag==true)
  358. {
  359. if(HauntedCastle.fireright == true)
  360. {
  361. g.drawImage(HauntedCastle.hero12,70,walky,Graphics.TOP|Graphics.LEFT );
  362. }
  363. else if(HauntedCastle.fireup == true)
  364. {
  365. g.drawImage(HauntedCastle.hero13,70,walky,Graphics.TOP|Graphics.LEFT );
  366. }
  367. else if(HauntedCastle.firedown == true)
  368. {
  369. g.drawImage(HauntedCastle.hero14,70,walky,Graphics.TOP|Graphics.LEFT );
  370. }  
  371. }
  372. if(HauntedCastle.leftflag==true)
  373. {
  374. if(HauntedCastle.fireleft == true)
  375. {
  376. g.drawImage(HauntedCastle.hero12f,70,walky,Graphics.TOP|Graphics.LEFT );
  377. }
  378. else if(HauntedCastle.fireup == true)
  379. {
  380. g.drawImage(HauntedCastle.hero13f,70,walky,Graphics.TOP|Graphics.LEFT );
  381. }
  382. else if(HauntedCastle.firedown == true)
  383. {
  384. g.drawImage(HauntedCastle.hero14f,70,walky,Graphics.TOP|Graphics.LEFT );
  385. }  
  386. }
  387. }
  388.  
  389.  
  390.   public void fireBall(Graphics g)
  391. {
  392. if(HauntedCastle.pany!=0)
  393.     bally=68; 
  394. else
  395.     bally=167;
  396. if(HauntedCastle.rightflag==true)
  397. {
  398. if(HauntedCastle.fireright == true)
  399. {
  400. HauntedCastle.panballx+=15;
  401. g.drawImage(HauntedCastle.firepower2,80+HauntedCastle.panballx,bally,Graphics.TOP|Graphics.LEFT );
  402. }
  403. else if(HauntedCastle.fireup == true)
  404. {
  405. HauntedCastle.panballx+=15;
  406. HauntedCastle.panbally-=15;
  407. g.drawImage(HauntedCastle.firepower3,80+HauntedCastle.panballx,bally+HauntedCastle.panbally,Graphics.TOP|Graphics.LEFT );
  408. }
  409. else if(HauntedCastle.firedown == true)
  410. {
  411. HauntedCastle.panballx+=15;
  412. HauntedCastle.panbally+=15;
  413. g.drawImage(HauntedCastle.firepower4,80+HauntedCastle.panballx,bally+HauntedCastle.panbally,Graphics.TOP|Graphics.LEFT );
  414. }  
  415. }
  416. if(HauntedCastle.leftflag==true)
  417. {
  418. if(HauntedCastle.fireleft == true)
  419. {
  420. HauntedCastle.panballx-=15;
  421. g.drawImage(HauntedCastle.firepower2,80+HauntedCastle.panballx,bally,Graphics.TOP|Graphics.LEFT );
  422. }
  423. else if(HauntedCastle.fireup == true)
  424. {
  425. HauntedCastle.panballx-=15;
  426. HauntedCastle.panbally-=15;
  427. g.drawImage(HauntedCastle.firepower3,80+HauntedCastle.panballx,bally+HauntedCastle.panbally,Graphics.TOP|Graphics.LEFT );
  428. }
  429. else if(HauntedCastle.firedown == true)
  430. {
  431. HauntedCastle.panballx-=15;
  432. HauntedCastle.panbally+=15;
  433. g.drawImage(HauntedCastle.firepower4,80+HauntedCastle.panballx,bally+HauntedCastle.panbally,Graphics.TOP|Graphics.LEFT );
  434. }  
  435. }
  436. }
  437.   
  438. }