diff --git a/org.niclasundharald.engine/Actor.cs b/org.niclasundharald.engine/Actor.cs
index c045b6a..9ab1949 100644
--- a/org.niclasundharald.engine/Actor.cs
+++ b/org.niclasundharald.engine/Actor.cs
@@ -56,6 +56,9 @@ namespace org.niclasundharald.engine
public float Weight { get; set; }
public virtual void update(float timespan){
+ if (soundPlaying()){
+ syncSoundPosition();
+ }
}
public void setHeading(Vector3 heading,Vector3 top){
@@ -118,16 +121,14 @@ namespace org.niclasundharald.engine
_player.play(aBuffers[sound], gain, loop);
}
- public void setPlayerPosition(Vector3 positon, Vector3 velocity)
+ private void syncSoundPosition()
{
- _player.setPosition(positon);
- _player.setVelocity(velocity);
+ _player.setPosition(this.Position);
+ _player.setVelocity(this.Velocity);
}
- public void updateSoundState()
- {
- isPlaying = _player.state();
-
+ public Boolean soundPlaying(){
+ return _player.state();
}
}
diff --git a/org.niclasundharald.engine/BallisticActor.cs b/org.niclasundharald.engine/BallisticActor.cs
index d1f8946..7f05456 100644
--- a/org.niclasundharald.engine/BallisticActor.cs
+++ b/org.niclasundharald.engine/BallisticActor.cs
@@ -10,9 +10,12 @@ namespace org.niclasundharald.engine
{
public class BallisticActor : Actor
{
+ BallisticActorStates actorState;
+
public BallisticActor(int id)
:base(id)
{
+ this.actorState = BallisticActorStates.FLYING;
this.Model3D = ModelManager.instance.findModel("ballistisch");
for (int n=0;n < this.Model3D.vertexes.Length;n++){
@@ -25,42 +28,40 @@ namespace org.niclasundharald.engine
setDistanceAttenuation(2, 200, 800);
}
- byte hit = 0;
-
-
public override void update(float timespan)
{
base.update(timespan);
- Velocity += (Physics.Gravitation * timespan);
- Position += Velocity * timespan;
- Scale = Matrix4.CreateScale(3.0f);
+ switch (actorState){
+ case BallisticActorStates.FLYING:
+ Velocity += (Physics.Gravitation * timespan);
+ Position += Velocity * timespan;
+
+ setHeading( Velocity, Physics.Gravitation);
+
+ try
+ {
+ Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
- setHeading( Velocity, Physics.Gravitation);
+ if (Position.Z <= ground.Z){
+ Console.WriteLine("BallisticActor hit ground!");
+ actorState = BallisticActorStates.HIT;
+ playSound("HowHit");
+ }
+ } catch (OutOfWorldException owe){
+ Console.WriteLine("BallisticActor disappeared at {0} [{1}]",Position,Velocity);
+ actorState = BallisticActorStates.DISAPPEARED;
+ }
+ break;
- Console.WriteLine("BallisticActor update: {0} / {1}",Position,Velocity);
+ case BallisticActorStates.HIT:
+ case BallisticActorStates.DISAPPEARED:
+ Model3D = null;
- updateSoundState();
- Console.WriteLine("Playing:" + isPlaying);
-
- try{
- Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
-
- if (Position.Z <= ground.Z){
- if(hit != 1) {
- playSound("HowHit");
- updateSoundState();
- hit = 1;
- }
-
- if(!isPlaying){
+ if (!soundPlaying()){
destroy();
}
- }
- } catch (OutOfWorldException e){
- if (!isPlaying){
- destroy();
- }
+ break;
}
}
diff --git a/org.niclasundharald.engine/BallisticActorStates.cs b/org.niclasundharald.engine/BallisticActorStates.cs
new file mode 100644
index 0000000..1ea56fc
--- /dev/null
+++ b/org.niclasundharald.engine/BallisticActorStates.cs
@@ -0,0 +1,10 @@
+using System;
+namespace org.niclasundharald.engine
+{
+ public enum BallisticActorStates
+ {
+ FLYING,
+ HIT,
+ DISAPPEARED
+ }
+}
diff --git a/org.niclasundharald.engine/org.niclasundharald.engine.csproj b/org.niclasundharald.engine/org.niclasundharald.engine.csproj
index 6cadc95..384aab6 100644
--- a/org.niclasundharald.engine/org.niclasundharald.engine.csproj
+++ b/org.niclasundharald.engine/org.niclasundharald.engine.csproj
@@ -75,6 +75,7 @@
+