public Projectile NewProjectile(ProjectileType pType)
    {
        Projectile newProjectile = null;

        switch(pType)
        {
            case ProjectileType.BlasterBolt:
                newProjectile = Instantiate(blasterBoltPrefab) as Projectile;
                break;
            case ProjectileType.RedBlasterBolt:
                newProjectile = Instantiate(redBlasterBoltPrefab) as Projectile;
                break;
            case ProjectileType.PurpleBlasterBolt:
                newProjectile = Instantiate(purpleBlasterBoltPrefab) as Projectile;
                break;
        }

        if (newProjectile)
        {
            newProjectile.transform.parent = transform;
            newProjectile.gameObject.SetActive(false);
            _projectiles[pType].Add(newProjectile);
        }

        return newProjectile;
    }
示例#2
0
文件: Projectile.cs 项目: Lyise/SARP
        public Projectile(Vector2 Location, Vector2 Direction, float Speed, Texture2D Texture, int Damage, Boolean IsPlayer, Vector2 Target, 
                            ProjectileType ProjectileType = ProjectileType.Cannon, float RateOfTurn = 0f, float FlightTime = 3f, int Health = 10)
        {
            v2Location = Location;
            v2Target = Target;
            Direction.Normalize();
            v2Direction = Direction;
            fSpeed = Speed;
            fRateOfTurn = RateOfTurn;

            ptType = ProjectileType;

            t2dTexture = Texture;
            rectHitBox.Width = Texture.Width;
            rectHitBox.Height = Texture.Height;

            if (ProjectileType == ProjectileType.Cannon)
                fFlightTime = FlightTime * 3f;
            else
                fFlightTime = FlightTime;

            iDamage = Damage;
            iHealth = Health;
            bActive = true;
            bPlayer = IsPlayer;

            CurrentAngle = (float)Math.Atan2((double)v2Direction.Y, (double)v2Direction.X);

            SetHitbox();
        }
    public void FireProjectile(Transform tar, float time, ProjectileType type, bool isHoming)
    {
        transform.localScale = new Vector3 (15, 15, 15);
        GameObject particle;
        particle = Instantiate (Resources.Load ("FireParticle") as GameObject, transform.position, transform.rotation) as GameObject;

        //Saved values i
        GameObject cloneTarget;
        cloneTarget = new GameObject ();
        cloneTarget.transform.position = tar.position;
        if (!isHoming)
            tar = cloneTarget.transform;
        orgin = transform.position;
        targetPositionAtFire = transform.position;
        target = tar;
        transitTime = time + 1;
        Destroy (particle, time);
        distanceCovered = 0;
        transform.LookAt(tar);
        //Calulate control point based on information given
        controlPoint = Vector3.Lerp(orgin, target.position, 0.5f);
        controlPoint += Vector3.up * (Vector3.Distance(orgin, tar.position) / 2);
        //Start the Event
        StartCoroutine (StartEvent (type));
        deathTimer = transitTime;
    }
示例#4
0
        public bool CheckHit(Vector2 pos, Vector2 speed, ProjectileType type, bool grenade)
        {
            //if (!Active) return false;
            if (HP <= 0) return false;

            bool isHit = false;

            if ((pos - CenterPosition).Length() <= (type!= ProjectileType.Grenade?(15 * scale):(20*scale)))
            {

                isHit = true;

                HP -= (!grenade?0.2f:0.1f);
                GameManager.ParticleController.AddMetalDebris(pos, speed*0.2f);
                if(!grenade)
                    AudioController.PlaySFX("metalhit" + (randomNumber.Next(4) +1), 0.5f, 0f, 0.3f, Position);
                if(randomNumber.Next(20)==1)
                    AudioController.PlaySFX("ricochet", 0.4f, 0f, 0.3f, Position);

                if (HP <= 0) Die();

            }

            return isHit;
        }
示例#5
0
 void getStatsForType(ProjectileType type_)
 {
     switch (type_)
     {
         case ProjectileType.NORMAL_BULLET:
             damage = 2;
             speed = 200;
             break;
         case ProjectileType.NORMAL_BULLET_UPGRADE:
             damage = 3;
             speed = 200;
             break;
         case ProjectileType.DOUBLE_BULLET:
             damage = 3;
             speed = 200;
             break;
         case ProjectileType.NORMAL_MISSLE:
             damage = 4;
             speed = 150;
             break;
         case ProjectileType.DOUBLE_MISSLE:
             damage = 5;
             speed = 150;
             break;
     }
 }
