package com.arretadogames.pilot.items; import org.jbox2d.collision.AABB; import org.jbox2d.common.Vec2; import org.jbox2d.dynamics.Fixture; import android.graphics.Color; import com.arretadogames.pilot.R; import com.arretadogames.pilot.entities.Coconut; import com.arretadogames.pilot.entities.Player; import com.arretadogames.pilot.world.GameWorld; public class CoconutItem implements Item { private ItemType type = ItemType.Coconut; private Player owner; @Override public int getImageDrawable() { return R.drawable.coconut; } @Override public String getName() { return type.getName(); } @Override public void activate(Player owner, GameWorld world) { if (!isActive() && !owner.isOnWater()) { this.owner = owner; this.owner.setItem(null); Fixture f = owner.body.getFixtureList(); AABB aabb = new AABB(); AABB auxAABB = new AABB(); while (f != null) { f.getShape().computeAABB(auxAABB, owner.body.getTransform(), 0); aabb.combine(auxAABB); f = f.getNext(); } Coconut coconut = new Coconut(aabb.upperBound.x + Coconut.COCONUT_SIZE, aabb.upperBound.y + Coconut.COCONUT_SIZE); world.getEntities().add(coconut); Vec2 impulse = new Vec2(0.9f, 0.15f); impulse.mulLocal(14); coconut.body.applyLinearImpulse(impulse, coconut.body.getWorldCenter(), true); } } @Override public void step(float timeElapsed) { if (isActive()) { } } @Override public ItemType getType() { return type; } @Override public int getColor() { return Color.WHITE; } @Override public boolean isActive() { return false; } }