Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. public class collision {
  2.  
  3.  
  4. public static boolean iscolliding(Point p,block b){
  5. return b.contains(p);
  6.  
  7. }
  8.  
  9. public class block extends Rectangle {
  10. private static final long serialVersionUID = 1L;
  11.  
  12. public static int blocksize = 40;
  13. private int id;
  14.  
  15. private Image i;
  16.  
  17. public static Rectangle r = new Rectangle(Comp.mx, Comp.my, 1, 1);
  18.  
  19. public static boolean c = false;
  20.  
  21.  
  22. public block(int x, int y, int id) {
  23. setBounds(x, y, blocksize, blocksize);
  24. this.id = id;
  25. }
  26.  
  27. public void render(Graphics g) {
  28. g.setColor(Color.green);
  29.  
  30. if (id == 0) {
  31. ImageIcon i62 = new ImageIcon("res/tiles/air.png");
  32. i = i62.getImage();
  33. g.drawImage(i, x - play.camx, y - play.camy, null);
  34.  
  35. }
  36. if (id == 1) {
  37. ImageIcon i62 = new ImageIcon("res/tiles/dirt.png");
  38. i = i62.getImage();
  39. g.drawImage(i, x - play.camx, y - play.camy, null);
  40.  
  41. }
  42. if (id == 2) {
  43. ImageIcon i62 = new ImageIcon("res/tiles/roots.png");
  44. i = i62.getImage();
  45. g.drawImage(i, x - play.camx, y - play.camy, null);
  46.  
  47. }
  48. if (id == 3) {
  49. ImageIcon i62 = new ImageIcon("res/tiles/hellgrasses/hellsoil.png");
  50. i = i62.getImage();
  51. g.drawImage(i, x - play.camx, y - play.camy, null);
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
  66.  
  67. public void setID(int id) {
  68. this.id = id;
  69. }
  70.  
  71. public int getID() {
  72. return id;
  73. }
  74.  
  75. public double x,y;
  76.  
  77. public boolean dead;
  78.  
  79. public Rectangle r = new Rectangle((int)x, (int)y,20,20);
  80.  
  81. public boolean canmove;
  82.  
  83. public blob (int x, int y){
  84. this.x = x;
  85. this.y = y;
  86. }
  87.  
  88. public void tick(){
  89. r = new Rectangle((int)x- play.camx, (int)y-play.camy,20,20);
  90.  
  91. if(!play.isPaused){
  92. if(x > play.p.x+ play.camx){
  93. x-=.2;
  94. }
  95. if(x < play.p.x+ play.camx){
  96. x+=.2;
  97. }
  98. if(y > play.p.y+ play.camy){
  99. y-=.2;
  100. }
  101. if(y < play.p.y+ play.camy){
  102. y+=.2;
  103. }
  104.  
  105. if(r.intersects(play.p.r)){
  106. play.p.health-=1;
  107. }
  108. }
  109.  
  110. if(dead){
  111. if(new Random().nextInt(100) >= 95){
  112. play.hp.add(new healthPack((int)x,(int)y));
  113. }
  114. }
  115. }
  116.  
  117. public void render(Graphics g){
  118. g.setColor(Color.green);
  119. g.fillRect((int)x - play.camx, (int)y -play.camy, 20, 20);
  120. g.setColor(Color.red);
  121. g.drawRect((int)r.x , (int)r.y, 20, 20);
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement