Vorschlag zur Verbesserung des coding styles... :)
parent
db934d2d38
commit
cfd74c9dde
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
switch (actorState){
|
||||
case BallisticActorStates.FLYING:
|
||||
Velocity += (Physics.Gravitation * timespan);
|
||||
Position += Velocity * timespan;
|
||||
Scale = Matrix4.CreateScale(3.0f);
|
||||
|
||||
setHeading( Velocity, Physics.Gravitation);
|
||||
|
||||
Console.WriteLine("BallisticActor update: {0} / {1}",Position,Velocity);
|
||||
|
||||
updateSoundState();
|
||||
Console.WriteLine("Playing:" + isPlaying);
|
||||
|
||||
try{
|
||||
try
|
||||
{
|
||||
Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
|
||||
|
||||
if (Position.Z <= ground.Z){
|
||||
if(hit != 1) {
|
||||
Console.WriteLine("BallisticActor hit ground!");
|
||||
actorState = BallisticActorStates.HIT;
|
||||
playSound("HowHit");
|
||||
updateSoundState();
|
||||
hit = 1;
|
||||
}
|
||||
} catch (OutOfWorldException owe){
|
||||
Console.WriteLine("BallisticActor disappeared at {0} [{1}]",Position,Velocity);
|
||||
actorState = BallisticActorStates.DISAPPEARED;
|
||||
}
|
||||
break;
|
||||
|
||||
if(!isPlaying){
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
} catch (OutOfWorldException e){
|
||||
if (!isPlaying){
|
||||
case BallisticActorStates.HIT:
|
||||
case BallisticActorStates.DISAPPEARED:
|
||||
Model3D = null;
|
||||
|
||||
if (!soundPlaying()){
|
||||
destroy();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
namespace org.niclasundharald.engine
|
||||
{
|
||||
public enum BallisticActorStates
|
||||
{
|
||||
FLYING,
|
||||
HIT,
|
||||
DISAPPEARED
|
||||
}
|
||||
}
|
|
@ -75,6 +75,7 @@
|
|||
<Compile Include="ArrayHelper.cs" />
|
||||
<Compile Include="Geometry.cs" />
|
||||
<Compile Include="Linear.cs" />
|
||||
<Compile Include="BallisticActorStates.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
|
|
Loading…
Reference in New Issue