budnhead/org.niclasundharald.engine/BallisticActor.cs

75 lines
1.2 KiB
C#
Raw Normal View History

2017-05-04 23:57:00 +02:00
using System;
using org.niclasundharald.engine.graphics.primitives;
using org.niclasundharald.engine.graphics;
using OpenTK;
2017-05-04 23:57:00 +02:00
namespace org.niclasundharald.engine
{
public class BallisticActor : Actor
{
public BallisticActor(int id)
:base(id)
{
this.Model3D = ModelManager.instance.findModel("ballistisch");
setBuffers("HowFire", "HowHit", "st1");
2017-05-04 23:57:00 +02:00
}
int hit = 0;
2017-05-04 23:57:00 +02:00
public override void update(float timespan)
{
base.update(timespan);
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);
2017-05-04 23:57:00 +02:00
try{
Vector3 ground = SquaredMap.activeMap.ground(Position.Xy);
if (Position.Z <= ground.Z){
if(hit != 1)
{
playSound("HowHit");
updateSoundState();
hit = 1;
}
if(!isPlaying)
{
destroy();
}
2017-05-04 23:57:00 +02:00
}
} catch (OutOfWorldException e){
if(!isPlaying)
2017-05-04 23:57:00 +02:00
destroy();
}
}
2017-05-04 23:57:00 +02:00
public void fire()
{
playSound("HowFire");
setDistanceAttenuation(2, 0, 50);
2017-05-04 23:57:00 +02:00
}
2017-05-04 23:57:00 +02:00
}
}