-
Notifications
You must be signed in to change notification settings - Fork 8
Things
jbaicoianu edited this page Apr 7, 2013
·
16 revisions
The basic game entity in the Elation Engine is the Thing. Everything in your game world is a Thing, and all Things inherit from elation.engine.things.generic which handles much of the underlying object initialization, event management, etc. The core engine includes some basic Thing types, and your game can augment these with any additional Thing types specific to your game.
elation.component.add("engine.things.turret", function() {
this.init = function() {
this.defineProperties({
'firedelay': { type: 'integer', default: 2000 },
'pitch': { type: 'angle', default: 0 },
'yaw': { type: 'angle', default: 0 },
'pitchspeed': { type: 'angle', default: Math.PI / 4 },
'yawspeed': { type: 'angle', default: Math.PI / 4 },
'maxpitchdegrees': { type: 'angle', default: 90 },
'minpitchdegrees': { type: 'angle', default: -44 },
'muzzleoffset': { type: 'vector3', default: [0,0,0] },
'muzzlespeed': { type: 'float', default: 150.0 }
});
this.defineActions({
'pitch': this.pitch,
'yaw': this.yaw,
'fire': this.fire
});
this.defineEvents({
// ...
});
}
this.pitch = function(value) {
this.angularvelocity.x = value * this.properties.turret.pitchspeed;
}
this.yaw = function(value) {
this.angularvelocity.y = value * this.properties.turret.yawspeed;
}
this.fire = function(value) {
if (value) {
var bulletargs = {
position: this.position.clone().add(this.properties.turret.muzzleoffset),
velocity: this.localToWorld(new THREE.Vector3(0,0,-this.properties.muzzlespeed))
};
// spawn new bullet, passing false for third argument makes it child of world instead of owner
var bullet = this.spawnThing('turret_bullet', bulletargs, false);
this.playSound('fire');
}
}
});