1 package ru
.deadsoftware
.cavecraft
.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
.cavecraft
.game
.GameProc
;
8 import java
.io
.Serializable
;
10 public class Drop
implements Serializable
{
13 public boolean pickedUp
= false;
14 public Vector2 move
, pos
;
16 public Drop(float x
, float y
, int id
) {
18 pos
= new Vector2(x
, y
);
19 move
= new Vector2(0, -1);
22 public int closeToPlayer(GameProc gp
) {
23 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());
24 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());
25 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());
32 public void moveToPlayer(GameProc gp
) {
33 int ctp
= closeToPlayer(gp
);
35 float px
= gp
.player
.pos
.x
;
36 float py
= gp
.player
.pos
.y
;
39 px
+= gp
.world
.getWidthPx();
42 px
-= gp
.world
.getWidthPx();
46 if (px
+ gp
.player
.getWidth() < pos
.x
+ 4) dx
= -.5f;
47 else if (px
> pos
.x
+ 4) dx
= .5f;
48 if (py
+ gp
.player
.getHeight() < pos
.y
+ 4) dy
= -.5f;
49 else if (py
> pos
.y
+ 4) dy
= .5f;
51 if (move
.x
> 2) move
.x
= 1;
52 if (move
.x
< -2) move
.x
= -1;
53 if (move
.y
> 2) move
.y
= 1;
54 if (move
.y
< -2) move
.y
= -1;
58 public void pickUpDrop(Player pl
) {
59 for (int i
= 0; i
< pl
.inv
.length
; i
++) {
60 if (pl
.inv
[i
] == 0 || pl
.inv
[i
] == id
) {
72 public Rectangle
getRect() {
73 return new Rectangle(pos
.x
, pos
.y
, 8, 8);