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
;
6 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Player
;
8 import java
.io
.Serializable
;
10 import static ru
.deadsoftware
.cavedroid
.GameScreen
.GP
;
12 public class Drop
implements Serializable
{
15 public boolean pickedUp
= false;
16 public final Vector2 move
;
17 public final Vector2 pos
;
19 public Drop(float x
, float y
, int id
) {
21 pos
= new Vector2(x
, y
);
22 move
= new Vector2(0, -1);
25 public int closeToPlayer() {
26 boolean[] c
= new boolean[3];
28 c
[0] = Intersector
.overlaps(new Rectangle(GP
.player
.getX() - 16,
29 GP
.player
.getY() - 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32),
31 c
[1] = Intersector
.overlaps(new Rectangle((GP
.player
.getX() + GP
.world
.getWidthPx()) - 16,
32 GP
.player
.getY() - 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32),
34 c
[2] = Intersector
.overlaps(new Rectangle((GP
.player
.getX() - GP
.world
.getWidthPx()) - 16,
35 GP
.player
.getY() - 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32),
38 for (int i
= 0; i
< 3; i
++) {
46 public void moveToPlayer() {
47 int ctp
= closeToPlayer();
49 float px
= GP
.player
.getX();
50 float py
= GP
.player
.getY();
53 px
+= GP
.world
.getWidthPx();
56 px
-= GP
.world
.getWidthPx();
60 if (px
+ GP
.player
.getWidth() < pos
.x
+ 4) {
62 } else if (px
> pos
.x
+ 4) {
66 if (py
+ GP
.player
.getHeight() < pos
.y
+ 4) {
68 } else if (py
> pos
.y
+ 4) {
76 } else if (move
.x
< -2) {
82 } else if (move
.y
< -2) {
88 public void pickUpDrop(Player pl
) {
89 for (int i
= 0; i
< pl
.inventory
.length
; i
++) {
90 if (pl
.inventory
[i
] == 0 || pl
.inventory
[i
] == id
) {
102 public Rectangle
getRect() {
103 return new Rectangle(pos
.x
, pos
.y
, 8, 8);