Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/levels/events.oxw @ 6977

Last change on this file since 6977 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 9.4 KB
RevLine 
[6417]1<?lua
2  include("hudtemplates3.oxo")
3  include("stats.oxo")
4  include("templates/spaceship_assff.oxt")
5  include("templates/spaceship_H2.oxt")
6?>
7
8<Level
9 name         = "Event testing"
10 description  = "A simple level to test the event-system (with comments)"
11>
12  <Scene
13   ambientlight = "0.5, 0.5, 0.5"
14   skybox       = "Orxonox/skypanoramagen1"
15  >
16    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
17
18    <SpawnPoint position="0,-100,0" lookat="0,0,0" roll=180 spawnclass=SpaceShip pawndesign=spaceshipassff />
19
20    <Billboard position=" 300,100,  0" material="Examples/Flare" colour="1.0, 0.0, 0.0" />
21    <Billboard position=" 200,100,  0" material="Examples/Flare" colour="1.0, 0.5, 0.0" />
22    <Billboard position=" 200,100,100" material="Examples/Flare" colour="1.0, 0.5, 0.0" />
23    <Billboard position=" 100,100,  0" material="Examples/Flare" colour="1.0, 1.0, 0.0" />
24    <Billboard position="   0,100,  0" material="Examples/Flare" colour="0.0, 1.0, 0.0" />
25    <Billboard position="-100,100,  0" material="Examples/Flare" colour="0.0, 1.0, 1.0" />
26    <Billboard position="-100,100,100" material="Examples/Flare" colour="0.0, 1.0, 1.0" />
27    <Billboard position="-200,100,  0" material="Examples/Flare" colour="0.0, 0.0, 1.0" />
28    <Billboard position="-300,100,  0" material="Examples/Flare" colour="1.0, 0.0, 1.0" />
29
30
31
32    <!--
33      Begin of the tutorial section.
34    -->
35
36
37
38    <!--
39      Note:
40      All following examples use only one subobject (in nested layouts). But of course you can add more
41      objects. They will all follow the same rules (depending on the example receive, send or pipe events).
42
43      Some examples address objects by name. Those methods always address ALL objects with this name, no
44      matter where they are in the XML-file (before or after the addressing object). Of course this also
45      works with all amounts of objects from zero to infinity. In the examples I used two objects each.
46    -->
47
48
49    <!-- red -->
50    <!--
51      Standard:
52      Direct event-connection between an event-listener (Billboard) and an event source (DistanceTrigger).
53      Every fired event of the source is mapped to the "visibility" state of the listener.
54
55      This is a 1:1 mapping between event-listener and event-source.
56    -->
57    <Billboard position="300,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0>
58      <events>
59        <visibility>
60          <DistanceTrigger position="300,100,0" distance=25 target="ControllableEntity" />
61        </visibility>
62      </events>
63    </Billboard>
64
65
66    <!-- orange -->
67    <!--
68      EventListener:
69      The EventListener object forwards all events from objects, whose names equal the "event" attribute
70      of the EventListener, to the enclosing object (Billboard).
71      In this case, both triggers have the name "trigger2" and thus both triggers send events to the Billboard.
72
73      The EventListener provides an 1:n mapping between one listener and multiple event-sources.
74    -->
75    <Billboard position="200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0>
76      <events>
77        <visibility>
78          <EventListener event="trigger2" />
79        </visibility>
80      </events>
81    </Billboard>
82    <DistanceTrigger name="trigger2" position="200,100,0" distance=25 target="ControllableEntity" />
83    <DistanceTrigger name="trigger2" position="200,100,100" distance=25 target="ControllableEntity" />
84
85
86    <!-- yellow -->
87    <!--
88      EventTarget:
89      The EventTarget object forwards the events, received from objects whithin the "events" subsection,
90      to all  objects whose names equal the "name" attribute.
91      In this case, the EventTarget forwards the event from the DistanceTrigger to all listeners with
92      name "bb3".
93
94      The EventTarget provides an n:1 mapping between several listeners and one event-source.
95    -->
96    <Billboard name="bb3" position="100,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
97    <Billboard name="bb3" position="100,150,100" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
98    <EventTarget target="bb3">
99      <events>
100        <visibility>
101          <DistanceTrigger position="100,100,0" distance=25 target="ControllableEntity" />
102        </visibility>
103      </events>
104    </EventTarget>
105
106
107    <!-- green -->
108    <!--
109      EventDispatcher:
110      The EventDispatcher catches events from objects in its "events" subsection. Those events are forwared
111      to all objects in the "targets" subsection. The EventDispatcher resembles the EventTarget, but
112      doesn't address objects with the "name" attribute. It rather places them directly inside the "targets"
113      subsection.
114      In this case, the EventDispatcher receives events from the DistanceTrigger and forwards those events
115      to the Billboard object.
116
117      The EventDispatcher provides an n:1 mapping between several targets (listeners) and one event source.
118    -->
119    <EventDispatcher>
120      <targets>
121        <Billboard position="0,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
122      </targets>
123      <events>
124        <visibility>
125          <DistanceTrigger position="0,100,0" distance=25 target="ControllableEntity" />
126        </visibility>
127      </events>
128    </EventDispatcher>
129
130
131    <!-- turquoise -->
132    <!--
133      Combination:
134      By combinding the above three classes, namely EventDispatcher, EventTarget and EventListener, you can
135      extract the event logic completely from the actual objects (Billboards and DistanceTriggers).
136      In this case, both triggers (whith names "trigger5") send events to both Billboards (with names "bb5").
137
138      This combination allows an n:n mapping between event-listeners and event-sources.
139    -->
140    <Billboard name="bb5" position="-100,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
141    <Billboard name="bb5" position="-100,150,100" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
142    <DistanceTrigger name="trigger5" position="-100,100,0" distance=25 target="ControllableEntity" />
143    <DistanceTrigger name="trigger5" position="-100,100,100" distance=25 target="ControllableEntity" />
144    <EventDispatcher>
145      <targets>
146        <EventTarget target="bb5" />
147      </targets>
148      <events>
149        <visibility>
150          <EventListener event="trigger5" />
151        </visibility>
152      </events>
153    </EventDispatcher>
154
155
156    <!-- blue -->
157    <!--
158      Mainstate:
159      Apart from the standard states (like activity and visibility), each object can have a mainstate.
160      You can define the mainstate with an xml-attribute: mainstate="state". "state" must be one of the
161      supported states of the object (except states which need the originator as a second argument). If
162      the mainstate is set (by default that's not the case), you can send events to the "mainstate" state.
163      This allows you to hide the actually affected state in the event-listener, while the event-source
164      just sends events.
165      Note that this example is exactly like the standard case, but the event is sent to the main-state,
166      which in turn is set to "visibility".
167    -->
168    <Billboard position="-200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility">
169      <events>
170        <mainstate>
171          <DistanceTrigger position="-200,100,0" distance=25 target="ControllableEntity" />
172        </mainstate>
173      </events>
174    </Billboard>
175
176
177    <!-- violet -->
178    <!--
179      Event forwarding:
180      As a consequence of the mainstate, events can also be sent without any explicit declaration of
181      the targets state. This allows us to forward events from an event-source directly to a bunch of
182      event-listeners. The events are automatically piped into the mainstate. Therefore the listeners
183      have to declare their main-state.
184      In this example, the DistanceTrigger forwards the events to the Billboards main-state (visibility).
185      This does the same like the example above, but instead of piping events backwards from the source
186      into the mainstate of the listener, we're forwarding the event implicitly to the mainstate.
187    -->
188    <DistanceTrigger position="-300,100,0" distance=25 target="ControllableEntity">
189      <eventlisteners>
190        <Billboard position="-300,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility" />
191      </eventlisteners>
192    </DistanceTrigger>
193
194
195
196    <!--
197      End of the tutorial section.
198    -->
199
200
201
202    <!--
203      The following example shows again the red (standard layout) and the violet (event forwarding) example,
204      but this time with a memoryless state (spawn) from the ParticleSpawner instead of the boolean state
205      (visibility) in the other examples.
206    -->
207    <Billboard position=" 300,100,300" material="Examples/Flare" colour="1.0, 0.0, 0.0" />
208    <Billboard position="-300,100,300" material="Examples/Flare" colour="1.0, 0.0, 1.0" />
209    <ParticleSpawner position="300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0>
210      <events>
211        <spawn>
212          <DistanceTrigger position="300,100,300" distance=25 target="ControllableEntity" />
213        </spawn>
214      </events>
215    </ParticleSpawner>
216    <DistanceTrigger position="-300,100,300" distance=25 target="ControllableEntity">
217      <eventlisteners>
218        <ParticleSpawner position="-300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0 mainstate="spawn" />
219      </eventlisteners>
220    </DistanceTrigger>
221
222  </Scene>
223</Level>
Note: See TracBrowser for help on using the repository browser.