Implemented item pickup from ground

This commit is contained in:
Collin Smith 2019-03-11 23:53:25 -07:00
parent 20aa0e79e3
commit 053c975fe7
3 changed files with 39 additions and 10 deletions

View File

@ -9,10 +9,11 @@ import com.riiablo.graphics.BlendMode;
import com.riiablo.graphics.PaletteIndexedBatch;
import com.riiablo.item.Item;
import com.riiablo.map.DT1;
import com.riiablo.screen.GameScreen;
public class ItemHolder extends Entity {
Item item;
public Item item;
AssetDescriptor<DC6> flippyDescriptor;
DC flippy;
@ -35,6 +36,16 @@ public class ItemHolder extends Entity {
return DT1.Tile.SUBTILE_HEIGHT;
}
@Override
public float getInteractRange() {
return 2;
}
@Override
public void interact(GameScreen gameScreen) {
gameScreen.pickup(this);
}
@Override
protected void updateCOF() {
Riiablo.assets.load(flippyDescriptor);

View File

@ -6,8 +6,10 @@ import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.riiablo.Riiablo;
import com.riiablo.entity.Entity;
import com.riiablo.entity.ItemHolder;
import com.riiablo.item.Item;
import com.riiablo.screen.GameScreen;
public class MapListener {
@ -20,7 +22,7 @@ public class MapListener {
MapRenderer mapRenderer;
Entity target;
boolean requireRelease;
public boolean requireRelease;
public MapListener(GameScreen gameScreen, Map map, MapRenderer mapRenderer) {
this.gameScreen = gameScreen;
@ -80,6 +82,16 @@ public class MapListener {
updateLabel(tmpVec2);
boolean pressed = Gdx.input.isButtonPressed(Input.Buttons.LEFT);
if (pressed && !requireRelease) {
Item cursor = Riiablo.cursor.getItem();
if (cursor != null) {
Riiablo.cursor.setItem(null);
Entity item = new ItemHolder(cursor);
item.position().set(gameScreen.player.position());
gameScreen.entities.put(gameScreen.entities.size + 1, item);
requireRelease = true;
return;
}
// exiting dialog should block all input until button is released to prevent menu from closing the following frame
if (gameScreen.getDialog() != null) {
gameScreen.setDialog(null);

View File

@ -452,21 +452,18 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
stage.screenToStageCoordinates(tmpVec2.set(Gdx.input.getX(), Gdx.input.getY()));
Actor hit = stage.hit(tmpVec2.x, tmpVec2.y, true);
if (hit == null) {
/*boolean pressed = Gdx.input.isButtonPressed(Input.Buttons.LEFT);
Item cursor = Riiablo.cursor.getItem();
if (cursor != null && Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
if (cursor != null && pressed) {
Riiablo.cursor.setItem(null);
Entity item = new ItemHolder(cursor);
item.position().set(player.position());
entities.put(entities.size + 1, item);
} else {
} else {*/
mapListener.update();
}
//}
}
else if (DEBUG_HIT) Gdx.app.debug(TAG, hit.toString());
//if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
// GridPoint2 coords = mapRenderer.coords();
// player.setPath(map, new Vector3(coords.x, coords.y, 0));
//}
}
/*
@ -717,4 +714,13 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
}
}
}
public void pickup(ItemHolder entity) {
Riiablo.cursor.setItem(entity.item);
int key = entities.findKey(entity, true, -1);
if (key != -1) {
entities.remove(key);
mapListener.requireRelease = true;
}
}
}