public void OnFire(Vector3 muzzlePosition, Vector3 muzzleDir) { if (coolDownTimeRemaining <= 0) { //fpsModel.SetAnimationLayer("Pistol_Idle", 0.0f); fpsModel.GetAnimationLayer().AddAnimation("Pistol_Fire", true); //fpsModel.SetAnimationLayer("Pistol_Fire", 1.0f); coolDownTimeRemaining = ResourceManager.Inst.GetAnimation("Pistol_Fire").EndTime; float dist; CollisionSkin skin; Vector3 pos, normal; Segment seg = new Segment(muzzlePosition, muzzleDir * 50); scene.GetPhysicsEngine().CollisionSystem.SegmentIntersect(out dist, out skin, out pos, out normal, seg, ignorePred); if (skin != null) { Decal decal = new Decal(); decal.SetMaterial("BulletMetal1"); decal.Normal = normal; decal.Scale = new Vector2(0.25f, 0.25f); Vector3 posNew = seg.Origin + seg.Delta * dist; decal.Transformation.SetPosition(posNew); decal.IsPersistent = false; scene.AddEntity("bullet", decal); ParticleEffect bulletEffect = ResourceManager.Inst.GetParticleEffect("BulletEffect"); ParticleEmitter collideEmitter = new ParticleEmitter(bulletEffect, 16); collideEmitter.EmitOnce = true; NormalTransform newTransform = new NormalTransform(); newTransform.ConformToNormal(normal); newTransform.SetPosition(pos); collideEmitter.Transformation = newTransform; scene.AddEntity("bulletEmitter", collideEmitter); } } }
public void OnUpdate() { fpsModel.OnUpdate(); if (coolDownTimeRemaining > 0) { coolDownTimeRemaining -= Time.GameTime.ElapsedTime; } if (timeTilFire > 0) timeTilFire -= Time.GameTime.ElapsedTime; if (timeTilFire <= 0 && !hasFired) { hasFired = true; if(!datablock.IsMelee) new Sound3D(datablock.GetSoundEffect((ammo > 0)?WeaponAnimations.Fire:WeaponAnimations.Empty), muzzlePos); if (ammo > 0 || datablock.IsMelee) { ammo--; float dist; CollisionSkin skin; Vector3 pos, normal; Segment seg = new Segment(muzzlePos, muzzleDir * datablock.FireDistance); Microsoft.Xna.Framework.Ray shootRay = new Microsoft.Xna.Framework.Ray(muzzlePos, muzzleDir); bool anyActorHit = false; scene.GetPhysicsEngine().CollisionSystem.SegmentIntersect(out dist, out skin, out pos, out normal, seg, ignorePred); float segDist = (skin != null) ? Vector3.Distance(seg.Delta * dist, Vector3.Zero): float.PositiveInfinity; for (int i = 0; i < scene.Actors.Count; i++) { Actor currActor = scene.Actors[i]; if (currActor != scene.MainPlayer) { float shootDist; HitType hit = currActor.GetHit(shootRay, datablock.FireDistance, out shootDist); if (hit != HitType.None) { if (skin == null || (shootDist <= segDist)) { currActor.ApplyDamage(datablock.Damage); ParticleEffect bloodEffect = ResourceManager.Inst.GetParticleEffect("BloodEffect"); ParticleEmitter collideEmitter = new ParticleEmitter(bloodEffect, 16); collideEmitter.EmitOnce = true; NormalTransform newTransform = new NormalTransform(); newTransform.ConformToNormal(-muzzleDir); newTransform.SetPosition(muzzlePos + muzzleDir*shootDist); collideEmitter.Transformation = newTransform; scene.AddEntity("bloodEmitter", collideEmitter); anyActorHit = true; } } } } if (skin != null) { ParticleEffect bulletEffect = ResourceManager.Inst.GetParticleEffect("BulletEffect"); ParticleEmitter collideEmitter = new ParticleEmitter(bulletEffect, 16); collideEmitter.EmitOnce = true; NormalTransform newTransform = new NormalTransform(); newTransform.ConformToNormal(normal); newTransform.SetPosition(pos); collideEmitter.Transformation = newTransform; scene.AddEntity("bulletEmitter", collideEmitter); } if(datablock.IsMelee) new Sound3D(datablock.GetSoundEffect((anyActorHit) ? WeaponAnimations.SuccessHit : WeaponAnimations.Fire), muzzlePos); } } }
void CreateLandmarks() { plant = new PowerPlant(this); gasStation = new GasStation(this); CreateHangar(); Model shack = new Model("Shack"); (MainTerrain as TerrainVoxel).GetLandmarkTransform(MapLandmark.Docks, shack.Transformation, shack.GetMesh().GetBounds()); AddEntity("Shack", shack); InteractObject key = new InteractObject(null, "Key"); key.SetInteractNode(new PickupNode(key, PickupName.Key, "Key")); key.Transformation.SetPosition(shack.Transformation.GetPosition()); key.Transformation.SetRotation(shack.Transformation.GetRotation()); AddEntity("Key", key); SafeTrigger campTrigger = new SafeTrigger(); campTrigger.Transformation.SetPosition(shack.Transformation.GetPosition()); campTrigger.Transformation.SetScale(Vector3.One * 30); AddEntity("SafeTrigger", campTrigger); Model arena = new Model("Arena"); (MainTerrain as TerrainVoxel).GetLandmarkTransform(MapLandmark.Meadow, arena.Transformation, arena.GetMesh().GetBounds()); AddEntity("Arena", arena); Model windmill = new Model("Windmill"); (MainTerrain as TerrainVoxel).GetLandmarkTransform(MapLandmark.Windmill, windmill.Transformation, windmill.GetMesh().GetBounds()); AddEntity("Windmill", windmill); Model well = new Model("Well"); (MainTerrain as TerrainVoxel).GetLandmarkTransform(MapLandmark.Well, well.Transformation, well.GetMesh().GetBounds()); AddEntity("Well", well); Model tower = new Model("RadioTower"); (MainTerrain as TerrainVoxel).GetLandmarkTransform(MapLandmark.RadioTower, tower.Transformation, tower.GetMesh().GetBounds()); AddEntity("RadioTower", tower); CreateStartZone(); BoundingBox sandBounds = MainTerrain.Transformation.GetBounds(); sandBounds.Max.Y = 0; (MainTerrain as TerrainVoxel).SetUnavailableRegion(sandBounds); for (int i = 0; i < 50; i++) { Vector3 normalWeapon; Vector3 posWeapon; (MainTerrain as TerrainVoxel).GenerateRandomTransform(RandomHelper.RandomGen, out posWeapon, out normalWeapon); InteractObject weaponBox = new InteractObject(new WeaponBoxNode(this), "AmmoBox"); NormalTransform transform = new NormalTransform(); weaponBox.Transformation = transform; transform.ConformToNormal(normalWeapon); transform.SetPosition(posWeapon); AddEntity("WeaponBox", weaponBox); } sandBounds = MainTerrain.Transformation.GetBounds(); sandBounds.Max.Y = 16; (MainTerrain as TerrainVoxel).SetUnavailableRegion(sandBounds); }