1 package ru
.deadsoftware
.cavedroid
.game
.objects
;
3 import com
.badlogic
.gdx
.math
.Intersector
;
4 import com
.badlogic
.gdx
.math
.Rectangle
;
5 import com
.badlogic
.gdx
.math
.Vector2
;
7 import java
.io
.Serializable
;
9 import static ru
.deadsoftware
.cavedroid
.GameScreen
.GP
;
11 public class Drop
implements Serializable
{
14 public boolean pickedUp
= false;
15 public Vector2 move
, pos
;
17 public Drop(float x
, float y
, int id
) {
19 pos
= new Vector2(x
, y
);
20 move
= new Vector2(0, -1);
23 public int closeToPlayer() {
24 boolean c1
= Intersector
.overlaps(new Rectangle(GP
.player
.pos
.x
- 16, GP
.player
.pos
.y
- 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32), getRect());
25 boolean c2
= Intersector
.overlaps(new Rectangle((GP
.player
.pos
.x
+ GP
.world
.getWidthPx()) - 16, GP
.player
.pos
.y
- 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32), getRect());
26 boolean c3
= Intersector
.overlaps(new Rectangle((GP
.player
.pos
.x
- GP
.world
.getWidthPx()) - 16, GP
.player
.pos
.y
- 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32), getRect());
33 public void moveToPlayer() {
34 int ctp
= closeToPlayer();
36 float px
= GP
.player
.pos
.x
;
37 float py
= GP
.player
.pos
.y
;
40 px
+= GP
.world
.getWidthPx();
43 px
-= GP
.world
.getWidthPx();
47 if (px
+ GP
.player
.getWidth() < pos
.x
+ 4) dx
= -.5f;
48 else if (px
> pos
.x
+ 4) dx
= .5f;
49 if (py
+ GP
.player
.getHeight() < pos
.y
+ 4) dy
= -.5f;
50 else if (py
> pos
.y
+ 4) dy
= .5f;
52 if (move
.x
> 2) move
.x
= 1;
53 if (move
.x
< -2) move
.x
= -1;
54 if (move
.y
> 2) move
.y
= 1;
55 if (move
.y
< -2) move
.y
= -1;
59 public void pickUpDrop(Player pl
) {
60 for (int i
= 0; i
< pl
.inv
.length
; i
++) {
61 if (pl
.inv
[i
] == 0 || pl
.inv
[i
] == id
) {
73 public Rectangle
getRect() {
74 return new Rectangle(pos
.x
, pos
.y
, 8, 8);