Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. package Koroljov.company;
  2.  
  3. import Koroljov.company.GameWindow;
  4.  
  5. import java.awt.*;
  6. import java.awt.event.MouseAdapter;
  7. import java.awt.event.MouseEvent;
  8. import java.io.IOException;
  9.  
  10. public class mousePressed extends MouseAdapter {
  11. @Override
  12. public void mousePressed(MouseEvent e) {
  13. if(e.getButton() == MouseEvent.BUTTON3)
  14. {
  15. if(GameWindow.pause)
  16. {
  17. GameWindow.pause=false;
  18. GameWindow.drop_v = GameWindow.drop_speed_save;
  19. try
  20. {
  21. Robot r = new Robot();
  22. r.mouseMove((int)GameWindow.mousecordX, (int)GameWindow.mousecordY);
  23. }
  24. catch (AWTException ee)
  25. {
  26.  
  27. }
  28. }
  29. else {
  30. GameWindow.drop_speed_save = GameWindow.drop_v;
  31. GameWindow.drop_v = 0;
  32. GameWindow.mousecordX = MouseInfo.getPointerInfo().getLocation().getX();
  33. GameWindow.mousecordY = MouseInfo.getPointerInfo().getLocation().getY();
  34. GameWindow.pause = true;
  35. }
  36. }
  37.  
  38. if(e.getButton() == MouseEvent.BUTTON1)
  39. {
  40. if(GameWindow.pause) return;
  41.  
  42. int x = e.getX();
  43. int y = e.getY();
  44.  
  45.  
  46.  
  47. float drop_right = GameWindow.drop_left + GameWindow.car.getWidth(null);
  48. float drop_bottom = GameWindow.drop_top + GameWindow.car.getHeight(null);
  49. boolean is_drop = x >= GameWindow.drop_left && x <= drop_right && y >= GameWindow.drop_top && y <= drop_bottom;
  50. if(is_drop){
  51. if(!(GameWindow.dropWaterFall_height > 25 && GameWindow.dropWaterFall_width > 50)) {
  52. GameWindow.dropWaterFall_width = GameWindow.dropWaterFall_width -1;
  53. GameWindow.dropWaterFall_height = GameWindow.dropWaterFall_height -2;
  54. try {
  55. GameWindow.dropWaterFallResize();
  56. }
  57. catch (IOException ioe){
  58.  
  59. }
  60. }
  61.  
  62. //drop_top = 200;
  63. GameWindow.drop_top = -100;
  64. GameWindow.drop_left = (int) (Math.random() * (GameWindow.game_field.getWidth() - GameWindow.car.getWidth(null)));
  65. GameWindow.drop_v = GameWindow.drop_v + 20;
  66. GameWindow.score++;
  67. GameWindow.onDirection();
  68. GameWindow.game_window.setTitle("Score: " + GameWindow.score);
  69. }
  70.  
  71. if(GameWindow.end){
  72. boolean isRestart = x>=0 & x <= 0 + GameWindow.restart.getWidth(null) && y >= 0 && y <= 0 + GameWindow.restart.getHeight(null);
  73. if(isRestart){
  74. GameWindow.end = false;
  75. GameWindow.score = 0;
  76. GameWindow.game_window.setTitle("Score: " + GameWindow.score);
  77. GameWindow.drop_top=-100;
  78. //drop_top=200;
  79. GameWindow.drop_left = (int) (Math.random()*(GameWindow.game_field.getWidth()- GameWindow.car.getWidth(null)));
  80. GameWindow.drop_v = 200;
  81. GameWindow.dropWaterFall_width = 129;
  82. GameWindow.dropWaterFall_height = 178;
  83. GameWindow.car_width = 310;
  84. GameWindow.car_height = 125;
  85. GameWindow.isRecorded = false;
  86. GameWindow.drawRecords = false;
  87. }
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement