Created
March 5, 2009 17:32
-
-
Save tj/74444 to your computer and use it in GitHub Desktop.
This file contains 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
if (!isObject(FollowMouseExBehavior)) | |
{ | |
%template = new BehaviorTemplate(FollowMouseExBehavior); | |
%template.friendlyName = "Follow Mouse Ex"; | |
%template.behaviorType = "Input"; | |
%template.description = "Set the object to follow the position of the mouse. This version can be " @ | |
"restricted by world limits and will obey collisions."; | |
%template.addBehaviorField(flipX, "Flip X axis", bool, true); | |
%template.addBehaviorField(followX, "Follow the mouse's X position", bool, true); | |
%template.addBehaviorField(followY, "Follow the mouse's Y position", bool, true); | |
%template.addBehaviorField(trackingSpeed, "The rate at which the object will move toward the mouse", float, 15.0); | |
} | |
function FollowMouseExBehavior::onBehaviorAdd(%this) | |
{ | |
%this.owner.enableUpdateCallback(); | |
} | |
function FollowMouseExBehavior::onUpdate(%this) | |
{ | |
if (!isObject(sceneWindow2d)) | |
return; | |
%mousePos = sceneWindow2D.getMousePosition(); | |
%position = %this.owner.position; | |
%difference = t2dVectorSub(%mousePos, %position); | |
%amount = t2dVectorScale(%difference, %this.trackingSpeed); | |
if (%this.flipX) | |
%this.owner.setFlipX(%mousePos.x > %position.x ? true : false); | |
if (%this.followX) | |
%this.owner.setLinearVelocityX(%amount.x); | |
if (%this.followY) | |
%this.owner.setLinearVelocityY(%amount.y); | |
} | |
if (!isObject(SwayBehavior)) | |
{ | |
%template = new BehaviorTemplate(SwayBehavior); | |
%template.friendlyName = "Sway"; | |
%template.behaviorType = "Game"; | |
%template.description = "Simulate an object swaying in the wind"; | |
%template.addBehaviorField(left, "Sway to the left", bool, true); | |
%template.addBehaviorField(right, "Sway to the right", bool, true); | |
%template.addBehaviorField(windSpeed, "Wind speed (determines how fast the object will sway)", float, 15.0); | |
%template.addBehaviorField(windStrength, "Wind strength (determines how far the object will sway)", float, 10.0); | |
} | |
function SwayBehavior::onBehaviorAdd(%this) | |
{ | |
%this.owner.enableUpdateCallback(); | |
} | |
function SwayBehavior::onUpdate(%this) | |
{ | |
%rotation = %this.owner.getRotation(); | |
if (!%this.owner.initialRotation) { | |
%this.owner.initialRotation = %rotation; | |
%this.owner.rotationLimit = %rotation + (%this.windStrength - %this.owner.mass); | |
} | |
if (%this.left) { | |
//if (%rotation < %this.owner.initialRotation) | |
// %this.owner.setRotation(%rotation + (%this.windSpeed - %this.owner.mass / 2)); | |
} | |
} | |
if (!isObject(UpdateDepthBehavior)) | |
{ | |
%template = new BehaviorTemplate(UpdateDepthBehavior); | |
%template.friendlyName = "Update Layer Depth On Collision"; | |
%template.behaviorType = "Game"; | |
%template.description = "Switches the colliding object's layer"; | |
%template.addBehaviorField(newLayer, "New layer when colliding", int, "", 0); | |
} | |
function UpdateDepthBehavior::onBehaviorAdd(%this) | |
{ | |
%this.owner.collisionCallback = true; | |
} | |
function UpdateDepthBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) | |
{ | |
if (!%dstObj.originalLayer) | |
%dstObj.originalLayer = %dstObj.getLayer(); | |
%dstObj.setLayer(%this.newLayer); | |
} | |
new AudioDescription(AudioMusicLoop) | |
{ | |
volume = 0.7; | |
isLooping = true; | |
is3D = false; | |
type = $GuiAudioType; | |
}; | |
new AudioProfile(chillMusic) | |
{ | |
filename = "~/data/audio/chill.wav"; | |
description = "AudioMusicLoop"; | |
preload = true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment