1 package ru
.deadsoftware
.cavedroid
.game
.objects
;
3 import com
.badlogic
.gdx
.math
.Intersector
;
4 import com
.badlogic
.gdx
.math
.MathUtils
;
5 import com
.badlogic
.gdx
.math
.Rectangle
;
6 import com
.badlogic
.gdx
.math
.Vector2
;
7 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Player
;
9 import java
.io
.Serializable
;
11 import static ru
.deadsoftware
.cavedroid
.GameScreen
.GP
;
13 public class Drop
extends Rectangle
implements Serializable
{
16 private final Vector2 move
;
17 private boolean pickedUp
= false;
19 public Drop(float x
, float y
, int id
) {
22 this.move
= new Vector2(0, -1);
25 public Vector2
getMove() {
29 public int closeToPlayer() {
30 boolean[] c
= new boolean[3];
32 c
[0] = Intersector
.overlaps(new Rectangle(GP
.player
.getX() - 16,
33 GP
.player
.getY() - 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32), this);
34 c
[1] = Intersector
.overlaps(new Rectangle((GP
.player
.getX() + GP
.world
.getWidthPx()) - 16,
35 GP
.player
.getY() - 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32), this);
36 c
[2] = Intersector
.overlaps(new Rectangle((GP
.player
.getX() - GP
.world
.getWidthPx()) - 16,
37 GP
.player
.getY() - 16, GP
.player
.getWidth() + 32, GP
.player
.getHeight() + 32), this);
39 for (int i
= 0; i
< 3; i
++) {
48 public void moveToPlayer() {
49 int ctp
= closeToPlayer();
51 float px
= GP
.player
.getX();
52 float py
= GP
.player
.getY();
56 px
+= GP
.world
.getWidthPx();
59 px
-= GP
.world
.getWidthPx();
65 if (px
+ GP
.player
.getWidth() < x
+ 4) {
67 } else if (px
> x
+ 4) {
71 if (py
+ GP
.player
.getHeight() < y
+ 4) {
73 } else if (py
> y
+ 4) {
81 } else if (move
.x
< -2) {
87 } else if (move
.y
< -2) {
93 public void pickUpDrop(Player pl
) {
94 for (int i
= 0; i
< pl
.inventory
.length
; i
++) {
95 if (pl
.inventory
[i
] == 0 || pl
.inventory
[i
] == id
) {
103 private void checkWorldBounds() {
104 if (x
+ 8 > GP
.world
.getWidthPx()) {
105 x
-= GP
.world
.getWidthPx();
107 x
+= GP
.world
.getWidthPx();
115 y
= MathUtils
.round(y
);
122 public boolean isPickedUp() {
126 public void setPickedUp(boolean pickedUp
) {
127 this.pickedUp
= pickedUp
;