This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dragengine:modules:dragonscript:abstractions [2019/04/25 19:39] – [Behavior Elements: Quick and Easy Development] dragonlord | dragengine:modules:dragonscript:abstractions [2024/03/14 16:43] (current) – dragonlord | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{tag> | ||
<WRAP youarehere> | <WRAP youarehere> | ||
[[: | [[: | ||
Line 4: | Line 5: | ||
- | ====== | + | ====== |
The **DragonScript Scripting Module** provides 3 main ways to build your game depending on your skill level and project requirements. The layers are listed from the most simple one (which is recommended for most projects) to the most flexible one. | The **DragonScript Scripting Module** provides 3 main ways to build your game depending on your skill level and project requirements. The layers are listed from the most simple one (which is recommended for most projects) to the most flexible one. | ||
Line 14: | Line 15: | ||
**Behavior Elements** are build on top of the **Scenery Elements** and provide a **composeable** way to build game logic. This is the fastest way to build your game by befitting elements with reusable **behavior** while still retaining all the powerful coupling to other script classes. | **Behavior Elements** are build on top of the **Scenery Elements** and provide a **composeable** way to build game logic. This is the fastest way to build your game by befitting elements with reusable **behavior** while still retaining all the powerful coupling to other script classes. | ||
- | Behavior elements are created by subclassing from [[https:// | + | Behavior elements are created by subclassing from # |
- | Behavior definitions are created by subclassing from [[https:// | + | Behavior definitions are created by subclassing from # |
Element class properties can be used with **XML Subclassing**. You can created a new element class just using an XML file (*.deeclass) and change the properties added by the behavior definition. This is especially useful for mappers to add variations of **Game Objects** without needing to touch script code for such a simple task. | Element class properties can be used with **XML Subclassing**. You can created a new element class just using an XML file (*.deeclass) and change the properties added by the behavior definition. This is especially useful for mappers to add variations of **Game Objects** without needing to touch script code for such a simple task. | ||
Line 22: | Line 23: | ||
Furthermore **Element Stubs** used to create **Game Objects** in your game world use the same names as the element class properties. This allows mappers to modify behaviors on a per **Game Object** basis if required. | Furthermore **Element Stubs** used to create **Game Objects** in your game world use the same names as the element class properties. This allows mappers to modify behaviors on a per **Game Object** basis if required. | ||
- | You can query [[https:// | + | You can query # |
- | Once a [[https:// | + | Once a # |
Behaviors are split in two groups: **Basic Behaviors** and **Complex Behaviors**. **Basic Behaviors** add a small basic building block of game logic like for example a component showing the visual appearance of a game object. These are highly reusable. **Complex Behaviors** on the other hand typically expect one or more **Basic Behaviors** to be present in the element class to provide a complex behavior for example animating the visual appearance. | Behaviors are split in two groups: **Basic Behaviors** and **Complex Behaviors**. **Basic Behaviors** add a small basic building block of game logic like for example a component showing the visual appearance of a game object. These are highly reusable. **Complex Behaviors** on the other hand typically expect one or more **Basic Behaviors** to be present in the element class to provide a complex behavior for example animating the visual appearance. | ||
- | + | | |
- | The **DragonScript Scripting Module** provides these **Basic Behaviors** as starting help: | + | * [[behaviors_a_to_z|Behaviors |
- | | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
- | + | ||
- | The **DragonScript Scripting Module** provides these **Complex | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
- | * [[https:// | + | |
Many more complex behaviors can be created either just for this game project or to be shared with other projects. Behaviors can extend other behaviors by subclassing or by using other behaviors present in the behavior element class. | Many more complex behaviors can be created either just for this game project or to be shared with other projects. Behaviors can extend other behaviors by subclassing or by using other behaviors present in the behavior element class. | ||
- | |||
This is an example of an element class which which has a visual appearance, physical interaction, | This is an example of an element class which which has a visual appearance, physical interaction, | ||
Line 65: | Line 52: | ||
public func new() super(" | public func new() super(" | ||
// create visual appearance with default model(mesh), | // create visual appearance with default model(mesh), | ||
- | // physical interaction and animation purpose | + | // physical interaction and animation purpose. this method assigns the resources located |
- | component = ECBehaviorComponent.new(this) | + | |
- | | + | component.setCommonPath("/ |
- | component.getComponent().getSkin().setPath("/ | + | |
- | component.getComponent().getRig().setPath("/ | + | |
| | ||
- | // create collider which is used for physical interaction | + | // create collider which is used for physical interaction. in most situations you want to |
- | collider = ECBehaviorCollider.new(this) | + | // animate the component with the rig. this requires to component behavior to go first |
+ | collider = ECBehaviorCollider.new(this, component) | ||
| | ||
- | // create head lights. attached to collider | + | // create head lights. attached to collider |
- | headLightLeft = ECBehaviorLight.new(this) | + | headLightLeft = ECBehaviorLight.new(this, collider, " |
- | headLightLeft.getLight().getColor().setColor(Color.YELLOW) | + | headLightLeft.getLight().getColor().setColor(Color.yellow) |
- | headLightLeft.getAttach().getPosition().setVector(Vector.new(-1.0, 0.5, 2.0)) | + | headLightLeft.getAttach().getPosition().setVector(Vector.new(-1, |
| | ||
- | headLightRight = ECBehaviorLight.new(this) | + | headLightRight = ECBehaviorLight.new(this, collider, " |
- | headLightRight.getLight().getColor().setColor(Color.YELLOW) | + | headLightRight.getLight().getColor().setColor(Color.yellow) |
- | headLightRight.getAttach().getPosition().setVector(Vector.new(1.0, 0.5, 2.0)) | + | headLightRight.getAttach().getPosition().setVector(Vector.new(1, |
| | ||
- | // create engine speaker. attached to the collider | + | // create engine speaker. attached to the collider |
- | speaker = ECBehaviorSpeaker.new(this) | + | speaker = ECBehaviorSpeaker.new(this, collider) |
speaker.getSpeaker().getSound().setPath("/ | speaker.getSpeaker().getSound().setPath("/ | ||
speaker.getAttach().getPosition().setVector(Vector.new(0.0, | speaker.getAttach().getPosition().setVector(Vector.new(0.0, | ||
| | ||
- | // create behavior animating the visual appearance using an animator | + | // create behavior animating the visual appearance |
- | animated = ECBehaviorAnimated.new(this) | + | animated = ECBehaviorAnimated.new(this, component) |
animated.getAnimator().getAnimator().setPath("/ | animated.getAnimator().getAnimator().setPath("/ | ||
| | ||
- | // create behavior moving collider on rail. the mapper defines what rail to use | + | // create behavior moving collider on rail. the mapper defines what rail to use. |
- | moveOnRail = ECBehaviorMoveOnRail.new(this) | + | // if you assign also the trigger table from the BaseGameApp then the mapper |
+ | // can use triggers to start/stop moving the train. if you want to control this | ||
+ | // on your own (or by other behaviors only) leave out this argument | ||
+ | moveOnRail = ECBehaviorMoveOnRail.new(this, collider, BaseGameApp.getApp().getTriggerTable()) | ||
end | end | ||
end | end | ||
</ | </ | ||
- | If you want to also add run-time behavior on top of the behavior without creating | + | The above script code creates a working element class which adds instances of BehaviorElement to the game world set up with the defined behaviors. |
< | < | ||
class MyTrainClass extends BehaviorElementClass | class MyTrainClass extends BehaviorElementClass | ||
Line 113: | Line 102: | ||
end | end | ||
</ | </ | ||
- | ====== Scenery Elements: Customized and Optimized for Special Needs ====== | ||
+ | Using unique instances allows to add run-time features to your class on top of what BehaviorElement provides without creating an own behavior. In general it is recommended to work with behaviors only and creating your own ones. This way you can reuse game logic across different projects easily. | ||
+ | ====== Scenery Elements: Customized and Optimized for Special Needs ====== | ||
+ | TODO | ||
====== Bare-Bone Implementation: | ====== Bare-Bone Implementation: | ||
+ | TODO |