Skip to content

Instantly share code, notes, and snippets.

@codeinvain
Created July 22, 2010 08:01
Show Gist options
  • Save codeinvain/485710 to your computer and use it in GitHub Desktop.
Save codeinvain/485710 to your computer and use it in GitHub Desktop.
private function onBodiesContact(e:b2ContactEvent):void
{
var b1:UIComponent = e.contact.GetFixtureA().GetBody().GetUserData();
var b2:UIComponent = e.contact.GetFixtureB().GetBody().GetUserData();
if (b1==p1 || b2 ==p1)
{
hitSound.play();
}
else if (b1==p2 || b2== p2)
{
hitSound.play();
}
else if (b1==p1Goal || b2==p1Goal)
{
wallSound.play();
goalAnimation.play([p1Goal]);
}
else if (b1==p2Goal || b2==p2Goal)
{
wallSound.play();
goalAnimation.play([p2Goal]);
}
}
protected function p2_mouseDownHandler(event:MouseEvent):void
{
p2StartDelta = event.stageY -p2.y;
moveP2=true;
}
protected function p2_mouseUpHandler(event:MouseEvent):void
{
moveP2=false;
}
protected function world_mouseMoveHandler(event:MouseEvent):void
{
if (moveP2==false)
return;
var p2b:b2Body = worldUIContainer.getComponentBody(p2);
var nextPos:Number = event.stageY-p2StartDelta;
if (nextPos < 10)
{
nextPos=10;
}else if (nextPos+p2.height>worldUIContainer.height-10){
nextPos = worldUIContainer.height-10-p2.height;
}
p2b.SetPosition(new b2Vec2(p2b.GetPosition().x,worldUIContainer.worldDef.meter(nextPos)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment