995c79e9bc88a544804c740f8ac5582e9ed68610
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
.world
.GameWorld
;
8 import ru
.deadsoftware
.cavedroid
.game
.mobs
.Player
;
10 import java
.io
.Serializable
;
12 public class Drop
extends Rectangle
implements Serializable
{
15 private final Vector2 velocity
;
16 private boolean pickedUp
= false;
18 Drop(float x
, float y
, int id
) {
21 this.velocity
= new Vector2(0, -1);
24 public Vector2
getVelocity() {
28 public int closeToPlayer(GameWorld gameWorld
, Player player
) {
29 boolean[] c
= new boolean[3];
31 c
[0] = Intersector
.overlaps(new Rectangle(player
.getX() - 16,
32 player
.getY() - 16, player
.getWidth() + 32, player
.getHeight() + 32), this);
33 c
[1] = Intersector
.overlaps(new Rectangle((player
.getX() + gameWorld
.getWidthPx()) - 16,
34 player
.getY() - 16, player
.getWidth() + 32, player
.getHeight() + 32), this);
35 c
[2] = Intersector
.overlaps(new Rectangle((player
.getX() - gameWorld
.getWidthPx()) - 16,
36 player
.getY() - 16, player
.getWidth() + 32, player
.getHeight() + 32), this);
38 for (int i
= 0; i
< 3; i
++) {
47 public void moveToPlayer(GameWorld gameWorld
, Player player
, int ctp
) {
49 float px
= player
.getX();
50 float py
= player
.getY();
54 px
+= gameWorld
.getWidthPx();
57 px
-= gameWorld
.getWidthPx();
63 if (px
+ player
.getWidth() < x
+ 4) {
65 } else if (px
> x
+ 4) {
69 if (py
+ player
.getHeight() < y
+ 4) {
71 } else if (py
> y
+ 4) {
79 } else if (velocity
.x
< -2) {
85 } else if (velocity
.y
< -2) {
91 public void pickUpDrop(Player pl
) {
92 for (int i
= 0; i
< pl
.inventory
.length
; i
++) {
93 if (pl
.inventory
[i
] == 0 || pl
.inventory
[i
] == id
) {
101 private void checkWorldBounds() {
102 // if (x + 8 > world.getWidthPx()) {
103 // x -= world.getWidthPx();
104 // } else if (x < 0) {
105 // x += world.getWidthPx();
109 public void move(float delta
) {
110 x
+= velocity
.x
* delta
;
111 y
+= velocity
.y
* delta
;
113 y
= MathUtils
.round(y
);
120 public boolean isPickedUp() {
124 public void setPickedUp(boolean pickedUp
) {
125 this.pickedUp
= pickedUp
;