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
{
12 public boolean pickedUp
= false;
13 public Vector2 move
, pos
;
15 public Drop(float x
, float y
, int id
) {
17 pos
= new Vector2(x
, y
);
18 move
= new Vector2(0, -1);
21 public int closeToPlayer(GameProc gp
) {
22 boolean c1
= Intersector
.overlaps(new Rectangle(gp
.player
.pos
.x
- 16, gp
.player
.pos
.y
- 16, gp
.player
.texWidth
+ 32, gp
.player
.height
+ 32), getRect());
23 boolean c2
= Intersector
.overlaps(new Rectangle((gp
.player
.pos
.x
+ gp
.world
.getWidth() * 16) - 16, gp
.player
.pos
.y
- 16, gp
.player
.texWidth
+ 32, gp
.player
.height
+ 32), getRect());
24 boolean c3
= Intersector
.overlaps(new Rectangle((gp
.player
.pos
.x
- gp
.world
.getWidth() * 16) - 16, gp
.player
.pos
.y
- 16, gp
.player
.texWidth
+ 32, gp
.player
.height
+ 32), getRect());
31 public void moveToPlayer(GameProc gp
) {
32 int ctp
= closeToPlayer(gp
);
34 float px
= gp
.player
.pos
.x
;
35 float py
= gp
.player
.pos
.y
;
38 px
+= gp
.world
.getWidth() * 16;
41 px
-= gp
.world
.getWidth() * 16;
45 if (px
+ gp
.player
.texWidth
< pos
.x
+ 4) dx
= -.5f;
46 else if (px
> pos
.x
+ 4) dx
= .5f;
47 if (py
+ gp
.player
.height
< pos
.y
+ 4) dy
= -.5f;
48 else if (py
> pos
.y
+ 4) dy
= .5f;
50 if (move
.x
> 2) move
.x
= 1;
51 if (move
.x
< -2) move
.x
= -1;
52 if (move
.y
> 2) move
.y
= 1;
53 if (move
.y
< -2) move
.y
= -1;
57 public void pickUpDrop(Player pl
) {
58 for (int i
= 0; i
< pl
.inv
.length
; i
++) {
59 if (pl
.inv
[i
] == 0 || pl
.inv
[i
] == id
) {
71 public Rectangle
getRect() {
72 return new Rectangle(pos
.x
, pos
.y
, 8, 8);