Created
August 21, 2022 11:22
-
-
Save rutvik110/3b11fcd85b825c97b997d69d7317faa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar extends BodyComponent with ContactCallbacks, KeyboardHandler { | |
late BodyDef bodyDef; | |
late Vector2 barPosition; | |
@override | |
Body createBody() { | |
barPosition = Vector2(10, 20); | |
final bar = PolygonShape()..setAsBoxXY(2, 5); | |
final fixtureDef = FixtureDef( | |
bar, | |
// restitution: 0, | |
// density: 1.0, | |
// friction: 0.4, | |
); | |
bodyDef = BodyDef( | |
userData: this, | |
//angularDamping: 0.8, | |
position: barPosition, //Vector2(10, 20), | |
// gravityScale: Vector2(0, 0), | |
//type: BodyType.dynamic, | |
); | |
add( | |
KeyboardListenerComponent( | |
keyDown: { | |
LogicalKeyboardKey.arrowUp: (keysPressed) { | |
barPosition += Vector2(0, -1.0); | |
return true; | |
}, | |
LogicalKeyboardKey.arrowDown: (keysPressed) { | |
barPosition += Vector2(0, 1.0); | |
return true; | |
}, | |
LogicalKeyboardKey.keyW: (keysPressed) { | |
return true; | |
}, | |
LogicalKeyboardKey.keyS: (keysPressed) { | |
return true; | |
}, | |
}, | |
), | |
); | |
final fixture = world.createBody(bodyDef)..createFixture(fixtureDef); | |
return fixture; | |
} | |
@override | |
void update(double dt) { | |
// TODO: implement update | |
super.update(dt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment