using System; using System.Collections.Generic; using System.Linq; using System.Text; using Duality; using Duality.Editor; using Duality.Resources; using Duality.Components; using Duality.Components.Physics; using Duality.Components.Renderers; namespace DualStickSpaceShooter { public class BulletBlueprint : Resource { private float lifetime = 8000.0f; private float impactMass = 1.5f; private float launchSpeed = 10.0f; private float damage = 5.0f; private ContentRef spriteMaterial = null; private ContentRef hitEffect = null; private ContentRef hitWorldEffect = null; private ContentRef hitSound = null; public float Lifetime { get { return this.lifetime; } set { this.lifetime = value; } } public float ImpactMass { get { return this.impactMass; } set { this.impactMass = value; } } public float LaunchSpeed { get { return this.launchSpeed; } set { this.launchSpeed = value; } } public float Damage { get { return this.damage; } set { this.damage = value; } } public ContentRef SpriteMaterial { get { return this.spriteMaterial; } set { this.spriteMaterial = value; } } public ContentRef HitEffect { get { return this.hitEffect; } set { this.hitEffect = value; } } public ContentRef HitWorldEffect { get { return this.hitWorldEffect; } set { this.hitWorldEffect = value; } } public ContentRef HitSound { get { return this.hitSound; } set { this.hitSound = value; } } public Bullet CreateBullet() { GameObject obj = new GameObject("Bullet"); Transform transform = obj.AddComponent(); RigidBody body = obj.AddComponent(); SpriteRenderer sprite = obj.AddComponent(); Bullet bullet = obj.AddComponent(); Material spriteMaterial = this.spriteMaterial.Res ?? Material.SolidWhite.Res; Vector2 spriteSize = spriteMaterial.MainTexture.IsAvailable ? spriteMaterial.MainTexture.Res.Size : new Vector2(5, 5); float spriteRadius = MathF.Max(spriteSize.X, spriteSize.Y) * 0.25f; body.ClearShapes(); CircleShapeInfo circleShape = new CircleShapeInfo(spriteRadius, Vector2.Zero, 1.0f); circleShape.IsSensor = true; body.AddShape(circleShape); body.CollisionCategory = CollisionCategory.Cat3; body.CollidesWith &= ~CollisionCategory.Cat3; sprite.SharedMaterial = this.spriteMaterial; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, spriteSize.X * 0.5f, spriteSize.Y * 0.5f); bullet.InitFrom(this); return bullet; } } }