示例#6
0
 public void RefreshWeaponBox(ProjectileType type, int count, bool startReload = false, float duration = 0)
 {
     weaponBoxes[type].UpdateCount(count);
     if (startReload) {
         weaponBoxes[type].StartReload(duration);
     }
 }
示例#7
0
 public Projectile(long id, double mass, double x, double y, double speedX, double speedY, double angle,
         double angularSpeed, double radius, long carId, long playerId, ProjectileType type)
         : base(id, mass, x, y, speedX, speedY, angle, angularSpeed, radius) {
     this.carId = carId;
     this.playerId = playerId;
     this.type = type;
 }
示例#8
0
 public static void Add(NetworkMessage message, Location fromLocation, Location toLocation, ProjectileType projectile)
 {
     message.AddByte((byte)ServerPacketType.Projectile);
     message.AddLocation(fromLocation);
     message.AddLocation(toLocation);
     message.AddByte((byte)projectile);
 }
示例#9
0
 public static bool Send(Objects.Client client, Objects.Location fromLocation, Objects.Location toLocation, ProjectileType effect)
 {
     ProjectilePacket p = new ProjectilePacket(client);
     p.FromPosition = fromLocation;
     p.ToPosition = toLocation;
     p.Effect = effect;
     return p.Send();
 }
示例#10
0
 public AProjectile(Projectile proj)
 {
     Type = proj.Type;
     X = proj.X;
     Y = proj.Y;
     Speed = new Point(proj.SpeedX, proj.SpeedY);
     Radius = proj.Radius;
 }
示例#11
0
 public static bool Defeats(ProjectileType type1, ProjectileType type2)
 {
     return type2 == ProjectileType.Fragile ||
         type1 == ProjectileType.Fire && type2 == ProjectileType.Ice ||
         type1 == ProjectileType.Ice && type2 == ProjectileType.Water ||
         type1 == ProjectileType.Water && type2 == ProjectileType.Fire ||
         type1 == ProjectileType.Fire && type2 == ProjectileType.Tree;
 }
示例#12
0
 public override void CreateProjectile(ProjectileType type, Vector2 startPosition, Vector2 startVelocity)
 {
     switch (type)
     {
         case ProjectileType.Bullet:
             projectiles.Add(new Bullet(this.content, startPosition, startVelocity));
             return;
         default: return;
     }
 }
示例#13
0
 /// <summary>
 ///  Constructs a projectile with the given y velocity
 /// </summary>
 /// <param name="type">the projectile type</param>
 /// <param name="sprite">the sprite for the projectile</param>
 /// <param name="x">the x location of the center of the projectile</param>
 /// <param name="y">the y location of the center of the projectile</param>
 /// <param name="yVelocity">the y velocity for the projectile</param>
 public Projectile(ProjectileType type, Texture2D sprite, int x, int y, 
     float yVelocity)
 {
     this.type = type;
     this.sprite = sprite;
     this.yVelocity = yVelocity;
     drawRectangle = new Rectangle(x - sprite.Width / 2,
         y - sprite.Height / 2, sprite.Width,
         sprite.Height);
 }
        public Projectile(Texture2D texture, Vector2 position, int width, Color color, float rotation, 
            float scale, float drawLayer, int frames, ProjectileType type, Vector2 direction, float speed, ProjectileOwner owner)
            : base(texture, position, width, color, rotation, scale, drawLayer, frames)
        {
            this.Type = type;
            this.Owner = owner;
            this.Direction = direction;
            this.Speed = speed;

            this.IsActive = true;
        }
示例#15
0
 public Projectile(ProjectileType type_, Texture2D texture, Vector2 pos, Vector2 direct, float ang)
 {
     type = type_;
     sprite = texture;
     position = pos;
     getStatsForType(type);
     direct.Normalize();
     velocity = direct * speed * -1;
     angle = ang;
     base.Initialize();
 }
示例#16
0
 public void Add(Vector2 loc, Vector2 speed, double life, bool ownerhero, ProjectileType type)
 {
     foreach (Projectile p in Projectiles)
     {
         if (!p.Active)
         {
             p.Spawn(loc, speed, life, ownerhero, type);
             break;
         }
     }
 }
示例#17
0
        public Projectile(TextureHandler t, HumptyDumpty humptyDumpty)
        {
            setDestination(humptyDumpty.Position);
            hitbox = new Rectangle((int)position.X, (int)position.Y, 10, 10);
            trajectory = new Rectangle((int)position.X, (int)position.Y, 2, 100);
            this.humptyDumpty = humptyDumpty;

            Random r = new Random();
            projectileType = (ProjectileType)r.Next(7);
            texture = t.getProjectile(projectileType);
        }
示例#18
0
        public void Spawn(Vector2 pos, Vector2 speed, double life, bool heroowner, ProjectileType type)
        {
            Active = true;
            Position = pos;
            Speed = speed;
            Life = life;
            OwnedByHero = heroowner;
            Type = type;

            alpha = 1f;
            rot = Helper.V2ToAngle(Speed);
        }
示例#19
0
 public Projectile(GameWorld pGameWorld, uint pTeam, ProjectileType pType, float pXPos, float pYPos, float pRotation, ProjectileKit pProjKit, Ship pTarget = null, Ship pOwner = null)
 {
     mXPos = pXPos;
     mYPos = pYPos;
     mType = pType;
     aaGameWorld = pGameWorld;
     mTeam = pTeam;
     SetProjType();
     mRotation = pRotation;
     mProjKit = pProjKit;
     mTarget = pTarget;
     mOwner = pOwner;
     mDispObject = new DisplayObject(aaGameWorld.aaDisplay, mAssetKit.ASSET_NAME, mXPos, mYPos, (int)mAssetKit.ORIGIN.X, (int)mAssetKit.ORIGIN.Y, Constants.LAYER_PROJECTILE_DEPTH, mAssetKit.SRC_RECTX, mAssetKit.SRC_RECTY, mAssetKit.SRC_RECTWIDTH, mAssetKit.SRC_RECTHEIGHT, mRotation, false);
 }
示例#20
0
 void Start()
 {
     player = GameObject.FindGameObjectWithTag("Player").GetComponent<Controller2D>();
     sprite = GetComponent<SpriteRenderer>();
     animationController = GetComponent<Animator>();
     projectileCollider = GetComponent<Collider2D>();
     initalXOffset = projectileCollider.offset.x;
     initalYOffset = projectileCollider.offset.y;
     hit = false;
     decaying = false;
     projectileType = (GameControl.gameControl.playerClass == 3) ? ProjectileType.Arrow : ProjectileType.MagicMissle;
     weaponType = (GameControl.gameControl.playerClass == 3) ? "Bow" : "Staff";
     projectileNumber = EquipmentDatabase.equipmentDatabase.equipment[GameControl.gameControl.profile1Weapon].equipmentTier;
     UpdateDirection();
 }
示例#21
0
 public void Spawn(float d, ProjectileType t, Vector2 v, Controller.Owner o, float m, bool hacked)
 {
     StopAllCoroutines();
     if (hacked)
         StartCoroutine(enableCollisions());
     despawnTimer = 0;
     rigid = GetComponent<Rigidbody2D>();
     damage = d;
     projectileType = t;
     setDamage();
     owner = o;
     rigid.velocity = v;
     setLayer();
     procChance = m;
 }
示例#22
0
 public Projectile(Projectile p)
 {
     position = new Vertex(p.position);
     type = p.type;
     lifeTime = p.lifeTime;
     exploded = p.exploded;
     playerProjectile = p.playerProjectile;
     if(p.srcMonster != null)
         srcMonsterId = p.srcMonster.id;
     missileTarget = p.missileTarget;
     stopped = p.stopped;
     exploding = p.exploding;
     explodeTime = p.explodeTime;
     laserDepth = p.laserDepth;
 }
示例#23
0
        public void Spawn(Vector2 pos, float landingheight, Vector2 speed, double life, bool heroowner, ProjectileType type, float pow, Color tint)
        {
            Active = true;
            Position = pos;
            Speed = speed;
            Life = life;
            OwnedByHero = heroowner;
            Type = type;
            Power = pow;
            Tint = tint;
            landingHeight = landingheight;

            alpha = 1f;
            rot = Helper.V2ToAngle(Speed);
        }
