User Tools

Site Tools


dragengine:modules:dragonscript:abstractions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dragengine:modules:dragonscript:abstractions [2020/05/05 20:16] dragonlorddragengine:modules:dragonscript:abstractions [2024/03/14 16:43] (current) dragonlord
Line 1: Line 1:
-{{tag>dragonscript project behavior}}+{{tag>dragonscript project behavior gettingstarted}}
 <WRAP youarehere> <WRAP youarehere>
 [[:start|Start Page]] >> [[dragengine:modules:dragonscript:main|DragonScript Scripting Language]] >> **Abstraction Layers: How you want to build your Game** [[:start|Start Page]] >> [[dragengine:modules:dragonscript:main|DragonScript Scripting Language]] >> **Abstraction Layers: How you want to build your Game**
Line 5: Line 5:
  
  
-====== Overview ======+====== How you want to build your Game ======
  
 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 15: 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://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElementClass.html|BehaviorElementClass]] script class. This class extends the [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ElementClass.html|ElementClass]] script class with support to add **Behavior Definitions**. When a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance is created these **behavior definitions** are used to befit the element with all the required functionality. All this can be done manually by using **Scenery Elements** but using **Behavior Elements** this boils down to just adding the **behavior definitions** you like to use.+Behavior elements are created by subclassing from #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElementClass.html,BehaviorElementClass~@# script class. This class extends the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ElementClass.html,ElementClass~@# script class with support to add **Behavior Definitions**. When a #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElement.html,BehaviorElement~@# instance is created these **behavior definitions** are used to befit the element with all the required functionality. All this can be done manually by using **Scenery Elements** but using **Behavior Elements** this boils down to just adding the **behavior definitions** you like to use.
  
-Behavior definitions are created by subclassing from [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/interfaceDragengine_1_1Scenery_1_1ECBehavior.html|ECBehavior]] script class. This stands for **Element Class Behavior**. Behavior definitions typically contain **Composeable Element Class** or **Element Class Property** instances with appropriate parameters set. This has a few nice properties making life simpler.+Behavior definitions are created by subclassing from #@LinkApiDocDEDS2_HTML~interfaceDragengine_1_1Scenery_1_1ECBehavior.html,ECBehavior~@# script class. This stands for **Element Class Behavior**. Behavior definitions typically contain **Composeable Element Class** or **Element Class Property** instances with appropriate parameters set. This has a few nice properties making life simpler.
  
 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 23: 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://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElementClass.html|BehaviorElementClass]] if it contains behaviors of a specific type. Some behavior definitions can be used more than once on the same element class. In this case you can assign each instance a unique **identifier**. This identifier is used to distinguish between the behavior definition instances and acts also as prefix modified of the added element class properties.+You can query #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElementClass.html,BehaviorElementClass~@# if it contains behaviors of a specific type. Some behavior definitions can be used more than once on the same element class. In this case you can assign each instance a unique **identifier**. This identifier is used to distinguish between the behavior definition instances and acts also as prefix modified of the added element class properties.
  
-Once a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance is created each behavior definitions adds a subclass of [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/interfaceDragengine_1_1Scenery_1_1ECBehaviorInstance.html|ECBehaviorInstance]]. These provide the actual behavior to the [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1BehaviorElement.html|BehaviorElement]] instance. Here too you can query the element if it contains instances of a specific behavior.+Once a #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElement.html,BehaviorElement~@# instance is created each behavior definitions adds a subclass of #@LinkApiDocDEDS2_HTML~interfaceDragengine_1_1Scenery_1_1ECBehaviorInstance.html,ECBehaviorInstance~@#. These provide the actual behavior to the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElement.html,BehaviorElement~@# instance. Here too you can query the element if it contains instances of a specific behavior.
  
 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.
  
- +  * [[behaviors_use_cases|Behaviors ExplainedBy Use-Case]] 
-The **DragonScript Scripting Module** provides these **Basic Behaviors** as starting help: +  * [[behaviors_a_to_z|Behaviors ExplainedFrom A to Z]]
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]Adds a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Component.html|Component]] to the providing the **Visual Appearance** of an element. This behavior can be used multiple times. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorCollider.html|ECBehaviorCollider]]: Adds a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Collider.html|Collider]] to the element providing the **Physical Interaction** of an element. This contains collision detection of various kinds. This behavior can be used only once. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorLight.html|ECBehaviorLight]]: Attaches a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Light.html|Light]] to the element. This behavior can be used multiple times. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorSpeaker.html|ECBehaviorSpeaker]]: Attaches a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Speaker.html|Speaker]] to the element. This behavior can be used multiple times. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTriggered.html|ECBehaviorTriggered]]: Adds support to be triggered by a **Trigger Expression**. This behavior can be used multiple times. +
- +
-The **DragonScript Scripting Module** provides these **Complex Behaviors** as starting help: +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorAnimated.html|ECBehaviorAnimated]]: Adds support to animate a single [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]. This behavior can be used multiple times each instance animating a different [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorComponent.html|ECBehaviorComponent]]. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTwoStateAnimated.html|ECBehaviorTwoStateAnimated]]: Similar to [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorAnimated.html|ECBehaviorAnimated]] but supports switching between the animation states. typical example would be a door which can be in an open or closed state.This behavior can be used multiple times. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorMoveOnRail.html|ECBehaviorMoveOnRail]]: Adds support to move an [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorCollider.html|ECBehaviorCollider]] along a path laid out by the mapper using **Rail Corners**. This behavior can be used only once. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorConversation.html|ECBehaviorConversation]]: Adds support to play back a **Conversation** if triggered by [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorTriggered.html|ECBehaviorTriggered]] or manually started. This behavior can be used only once. +
-  * [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ECBehaviorHearSounds.html|ECBehaviorHearSounds]]: Adds a [[https://developer.dragondreams.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1SoundLevelMeter.html|SoundLevelMeter]] to listen what sounds are playing around the element. +
  
 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, is animated, has two lights, has a speaker and moves along a rail. Basically this describes a kind of train running on a rail between two destinations. This is an example of an element class which which has a visual appearance, physical interaction, is animated, has two lights, has a speaker and moves along a rail. Basically this describes a kind of train running on a rail between two destinations.
Line 93: Line 79:
                  
         // 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.
-        // if you assign also the trigger system from the BaseGameApp then the mapper+        // 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         // 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         // on your own (or by other behaviors only) leave out this argument
-        moveOnRail = ECBehaviorMoveOnRail.new(this, collider, BaseGameApp.getApp().getTriggerSystem())+        moveOnRail = ECBehaviorMoveOnRail.new(this, collider, BaseGameApp.getApp().getTriggerTable())
    end    end
 end end
 </code> </code>
  
-If you want to also add run-time behavior on top of the behavior without creating your own behavior you can modify the code like this:+The above script code creates a working element class which adds instances of BehaviorElement to the game world set up with the defined behaviors. If you want to have a unique element instance for your class to work with you can modify the code like this:
 <code> <code>
 class MyTrainClass extends BehaviorElementClass class MyTrainClass extends BehaviorElementClass
Line 116: Line 102:
 end end
 </code> </code>
-====== 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: Create all from Scratch mostly for Framework Creators ====== ====== Bare-Bone Implementation: Create all from Scratch mostly for Framework Creators ======
  
 +TODO
dragengine/modules/dragonscript/abstractions.1588709790.txt.gz · Last modified: 2020/05/05 20:16 by dragonlord