Guest User

Untitled

a guest
May 5th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.50 KB | None | 0 0
  1. import java.applet.Applet;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class RSApplet extends Applet implements Runnable, MouseListener, MouseMotionListener, KeyListener, FocusListener, WindowListener {
  6.  
  7. final void createClientFrame(int i, int j) {
  8. myWidth = j;
  9. myHeight = i;
  10. gameFrame = new RSFrame(this, myWidth, myHeight);
  11. graphics = getGameComponent().getGraphics();
  12. fullGameScreen = new RSImageProducer(myWidth, myHeight, getGameComponent());
  13. startRunnable(this, 1);
  14. }
  15.  
  16. final void initClientFrame(int i, int j) {
  17. myWidth = j;
  18. myHeight = i;
  19. graphics = getGameComponent().getGraphics();
  20. fullGameScreen = new RSImageProducer(myWidth, myHeight, getGameComponent());
  21. startRunnable(this, 1);
  22. }
  23.  
  24. public void run()
  25. {
  26. getGameComponent().addMouseListener(this);
  27. getGameComponent().addMouseMotionListener(this);
  28. getGameComponent().addKeyListener(this);
  29. getGameComponent().addFocusListener(this);
  30. if(gameFrame != null)
  31. gameFrame.addWindowListener(this);
  32. drawLoadingText(0, "Loading...");
  33. startUp();
  34. int i = 0;
  35. int j = 256;
  36. int k = 1;
  37. int i1 = 0;
  38. int j1 = 0;
  39. for(int k1 = 0; k1 < 10; k1++)
  40. aLongArray7[k1] = System.currentTimeMillis();
  41.  
  42. long l = System.currentTimeMillis();
  43. while(anInt4 >= 0)
  44. {
  45. if(anInt4 > 0)
  46. {
  47. anInt4--;
  48. if(anInt4 == 0)
  49. {
  50. exit();
  51. return;
  52. }
  53. }
  54. int i2 = j;
  55. int j2 = k;
  56. j = 300;
  57. k = 1;
  58. long l1 = System.currentTimeMillis();
  59. if(aLongArray7[i] == 0L)
  60. {
  61. j = i2;
  62. k = j2;
  63. } else
  64. if(l1 > aLongArray7[i])
  65. j = (int)((long)(2560 * delayTime) / (l1 - aLongArray7[i]));
  66. if(j < 25)
  67. j = 25;
  68. if(j > 256)
  69. {
  70. j = 256;
  71. k = (int)((long) delayTime - (l1 - aLongArray7[i]) / 10L);
  72. }
  73. if(k > delayTime)
  74. k = delayTime;
  75. aLongArray7[i] = l1;
  76. i = (i + 1) % 10;
  77. if(k > 1)
  78. {
  79. for(int k2 = 0; k2 < 10; k2++)
  80. if(aLongArray7[k2] != 0L)
  81. aLongArray7[k2] += k;
  82.  
  83. }
  84. if(k < minDelay)
  85. k = minDelay;
  86. try
  87. {
  88. Thread.sleep(k);
  89. }
  90. catch(InterruptedException _ex)
  91. {
  92. j1++;
  93. }
  94. for(; i1 < 256; i1 += j)
  95. {
  96. clickMode3 = clickMode1;
  97. saveClickX = clickX;
  98. saveClickY = clickY;
  99. aLong29 = clickTime;
  100. clickMode1 = 0;
  101. processGameLoop();
  102. readIndex = writeIndex;
  103. }
  104.  
  105. i1 &= 0xff;
  106. if(delayTime > 0)
  107. fps = (1000 * j) / (delayTime * 256);
  108. processDrawing();
  109. if(shouldDebug)
  110. {
  111. System.out.println("ntime:" + l1);
  112. for(int l2 = 0; l2 < 10; l2++)
  113. {
  114. int i3 = ((i - l2 - 1) + 20) % 10;
  115. System.out.println("otim" + i3 + ":" + aLongArray7[i3]);
  116. }
  117.  
  118. System.out.println("fps:" + fps + " ratio:" + j + " count:" + i1);
  119. System.out.println("del:" + k + " deltime:" + delayTime + " mindel:" + minDelay);
  120. System.out.println("intex:" + j1 + " opos:" + i);
  121. shouldDebug = false;
  122. j1 = 0;
  123. }
  124. }
  125. if(anInt4 == -1)
  126. exit();
  127. }
  128.  
  129. private void exit()
  130. {
  131. anInt4 = -2;
  132. cleanUpForQuit();
  133. if(gameFrame != null)
  134. {
  135. try
  136. {
  137. Thread.sleep(1000L);
  138. }
  139. catch(Exception _ex) { }
  140. try
  141. {
  142. System.exit(0);
  143. }
  144. catch(Throwable _ex) { }
  145. }
  146. }
  147.  
  148. final void method4(int i)
  149. {
  150. delayTime = 1000 / i;
  151. }
  152.  
  153. public final void start()
  154. {
  155. if(anInt4 >= 0)
  156. anInt4 = 0;
  157. }
  158.  
  159. public final void stop()
  160. {
  161. if(anInt4 >= 0)
  162. anInt4 = 4000 / delayTime;
  163. }
  164.  
  165. public final void destroy()
  166. {
  167. anInt4 = -1;
  168. try
  169. {
  170. Thread.sleep(5000L);
  171. }
  172. catch(Exception _ex) { }
  173. if(anInt4 == -1)
  174. exit();
  175. }
  176.  
  177. public final void update(Graphics g)
  178. {
  179. if(graphics == null)
  180. graphics = g;
  181. shouldClearScreen = true;
  182. raiseWelcomeScreen();
  183. }
  184.  
  185. public final void paint(Graphics g)
  186. {
  187. if(graphics == null)
  188. graphics = g;
  189. shouldClearScreen = true;
  190. raiseWelcomeScreen();
  191. }
  192.  
  193. public final void mousePressed(MouseEvent mouseevent)
  194. {
  195. int i = mouseevent.getX();
  196. int j = mouseevent.getY();
  197. if(gameFrame != null)
  198. {
  199. i -= 4;//4
  200. j -= 22;//22
  201. }
  202. idleTime = 0;
  203. clickX = i;
  204. clickY = j;
  205. clickTime = System.currentTimeMillis();
  206. if(mouseevent.isMetaDown())
  207. {
  208. clickMode1 = 2;
  209. clickMode2 = 2;
  210. } else
  211. {
  212. clickMode1 = 1;
  213. clickMode2 = 1;
  214. }
  215. }
  216.  
  217. public final void mouseReleased(MouseEvent mouseevent)
  218. {
  219. idleTime = 0;
  220. clickMode2 = 0;
  221. }
  222.  
  223. public final void mouseClicked(MouseEvent mouseevent)
  224. {
  225. }
  226.  
  227. public final void mouseEntered(MouseEvent mouseevent)
  228. {
  229. }
  230.  
  231. public final void mouseExited(MouseEvent mouseevent)
  232. {
  233. idleTime = 0;
  234. mouseX = -1;
  235. mouseY = -1;
  236. }
  237.  
  238. public final void mouseDragged(MouseEvent mouseevent)
  239. {
  240. int i = mouseevent.getX();
  241. int j = mouseevent.getY();
  242. if(gameFrame != null)
  243. {
  244. i -= 4;
  245. j -= 22;
  246. }
  247. idleTime = 0;
  248. mouseX = i;
  249. mouseY = j;
  250. }
  251.  
  252. public final void mouseMoved(MouseEvent mouseevent)
  253. {
  254. int i = mouseevent.getX();
  255. int j = mouseevent.getY();
  256. if(gameFrame != null)
  257. {
  258. i -= 4;
  259. j -= 22;
  260. }
  261. idleTime = 0;
  262. mouseX = i;
  263. mouseY = j;
  264. }
  265. public static int hotKey = 508;
  266. public final void keyPressed(KeyEvent keyevent)
  267. {
  268. idleTime = 0;
  269. int i = keyevent.getKeyCode();
  270. int j = keyevent.getKeyChar();
  271. //hotkeys here
  272. if (hotKey == 508) {
  273. if(i == KeyEvent.VK_ESCAPE){
  274. //client.setTab(3);
  275. } else if(i == KeyEvent.VK_F1){
  276. client.setTab(3);
  277. } else if(i == KeyEvent.VK_F2){
  278. client.setTab(4);
  279. } else if(i == KeyEvent.VK_F3){
  280. client.setTab(5);
  281. } else if(i == KeyEvent.VK_F4){
  282. client.setTab(6);
  283. } else if(i == KeyEvent.VK_F5){
  284. client.setTab(0);
  285. /*} else if(i == KeyEvent.VK_F6){
  286. client.setTab(5);
  287. } else if(i == KeyEvent.VK_F7){
  288. client.setTab(6);
  289. } else if(i == KeyEvent.VK_F8){
  290. client.setTab(7);
  291. } else if(i == KeyEvent.VK_F9){
  292. client.setTab(8);
  293. } else if(i == KeyEvent.VK_F10){
  294. client.setTab(9);
  295. } else if(i == KeyEvent.VK_F11){
  296. client.setTab(10);
  297. } else if(i == KeyEvent.VK_F12){
  298. client.setTab(11);*/
  299. }
  300. } else {
  301. if(i == KeyEvent.VK_ESCAPE){
  302. //client.setTab(3);
  303. } else if(i == KeyEvent.VK_F1){
  304. client.setTab(3);
  305. } else if(i == KeyEvent.VK_F2){
  306. client.setTab(4);
  307. } else if(i == KeyEvent.VK_F3){
  308. client.setTab(5);
  309. } else if(i == KeyEvent.VK_F4){
  310. client.setTab(6);
  311. } else if(i == KeyEvent.VK_F5){
  312. client.setTab(0);
  313. /*} else if(i == KeyEvent.VK_F6){
  314. client.setTab(5);
  315. } else if(i == KeyEvent.VK_F7){
  316. client.setTab(6);
  317. } else if(i == KeyEvent.VK_F8){
  318. client.setTab(7);
  319. } else if(i == KeyEvent.VK_F9){
  320. client.setTab(8);
  321. } else if(i == KeyEvent.VK_F10){
  322. client.setTab(9);
  323. } else if(i == KeyEvent.VK_F11){
  324. client.setTab(10);
  325. } else if(i == KeyEvent.VK_F12){
  326. client.setTab(11);*/
  327. }
  328. }
  329. //end of hotkeys
  330. if(j < 30)
  331. j = 0;
  332. if(i == 37)
  333. j = 1;
  334. if(i == 39)
  335. j = 2;
  336. if(i == 38)
  337. j = 3;
  338. if(i == 40)
  339. j = 4;
  340. if(i == 17)
  341. j = 5;
  342. if(i == 8)
  343. j = 8;
  344. if(i == 127)
  345. j = 8;
  346. if(i == 9)
  347. j = 9;
  348. if(i == 10)
  349. j = 10;
  350. if(i >= 112 && i <= 123)
  351. j = (1008 + i) - 112;
  352. if(i == 36)
  353. j = 1000;
  354. if(i == 35)
  355. j = 1001;
  356. if(i == 33)
  357. j = 1002;
  358. if(i == 34)
  359. j = 1003;
  360. if(j > 0 && j < 128)
  361. keyArray[j] = 1;
  362. if(j > 4)
  363. {
  364. charQueue[writeIndex] = j;
  365. writeIndex = writeIndex + 1 & 0x7f;
  366. }
  367. }
  368.  
  369. public final void keyReleased(KeyEvent keyevent)
  370. {
  371. idleTime = 0;
  372. int i = keyevent.getKeyCode();
  373. char c = keyevent.getKeyChar();
  374. if(c < '\036')
  375. c = '\0';
  376. if(i == 37)
  377. c = '\001';
  378. if(i == 39)
  379. c = '\002';
  380. if(i == 38)
  381. c = '\003';
  382. if(i == 40)
  383. c = '\004';
  384. if(i == 17)
  385. c = '\005';
  386. if(i == 8)
  387. c = '\b';
  388. if(i == 127)
  389. c = '\b';
  390. if(i == 9)
  391. c = '\t';
  392. if(i == 10)
  393. c = '\n';
  394. if(c > 0 && c < '\200')
  395. keyArray[c] = 0;
  396. }
  397.  
  398. public final void keyTyped(KeyEvent keyevent)
  399. {
  400. }
  401.  
  402. final int readChar(int dummy)
  403. {
  404. while(dummy >= 0)
  405. {
  406. for(int j = 1; j > 0; j++);
  407. }
  408. int k = -1;
  409. if(writeIndex != readIndex)
  410. {
  411. k = charQueue[readIndex];
  412. readIndex = readIndex + 1 & 0x7f;
  413. }
  414. return k;
  415. }
  416.  
  417. public final void focusGained(FocusEvent focusevent)
  418. {
  419. awtFocus = true;
  420. shouldClearScreen = true;
  421. raiseWelcomeScreen();
  422. }
  423.  
  424. public final void focusLost(FocusEvent focusevent)
  425. {
  426. awtFocus = false;
  427. for(int i = 0; i < 128; i++)
  428. keyArray[i] = 0;
  429.  
  430. }
  431.  
  432. public final void windowActivated(WindowEvent windowevent)
  433. {
  434. }
  435.  
  436. public final void windowClosed(WindowEvent windowevent)
  437. {
  438. }
  439.  
  440. public final void windowClosing(WindowEvent windowevent)
  441. {
  442. destroy();
  443. }
  444.  
  445. public final void windowDeactivated(WindowEvent windowevent)
  446. {
  447. }
  448.  
  449. public final void windowDeiconified(WindowEvent windowevent)
  450. {
  451. }
  452.  
  453. public final void windowIconified(WindowEvent windowevent)
  454. {
  455. }
  456.  
  457. public final void windowOpened(WindowEvent windowevent)
  458. {
  459. }
  460.  
  461. void startUp()
  462. {
  463. }
  464.  
  465. void processGameLoop()
  466. {
  467. }
  468.  
  469. void cleanUpForQuit()
  470. {
  471. }
  472.  
  473. void processDrawing()
  474. {
  475. }
  476.  
  477. void raiseWelcomeScreen()
  478. {
  479. }
  480.  
  481. Component getGameComponent()
  482. {
  483. if(gameFrame != null)
  484. return gameFrame;
  485. else
  486. return this;
  487. }
  488.  
  489. public void startRunnable(Runnable runnable, int priority)
  490. {
  491. Thread thread = new Thread(runnable);
  492. thread.start();
  493. thread.setPriority(priority);
  494. }
  495.  
  496. void drawLoadingText(int i, String s)
  497. {
  498. while(graphics == null)
  499. {
  500. graphics = getGameComponent().getGraphics();
  501. try
  502. {
  503. getGameComponent().repaint();
  504. }
  505. catch(Exception _ex) { }
  506. try
  507. {
  508. Thread.sleep(1000L);
  509. }
  510. catch(Exception _ex) { }
  511. }
  512. Font font = new Font("Helvetica", 1, 13);
  513. FontMetrics fontmetrics = getGameComponent().getFontMetrics(font);
  514. Font font1 = new Font("Helvetica", 0, 13);
  515. getGameComponent().getFontMetrics(font1);
  516. if(shouldClearScreen)
  517. {
  518. graphics.setColor(Color.black);
  519. graphics.fillRect(0, 0, myWidth, myHeight);
  520. shouldClearScreen = false;
  521. }
  522. Color color = new Color(140, 17, 17);
  523. int j = myHeight / 2 - 18;
  524. graphics.setColor(color);
  525. graphics.drawRect(myWidth / 2 - 152, j, 304, 33);
  526. graphics.fillRect(myWidth / 2 - 150, j + 2, i * 3, 30);
  527. graphics.setColor(Color.black);
  528. graphics.fillRect((myWidth / 2 - 150) + i * 3, j + 2, 300 - i * 3, 30);
  529. graphics.setFont(font);
  530. graphics.setColor(Color.white);
  531. //graphics.drawString("SlashScape is Loading... Please wait.", (myWidth -
  532. // fontmetrics.stringWidth("SlashScape is Loading... Please wait.")) / 2, j - 11);
  533. graphics.drawString(s, (myWidth - fontmetrics.stringWidth(s)) / 2, j + 22);
  534. }
  535.  
  536. RSApplet()
  537. {
  538. delayTime = 20;
  539. minDelay = 1;
  540. aLongArray7 = new long[10];
  541. shouldDebug = false;
  542. shouldClearScreen = true;
  543. awtFocus = true;
  544. keyArray = new int[128];
  545. charQueue = new int[128];
  546. }
  547.  
  548. private int anInt4;
  549. private int delayTime;
  550. int minDelay;
  551. private final long[] aLongArray7;
  552. int fps;
  553. boolean shouldDebug;
  554. int myWidth;
  555. int myHeight;
  556. Graphics graphics;
  557. RSImageProducer fullGameScreen;
  558. RSFrame gameFrame;
  559. private boolean shouldClearScreen;
  560. boolean awtFocus;
  561. int idleTime;
  562. int clickMode2;
  563. public int mouseX;
  564. public int mouseY;
  565. private int clickMode1;
  566. private int clickX;
  567. private int clickY;
  568. private long clickTime;
  569. int clickMode3;
  570. int saveClickX;
  571. int saveClickY;
  572. long aLong29;
  573. final int[] keyArray;
  574. private final int[] charQueue;
  575. private int readIndex;
  576. private int writeIndex;
  577. public static int anInt34;
  578. }
Advertisement
Add Comment
Please, Sign In to add comment