Vorschlag zur Verbesserung des coding styles... :)
parent
db934d2d38
commit
cfd74c9dde
|
@ -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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
setHeading( Velocity, Physics.Gravitation);
|
||||||
|
|
||||||
Console.WriteLine("BallisticActor update: {0} / {1}",Position,Velocity);
|
try
|
||||||
|
{
|
||||||
|
Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
|
||||||
|
|
||||||
updateSoundState();
|
if (Position.Z <= ground.Z){
|
||||||
Console.WriteLine("Playing:" + isPlaying);
|
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;
|
||||||
|
|
||||||
try{
|
case BallisticActorStates.HIT:
|
||||||
Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
|
case BallisticActorStates.DISAPPEARED:
|
||||||
|
Model3D = null;
|
||||||
|
|
||||||
if (Position.Z <= ground.Z){
|
if (!soundPlaying()){
|
||||||
if(hit != 1) {
|
|
||||||
playSound("HowHit");
|
|
||||||
updateSoundState();
|
|
||||||
hit = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isPlaying){
|
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
} catch (OutOfWorldException e){
|
|
||||||
if (!isPlaying){
|
|
||||||
destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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="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" />
|
||||||
|
|
Loading…
Reference in New Issue