Vorschlag zur Verbesserung des coding styles... :)

audio-improve-offer
Harald Wolff 2017-05-08 16:52:40 +02:00
parent db934d2d38
commit cfd74c9dde
4 changed files with 47 additions and 34 deletions

View File

@ -56,6 +56,9 @@ namespace org.niclasundharald.engine
public float Weight { get; set; } public float Weight { get; set; }
public virtual void update(float timespan){ public virtual void update(float timespan){
if (soundPlaying()){
syncSoundPosition();
}
} }
public void setHeading(Vector3 heading,Vector3 top){ public void setHeading(Vector3 heading,Vector3 top){
@ -118,16 +121,14 @@ namespace org.niclasundharald.engine
_player.play(aBuffers[sound], gain, loop); _player.play(aBuffers[sound], gain, loop);
} }
public void setPlayerPosition(Vector3 positon, Vector3 velocity) private void syncSoundPosition()
{ {
_player.setPosition(positon); _player.setPosition(this.Position);
_player.setVelocity(velocity); _player.setVelocity(this.Velocity);
} }
public void updateSoundState() public Boolean soundPlaying(){
{ return _player.state();
isPlaying = _player.state();
} }
} }

View File

@ -10,9 +10,12 @@ namespace org.niclasundharald.engine
{ {
public class BallisticActor : Actor public class BallisticActor : Actor
{ {
BallisticActorStates actorState;
public BallisticActor(int id) public BallisticActor(int id)
:base(id) :base(id)
{ {
this.actorState = BallisticActorStates.FLYING;
this.Model3D = ModelManager.instance.findModel("ballistisch"); this.Model3D = ModelManager.instance.findModel("ballistisch");
for (int n=0;n < this.Model3D.vertexes.Length;n++){ for (int n=0;n < this.Model3D.vertexes.Length;n++){
@ -25,42 +28,40 @@ namespace org.niclasundharald.engine
setDistanceAttenuation(2, 200, 800); setDistanceAttenuation(2, 200, 800);
} }
byte hit = 0;
public override void update(float timespan) public override void update(float timespan)
{ {
base.update(timespan); base.update(timespan);
Velocity += (Physics.Gravitation * timespan); switch (actorState){
Position += Velocity * timespan; case BallisticActorStates.FLYING:
Scale = Matrix4.CreateScale(3.0f); 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(); if (!soundPlaying()){
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){
destroy(); destroy();
} }
} break;
} catch (OutOfWorldException e){
if (!isPlaying){
destroy();
}
} }
} }

View File

@ -0,0 +1,10 @@
using System;
namespace org.niclasundharald.engine
{
public enum BallisticActorStates
{
FLYING,
HIT,
DISAPPEARED
}
}

View File

@ -75,6 +75,7 @@
<Compile Include="ArrayHelper.cs" /> <Compile Include="ArrayHelper.cs" />
<Compile Include="Geometry.cs" /> <Compile Include="Geometry.cs" />
<Compile Include="Linear.cs" /> <Compile Include="Linear.cs" />
<Compile Include="BallisticActorStates.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="OpenTK.dll.config" /> <None Include="OpenTK.dll.config" />