aboutsummaryrefslogtreecommitdiff
path: root/src/doc/feature/script.dox
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-20 20:31:11 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-20 20:31:11 +0100
commit3a5a61399cea453c5fc25e3b999ef9a751fd4448 (patch)
tree5fd9d88d7e71696ffd7b52e956b44c3ade92dd81 /src/doc/feature/script.dox
parent5ec30d8915debef409f6db6f8ee9b822fb24d46b (diff)
parentb6aea9de9c9c8d86856bcd6c3b521e385bc00a69 (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/events
Diffstat (limited to 'src/doc/feature/script.dox')
-rw-r--r--src/doc/feature/script.dox62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/doc/feature/script.dox b/src/doc/feature/script.dox
new file mode 100644
index 0000000..d25a63b
--- /dev/null
+++ b/src/doc/feature/script.dox
@@ -0,0 +1,62 @@
+// vim:ft=doxygen
+namespace crepe {
+/**
+
+\defgroup feature_script Scripting
+\ingroup feature
+\brief User-defined scripts for game objects
+
+Scripts can be used to implement game behavior, and allow arbitrary code to run
+as part of the game loop. Scripts are implemented as derivative classes of
+Script, which are added to game objects using the BehaviorScript \ref Component
+"component".
+
+\todo This section is incomplete:
+- Utility functions to get components/events/etc inside script
+- How to listen for events
+- Extensions of script (keylistener)
+
+\see Script
+\see BehaviorScript
+\see GameObject
+
+\par Example
+
+First, define a class that inherits from Script. This class acts as an
+interface, and has two functions (\ref Script::init "\c init()" and \ref
+Script::update "\c update()"), which may be implemented (they are empty by
+default). From now on, this derivative class will be referred to as a *concrete
+script*.
+
+```cpp
+#include <crepe/api/Script.h>
+#include <crepe/api/BehaviorScript.h>
+
+class MyScript : public crepe::Script {
+ void init() {
+ // called once
+ }
+ void update() {
+ // called on fixed update
+ }
+};
+```
+
+Concrete scripts can be instantiated and attached to \ref GameObject
+"game objects" using the BehaviorScript \ref Component "component".
+
+```cpp
+using namespace crepe;
+GameObject obj = component_manager.new_object("name");
+
+// create BehaviorScript instance
+BehaviorScript & behavior_script = obj.add_component<BehaviorScript>();
+// attach (and instantiate) MyScript to behavior_script
+behavior_script.set_script<MyScript>();
+
+// the above can also be done in a single call for convenience:
+obj.add_component<BehaviorScript>().set_script<MyScript>();
+```
+
+*/
+}