import java.util.HashMap; import org.jbox2d.common.Vec2; import org.jbox2d.dynamics.Body; import pulpfizz.physics.Actor; import pulpfizz.physics.BodyUtils; import pulpfizz.physics.CollisionUtils; import pulpfizz.physics.contact.ContactData; import pulpfizz.physics.contact.ContactEventListener; import pulpfizz.pulp.body.ImageBodySprite; import pulpfizz.pulp.body.PhysicsLayer; public class PostIt extends Actor implements ContactEventListener { Body body; Blokk.BodyShapes shape; PhysicsLayer physics; ImageBodySprite imgSprite; private static HashMap shapeToImg = new HashMap(); static { shapeToImg.put(Blokk.BodyShapes.FULL_RECT,"post-rect.png"); shapeToImg.put(Blokk.BodyShapes.FULL_CRESCENT_FILL,"post-halfcirc.png"); shapeToImg.put(Blokk.BodyShapes.HALF_RECT,"post-square.png"); shapeToImg.put(Blokk.BodyShapes.FULL_TRIANGLE_R,"post-triangle.png"); shapeToImg.put(Blokk.BodyShapes.FULL_TRIANGLE_L,"post-tri-side.png"); } public PostIt(PhysicsLayer physics, Blokk.BodyShapes shape, float x, float y) { this(physics,GameScene.IMG_LOC+shapeToImg.get(shape),x,y); this.shape = shape; } public PostIt(PhysicsLayer physics, String imgAsset, float x, float y) { this.physics = physics; Vec2 camPoint = new Vec2(x,y); Vec2 physPoint = physics.canvasToPhysics(camPoint); body = BodyUtils.createBox(physics.getWorld(), physPoint.x,physPoint.y,2,2); CollisionUtils.setSensor(true, body); addBody(body); setName("Post-it "+imgAsset); physics.getWorld().getContactEventDispatcher().registerActorGroupListener(getID(), Blokk.BLOKK_GROUP, this); imgSprite = new ImageBodySprite(body,physics,imgAsset); physics.add(imgSprite); physics.moveToBottom(imgSprite); } boolean satisfied = false; public void trigger(ContactData c) { Body b = c.shape2.getBody(); Actor a = (Actor) b.getUserData(); if (a instanceof Blokk) { Blokk blokk = (Blokk) a; if (blokk.bodyShape == shape) { if (c.state == ContactData.ADD || c.state == ContactData.PERSIST) { satisfied = true; } else { satisfied = false; } } } } public boolean isCovered() { return satisfied; } }