Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menue/data/levels/events.oxw @ 8916

Last change on this file since 8916 was 8916, checked in by baermatt, 13 years ago

Associated each screenshot to the correct level

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