示例#24
0
        public override bool ParseMessage(NetworkMessage msg, PacketDestination destination)
        {
            int position = msg.Position;

            if (msg.GetByte() != (byte)IncomingPacketType.Projectile)
                return false;

            Destination = destination;
            Type = IncomingPacketType.Projectile;

            FromPosition = msg.GetLocation();
            ToPosition = msg.GetLocation();
            Effect = (ProjectileType)msg.GetByte();

            return true;
        }
示例#25
0
    public void Init(Vector2 goalPos, ProjectileType type, float speed)
    {
        this.goalPos = goalPos;
        this.type = type;

        GetComponent<SpriteRenderer>().sprite = SpriteLibrary.I.GetProjectileSprite(type);

        //Set velocity
        Vector2 dir = (goalPos - (Vector2)transform.position).normalized;
        Vector2 vel = dir * speed;
        rb.AddForce(vel, ForceMode2D.Impulse);

        //Set rotation

        transform.rotation = Tools.DirectionToQuaternion(dir);
    }
        public ProjectileController(IGameObject owner, Vector2 position, Vector2 velocity, ProjectileType type, int damage, String texturePath)
        {
            Rectangle bounds = new Rectangle((int)position.X - 1, (int)position.Y - 1, 3, 3);
            m_collider = new Collider(this, bounds, ColliderType.Projectile);

            Owner = owner;
            Velocity = velocity;
            Damage = damage;
            Tint = Color.White;
            Freezes = false;

            m_position = position;
            m_type = type;

            m_texture = new GameTexture(texturePath);
        }
示例#27
0
        /// <summary>
        /// Creates a new projectile for the level based on its type.  It's position is updated and then added to the list of projectiles in the game.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public void CreateProjectile(ProjectileType type, Vector2 spawnPosition, Game game, ProjectileAlignment alignment)
        {
            Projectile newProjectile = null;
            switch (type)
            {
                case ProjectileType.BasicLaser:
                    newProjectile = new BasicLaser(game, alignment);
                    break;
                case ProjectileType.ChargedLaser:
                    newProjectile = new ChargedLaser(game, alignment);
                    break;
            }
            newProjectile.Position = spawnPosition;

            ProjectileList.Add(newProjectile);
        }
示例#28
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public Projectile()
        {
            EnablePhysics(PhysicsFlags.Flying);

            syncAnimationWithAngle		= false;
            syncAnimationWithDirection	= false;

            owner			= null;
            eventCollision	= null;
            eventLand		= null;
            angle			= 0;
            direction		= 0;

            crashAnimation	= null;
            bounceOnCrash	= false;

            projectileType = ProjectileType.Physical;
        }
示例#29
0
 public static Projectile Create(ProjectileType type)
 {
     var result = new Projectile();
     switch (type)
     {
         case ProjectileType.Torpedo:
             break;
         case ProjectileType.Skattershot:
             break;
         case ProjectileType.Hardshell:
             break;
         case ProjectileType.Nuke:
             break;
         case ProjectileType.Knockshot:
             break;
     }
     return result;
 }
示例#30
0
    IEnumerator StartEvent(ProjectileType type)
    {
        //While traveling towards the target
        while (Vector3.Distance(transform.position, target.position) >= .25f)
        {
            //If its a missle type
            if (type == ProjectileType.Missle)
            {
                distanceCovered += Time.deltaTime;
                float fracJour = distanceCovered / transitTime;
                transform.position = Vector3.Lerp(orgin, target.position, fracJour);
                yield return null;
            }
            //If its a bomb type
            else if (type == ProjectileType.Bomb)
            {
                distanceCovered += Time.deltaTime;
                float fracJour = distanceCovered / transitTime;
                transform.position = BezierVec3(orgin, controlPoint, target.position, fracJour);
                yield return null;
            }
            //Or if its not yet programmed, destory the object
            else
            {
                print("Projectile type has not algorithm.");
                Destroy(this.gameObject);
            }

            deathTimer -= Time.deltaTime;
            if (deathTimer <= 0)
            {
                print("Projectile has lived too long.");
                Destroy(this.gameObject);
            }

            if(Vector3.Dot(transform.forward, target.position - transform.position) < 0)
            {
                print("Projectile passed its target");
                Destroy(this.gameObject);
            }
        }
        ResolveProjectile();
    }