budnhead/org.budnhead/core/BallisticActor.cs

81 lines
1.7 KiB
C#
Raw Normal View History

2017-05-04 23:57:00 +02:00
using System;
2017-05-09 23:41:50 +02:00
using org.budnhead.graphics.primitives;
using org.budnhead.graphics;
using org.budnhead.exceptions;
2017-05-04 23:57:00 +02:00
using OpenTK;
2017-05-09 23:41:50 +02:00
namespace org.budnhead.core
2017-05-04 23:57:00 +02:00
{
public class BallisticActor : Actor
{
BallisticActorStates actorState;
2017-05-04 23:57:00 +02:00
public BallisticActor(int id)
:base(id)
{
this.actorState = BallisticActorStates.FLYING;
2017-05-04 23:57:00 +02:00
this.Model3D = ModelManager.instance.findModel("ballistisch");
2017-05-06 12:37:36 +02:00
for (int n=0;n < this.Model3D.vertexes.Length;n++){
this.Model3D.colors[n] = new Vector4(1.0f,0.2f + (0.5f * this.Model3D.vertexes[n].Z / -4.0f),0,1.0f);
}
this.Model3D.rebind();
setBuffers("HowFire", "HowHit");
setDistanceAttenuation(2, 200, 800);
2017-05-04 23:57:00 +02:00
}
public override void update(float timespan)
{
base.update(timespan);
switch (actorState){
case BallisticActorStates.FLYING:
Velocity += (Physics.Gravitation * timespan);
Position += Velocity * timespan;
setHeading( Velocity, Physics.Gravitation);
try
{
Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
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;
case BallisticActorStates.HIT:
case BallisticActorStates.DISAPPEARED:
Model3D = null;
if (!soundPlaying()){
destroy();
}
break;
2017-05-04 23:57:00 +02:00
}
}
2017-05-04 23:57:00 +02:00
public void fire()
{
playSound("HowFire");
2017-05-04 23:57:00 +02:00
}
2017-05-04 23:57:00 +02:00
}
}