public void throwOnGround(Point2F destination, Mob thrower) { dropped = true; landingLoc = destination; startLoc = thrower.getLocation(); physicsComponent.setLocation(startLoc.x, startLoc.y); thrower.getLevel().addNewFloorItem(this); angle = startLoc.angle(landingLoc); x = y = z = 0; maxDistance = startLoc.distance(landingLoc); }
public void throwItemAtTarget(Mob thrower, Entity target) { thrown = true; landingLoc = target.getLocation(); startLoc = thrower.getLocation(); physicsComponent.setLocation(startLoc.x, startLoc.y); thrower.getLevel().addNewThrownItem(this); angle = startLoc.angle(landingLoc); x = y = z = 0; maxDistance = startLoc.distance(landingLoc); }
public void render(SpriteBatch g) { if (onGround || thrown || dropped) { Point2F p = Globals.toIsoCoord(getX(), getY()); if (dropped || thrown) { p.y += z; } g.setColor(drawColor); groundSprite.render(g, p.x, p.y); g.setColor(Color.WHITE); } else { System.out.println( "WARNING " + name + " is out of state! A inventory item is being drawn like a floor item."); } }
@Override public void tick(float deltaTime) { if (dropped || thrown) { float dx = 0; float dy = 0; if (dropped) { dx = (float) (Math.cos(angle) * 6F); dy = (float) (Math.sin(angle) * 6F); } if (thrown) { dx = (float) (Math.cos(angle) * 28F); dy = (float) (Math.sin(angle) * 28F); } float curDistance = startLoc.distance(getX(), getY()); x = getX() + dx; y = getY() + dy; if (dropped) z = getArcHeight(curDistance, maxDistance, 150); if (thrown) z = getArcHeight(curDistance, maxDistance, 40) + 160; // 160 so it starts at chest height of thrower physicsComponent.setLocation(x, y); if (curDistance >= maxDistance) { if (dropped) { onGround = true; physicsComponent.setLocation(landingLoc.x, landingLoc.y); } dropped = false; thrown = false; } } super.tick(deltaTime); }