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-26 15:12:22 +02:00
|
|
|
|
using org.budnhead.tools;
|
2017-05-04 23:57:00 +02:00
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
|
2017-05-06 01:20:13 +02:00
|
|
|
|
|
|
|
|
|
|
2017-05-09 23:41:50 +02:00
|
|
|
|
namespace org.budnhead.core
|
2017-05-04 23:57:00 +02:00
|
|
|
|
{
|
|
|
|
|
public class BallisticActor : Actor
|
|
|
|
|
{
|
2017-05-08 16:52:40 +02:00
|
|
|
|
BallisticActorStates actorState;
|
|
|
|
|
|
2017-05-04 23:57:00 +02:00
|
|
|
|
public BallisticActor(int id)
|
|
|
|
|
:base(id)
|
|
|
|
|
{
|
2017-05-08 16:52:40 +02:00
|
|
|
|
this.actorState = BallisticActorStates.FLYING;
|
2017-05-26 15:12:22 +02:00
|
|
|
|
this.Model3D = ResourceLibrary.getResource<LoadedModel>("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();
|
2017-05-08 14:59:41 +02:00
|
|
|
|
|
2017-05-06 18:12:21 +02:00
|
|
|
|
setBuffers("HowFire", "HowHit");
|
|
|
|
|
setDistanceAttenuation(2, 200, 800);
|
2017-05-04 23:57:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void update(float timespan)
|
|
|
|
|
{
|
|
|
|
|
base.update(timespan);
|
|
|
|
|
|
2017-05-08 16:52:40 +02:00
|
|
|
|
switch (actorState){
|
|
|
|
|
case BallisticActorStates.FLYING:
|
2017-05-26 15:12:22 +02:00
|
|
|
|
Velocity.Value += (Physics.Gravitation * timespan);
|
|
|
|
|
Position.Value += Velocity.Value * timespan;
|
2017-05-08 16:52:40 +02:00
|
|
|
|
|
2017-05-26 15:12:22 +02:00
|
|
|
|
setHeading( Velocity.Value, Physics.Gravitation);
|
2017-05-08 16:52:40 +02:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-26 15:12:22 +02:00
|
|
|
|
Vector3 ground = SquaredMap.activeMap.ground(Position.Value.Xy);
|
2017-05-08 16:52:40 +02:00
|
|
|
|
|
2017-05-26 15:12:22 +02:00
|
|
|
|
if (Position.Value.Z <= ground.Z){
|
2017-05-08 16:52:40 +02:00
|
|
|
|
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()){
|
2017-05-06 01:20:13 +02:00
|
|
|
|
destroy();
|
|
|
|
|
}
|
2017-05-08 16:52:40 +02:00
|
|
|
|
break;
|
2017-05-04 23:57:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-06 01:20:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-04 23:57:00 +02:00
|
|
|
|
|
2017-05-06 01:20:13 +02:00
|
|
|
|
|
|
|
|
|
public void fire()
|
|
|
|
|
{
|
2017-05-26 15:12:22 +02:00
|
|
|
|
//playSound("HowFire");
|
2017-05-04 23:57:00 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-06 01:20:13 +02:00
|
|
|
|
|
2017-05-04 23:57:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|