forked from LeenkxTeam/Leenkx_Examples
update
This commit is contained in:
55
game_bowling/Sources/lnx/BallTrait.hx
Normal file
55
game_bowling/Sources/lnx/BallTrait.hx
Normal file
@ -0,0 +1,55 @@
|
||||
package lnx;
|
||||
|
||||
import iron.math.Vec4;
|
||||
import leenkx.trait.physics.RigidBody;
|
||||
|
||||
class BallTrait extends iron.Trait {
|
||||
|
||||
@prop
|
||||
var impulse = 65.0;
|
||||
|
||||
var fired = false;
|
||||
var rb:RigidBody;
|
||||
var start = new Vec4();
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnInit(function() {
|
||||
rb = object.getTrait(RigidBody);
|
||||
start.setFrom(object.transform.loc);
|
||||
});
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
|
||||
var kb = iron.system.Input.getKeyboard();
|
||||
var tr = object.transform;
|
||||
|
||||
if (!fired) {
|
||||
if (kb.started("x") || kb.started("space")) {
|
||||
rb.applyImpulse(new Vec4(0, impulse, 0));
|
||||
fired = true;
|
||||
}
|
||||
else if (kb.down("left") && tr.loc.x > -0.9) {
|
||||
tr.loc.x -= 0.02;
|
||||
tr.buildMatrix();
|
||||
rb.syncTransform();
|
||||
}
|
||||
else if (kb.down("right") && tr.loc.x < 0.9) {
|
||||
tr.loc.x += 0.02;
|
||||
tr.buildMatrix();
|
||||
rb.syncTransform();
|
||||
}
|
||||
}
|
||||
|
||||
if (fired && tr.loc.z < -10) {
|
||||
tr.loc.setFrom(start);
|
||||
tr.buildMatrix();
|
||||
rb.setLinearVelocity(0, 0, 0);
|
||||
rb.setAngularVelocity(0, 0, 0);
|
||||
rb.syncTransform();
|
||||
fired = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
24
game_bowling/Sources/lnx/PinTrait.hx
Normal file
24
game_bowling/Sources/lnx/PinTrait.hx
Normal file
@ -0,0 +1,24 @@
|
||||
package lnx;
|
||||
|
||||
class PinTrait extends iron.Trait {
|
||||
|
||||
public static var pinsRemoved = 0;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
pinsRemoved = 0;
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
|
||||
if (object.transform.loc.z < - 20) {
|
||||
object.remove();
|
||||
|
||||
if (++pinsRemoved >= 10) {
|
||||
leenkx.system.Event.send("exit");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user