public void LaunchThorpede(MissleSide side, Object beh)
    {
        if (side == MissleSide.FRIENDLY)
        {
            friendlyInstance = (FriendlySpaceship)beh;
            misTmp           = getFreeThorpede(side);

            misTmp.gameObject.transform.position    = friendlyInstance.MisslesLaunchPoint.transform.position;
            misTmp.gameObject.transform.eulerAngles = new Vector3(270, friendlyInstance.transform.eulerAngles.y, 0);
            misTmp.Activate();
            misTmp.hideIcon();
            misTmp.gameObject.SetActive(true);
            activeFriendlyThorpedes.Add(misTmp);
        }
        if (side == MissleSide.ENEMY)
        {
            enemyInstance = (EnemySpaceship)beh;
            misTmp        = getFreeThorpede(side);
            misTmp.gameObject.transform.position    = enemyInstance.MissleLaunchPos.transform.position;
            misTmp.gameObject.transform.eulerAngles = new Vector3(270, enemyInstance.transform.eulerAngles.y, 0);
            misTmp.Activate();
            misTmp.gameObject.SetActive(true);
            activeEnemyThorpeds.Add(misTmp);
        }
    }
        public void Update(
            EnemySpaceship enemy,
            PlayerSpaceship player,
            int offsetEnemy  = 0,
            int offsetPlayer = 0,
            float force      = 2)
        {
            if (enemy == null || player == null)
            {
                return;
            }

            var enemyRect  = ImageToRectangle.TransformInRespectToCenter(enemy.CurrentImage, offsetEnemy);
            var playerRect = ImageToRectangle.TransformInRespectToCenter(player.CurrentImage, offsetPlayer);

            AttractionMechanics.Update(
                enemy.CurrentImage,
                player.CurrentImage,
                force);

            if (enemyRect.X > playerRect.X ||
                enemyRect.X + enemyRect.Width < playerRect.X ||
                enemyRect.Y > playerRect.Y ||
                enemyRect.Y + enemyRect.Height < playerRect.Y)
            {
                FacePointMechanics.Update(
                    enemy.CurrentImage,
                    player.CurrentImage);
            }
        }
Example #3
0
    public FriendlySpaceship getNearbyFriendly(EnemySpaceship attacker)
    {
        FriendlySpaceship ret = null;

        d = -1;
        v1.Set(attacker.gameObject.transform.position.x, attacker.gameObject.transform.position.z);
        foreach (FriendlySpaceship target in friendlySpaceships)
        {
            v2.Set(target.gameObject.transform.position.x, target.gameObject.transform.position.z);
            if (d < 0)
            {
                ret = target;
                v2.Set(v1.x - v2.x, v1.y - v2.y);
                d = v2.sqrMagnitude;
            }
            else
            {
                v2.Set(v1.x - v2.x, v1.y - v2.y);
                if (d > v2.sqrMagnitude)
                {
                    ret = target;
                    d   = v2.sqrMagnitude;
                }
            }
        }
        return(ret);
    }
Example #4
0
    void Shoot()
    {
        Vector2      mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
        Vector2      firePointpos  = new Vector2(firePoint.position.x, firePoint.position.y);
        RaycastHit2D hit           = Physics2D.Raycast(firePointpos, mousePosition - firePointpos, 100, allowToHit);

        Debug.DrawLine(firePointpos, (mousePosition - firePointpos) * 100, Color.cyan);
        if (hit.collider != null)
        {
            Debug.DrawLine(firePointpos, hit.point, Color.red);
            EnemySpaceship enemy = hit.collider.GetComponent <EnemySpaceship>();
            if (enemy != null)
            {
                enemy.DamageToEnemy(Damage);
            }
        }
        if (Time.time >= timeToSpawnEffect)
        {
            Vector3 hit_pos;
            if (hit.collider == null)
            {
                hit_pos = (mousePosition - firePointpos) * 30;
            }
            else
            {
                hit_pos = hit.point;
            }


            Effect(hit_pos);
            timeToSpawnEffect = Time.time + 1 / effectSpawnRate;
        }
    }
        public Projectile Update(
            EnemySpaceship enemy,
            PlayerSpaceship player,
            int offsetEnemy  = 0,
            int offsetPlayer = 0)
        {
            if (enemy == null || player == null)
            {
                return(null);
            }
            var distance = 512;
            var distanceBetweenPlayerAndEnemy = Vector2.Distance(player.CurrentImage.Position, enemy.CurrentImage.Position);

            if (distanceBetweenPlayerAndEnemy > distance)
            {
                return(null);
            }
            enemy.CurrentImage.Rotation.Rotation = MathHelper.Lerp(player.CurrentImage.Rotation, enemy.CurrentImage.Rotation, 0.001f);
            return(ProjectileMaker.Create(enemy));
            // var enemyRect = ImageToRectangle.Transform(enemy.CurrentImage, offsetEnemy);
            // var playerRect = ImageToRectangle.Transform(player.CurrentImage, offsetPlayer);
        }
 public void LaunchGas(MissleSide side, Object beh)
 {
     if (side == MissleSide.FRIENDLY)
     {
         friendlyInstance = (FriendlySpaceship)beh;
         misTmp           = getFreeGas(side);
         misTmp.gameObject.transform.position    = friendlyInstance.transform.position;
         misTmp.gameObject.transform.eulerAngles = new Vector3(270, friendlyInstance.transform.eulerAngles.y, 0);
         misTmp.Activate();
         misTmp.gameObject.SetActive(true);
         activeFriendlyGasList.Add(misTmp);
     }
     if (side == MissleSide.ENEMY)
     {
         enemyInstance = (EnemySpaceship)beh;
         misTmp        = getFreeGas(side);
         misTmp.gameObject.transform.position    = enemyInstance.transform.position;
         misTmp.gameObject.transform.eulerAngles = new Vector3(270, enemyInstance.transform.eulerAngles.y, 0);
         misTmp.Activate();
         misTmp.gameObject.SetActive(true);
         activeEnemyGasList.Add(misTmp);
     }
 }
Example #7
0
    public FriendlySpaceship getFriendlyInFireZone(EnemySpaceship friendlyShuttle, Templates.GunOnShuttle gun)
    {
        FriendlySpaceship ret     = null;
        float             dist    = 0;
        float             mindist = -1;

        Templates.GunTemplate gunTemp = Templates.getInstance().getGunTemplate(gun.gunId);
        Vector2 gunPos   = new Vector2(friendlyShuttle.gameObject.transform.position.x + gun.pos.x, friendlyShuttle.gameObject.transform.position.z + gun.pos.y);
        float   gunAngle = Mathf.Repeat(friendlyShuttle.transform.eulerAngles.y + gun.turnAngle, 360);
        Vector2 pos2;

        foreach (FriendlySpaceship enemy in friendlySpaceships)
        {
            if (enemy.isAlive())
            {
                pos2 = new Vector2(enemy.gameObject.transform.position.x, enemy.gameObject.transform.position.z);
                if ((dist = Vector2.Distance(gunPos, pos2)) <= gunTemp.attackRange && Mathf.Abs(getAngleDst(gunAngle, getAngleRelative(friendlyShuttle.gameObject, enemy.gameObject))) <= gunTemp.attackAngle)
                {
                    if (mindist < 0)
                    {
                        ret     = enemy;
                        mindist = dist;
                    }
                    else
                    {
                        if (dist < mindist)
                        {
                            ret     = enemy;
                            mindist = dist;
                        }
                    }
                }
            }
        }
        return(ret);
    }
Example #8
0
 public static void KillEnemy(EnemySpaceship enemy)
 {
     gm._KillEnemy(enemy);
 }
Example #9
0
 public override void HitEffect(EnemySpaceship target)
 {
     projectile    = Resources.Load <GameObject>("Laser");
     target.health = target.health - damage;
 }
Example #10
0
	public FriendlySpaceship getNearbyFriendly(EnemySpaceship attacker)
	{
		FriendlySpaceship ret=null;
		d=-1;
		v1.Set(attacker.gameObject.transform.position.x,attacker.gameObject.transform.position.z);
		foreach(FriendlySpaceship target in friendlySpaceships)
		{
			v2.Set(target.gameObject.transform.position.x,target.gameObject.transform.position.z);
			if(d<0)
			{
				ret=target;
				v2.Set(v1.x-v2.x,v1.y-v2.y);
				d = v2.sqrMagnitude;
			}
			else
			{
				v2.Set(v1.x-v2.x,v1.y-v2.y);
				if(d>v2.sqrMagnitude)
				{
					ret=target;
					d=v2.sqrMagnitude;
				}
			}
		}
		return ret;
	}
Example #11
0
 public abstract void HitEffect(EnemySpaceship target);
Example #12
0
 public override void HitEffect(EnemySpaceship target)
 {
 }
Example #13
0
	public FriendlySpaceship getFriendlyInFireZone(EnemySpaceship friendlyShuttle, Templates.GunOnShuttle gun)
	{
		FriendlySpaceship ret = null;
		float dist=0;
		float mindist=-1;
		Templates.GunTemplate gunTemp = Templates.getInstance().getGunTemplate(gun.gunId);
		Vector2 gunPos = new Vector2(friendlyShuttle.gameObject.transform.position.x+gun.pos.x,friendlyShuttle.gameObject.transform.position.z+gun.pos.y);
		float gunAngle = Mathf.Repeat(friendlyShuttle.transform.eulerAngles.y+gun.turnAngle,360);
		Vector2 pos2;
		foreach(FriendlySpaceship enemy in friendlySpaceships)
		{
			if(enemy.isAlive())
			{
				pos2=new Vector2(enemy.gameObject.transform.position.x,enemy.gameObject.transform.position.z);
				if((dist=Vector2.Distance(gunPos,pos2))<=gunTemp.attackRange && Mathf.Abs(getAngleDst(gunAngle,getAngleRelative(friendlyShuttle.gameObject,enemy.gameObject)))<=gunTemp.attackAngle)
				{
					if(mindist<0)
					{
						ret=enemy;
						mindist=dist;
					}
					else
					{
						if(dist<mindist)
						{
							ret=enemy;
							mindist=dist;
						}
					}
				}
			}
		}
		return ret;
	}
	public void STEP()
	{
		if(!exploded)
		{
			if(!Abilities.getLockGun(activeAbil))
			{
				foreach(Templates.GunOnShuttle gun in planeTemplate.guns)
				{
					gunTemp=Templates.getInstance().getGunTemplate(gun.gunId);
					if(!gun.ready)
						if(gun.shotTime+gunTemp.reuse<Time.time)
							gun.ready=true;
					
					enemy=GameStorage.getInstance().getEnemyInFireZone(this,gun);
					if(gun.ready && enemy!=null)
					{
						//SHOT PROCEDURE WITH POOLING
						f = Quaternion.Euler(0,0,-gameObject.transform.eulerAngles.y)*gun.pos;
						BulletPoolManager.getInstance().shotBullet(BulletSide.FRIENDLY,new Vector3(transform.position.x+f.x,5,transform.position.z+f.y),enemy.transform.position,gunTemp.damage,gunTemp.bulletSpeed,gunTemp.gunType,gunTemp.attackRange,gunTemp.bulletDispersion);
						gun.ready=false;
						gun.shotTime=Time.time;
					}
				}
			}
			
			if(underGas)
			{
				if(Time.time >= lastGasBurned+Abilities.GasParameters.gasReuse)
				{
					Attacked(Abilities.GasParameters.gasDamage);
					lastGasBurned=Time.time;
				}
			}
			
			t+=1f/151f;
			x=(1-t)*(1-t)*(1-t)*point1.x+3*(1-t)*(1-t)*t*point2.x+3*(1-t)*t*t*point3.x+t*t*t*point4.x;
			y=(1-t)*(1-t)*(1-t)*point1.y+3*(1-t)*(1-t)*t*point2.y+3*(1-t)*t*t*point3.y+t*t*t*point4.y;
			tmpVec.x=x;
			tmpVec.y=5;
			tmpVec.z=y;
			curDistance+=Vector3.Distance(forDist,tmpVec);
			if(activeAbil==Abilities.AbilityType.halfRoundTurn)
				f2tmp=transform.eulerAngles.y+abilRandonRotateDirection*180*Time.fixedDeltaTime/3;
			else if(activeAbil==Abilities.AbilityType.turnAround)
				f2tmp=transform.eulerAngles.y+abilRandonRotateDirection*360*Time.fixedDeltaTime/3;
			else
			{
				v2tmp1.x=x-transform.position.x;
				v2tmp1.y=y-transform.position.z;
				v2tmp2 = new Vector2(0,5);
				f1tmp = (v2tmp2.x*v2tmp1.y - v2tmp2.y*v2tmp1.x);
				f2tmp = Vector2.Angle(v2tmp2,v2tmp1);
				if(f1tmp>0)
					f2tmp=(180-f2tmp)+180;
			}
			
			if(activeAbil==Abilities.AbilityType.homingMissle && t>=0.5f && !rocketLaunched)
			{
				MisslePoolManager.getInstance().LaunchRocket(MissleSide.FRIENDLY,this);
				rocketLaunched=true;
			}
			else if(activeAbil==Abilities.AbilityType.homingThorpede && t>=0.5f && !rocketLaunched)
			{
				MisslePoolManager.getInstance().LaunchThorpede(MissleSide.FRIENDLY,this);
				rocketLaunched=true;
			}
			else if(activeAbil==Abilities.AbilityType.gas)
			{
				if(curDistance>=gasLastSpawnDist)
				{
					MisslePoolManager.getInstance().LaunchGas(MissleSide.FRIENDLY,this);
					gasLastSpawnDist=curDistance+Abilities.GasParameters.betweenDist;
				}
			}
			else if(activeAbil==Abilities.AbilityType.mines)
			{
				if(curDistance>=gasLastSpawnDist)
				{
					MisslePoolManager.getInstance().LaunchMine(MissleSide.FRIENDLY,this);
					gasLastSpawnDist=curDistance+Abilities.MinesParameters.betweenDist;
				}
			}
			
			transform.eulerAngles=new Vector3(270,f2tmp,0);
			//Debug.Log("ALLY: "+f2tmp);
			fortestAngle=f2tmp;
			
			transform.position=tmpVec;
			forDist=transform.position;
		}
	}
Example #15
0
 public void _KillEnemy(EnemySpaceship _enemy)
 {
     Destroy(_enemy.gameObject);
 }
    public void STEP()
    {
        if (!exploded)
        {
            if (!Abilities.getLockGun(activeAbil))
            {
                foreach (Templates.GunOnShuttle gun in planeTemplate.guns)
                {
                    gunTemp = Templates.getInstance().getGunTemplate(gun.gunId);
                    if (!gun.ready)
                    {
                        if (gun.shotTime + gunTemp.reuse < Time.time)
                        {
                            gun.ready = true;
                        }
                    }

                    enemy = GameStorage.getInstance().getEnemyInFireZone(this, gun);
                    if (gun.ready && enemy != null)
                    {
                        //SHOT PROCEDURE WITH POOLING
                        f = Quaternion.Euler(0, 0, -gameObject.transform.eulerAngles.y) * gun.pos;
                        BulletPoolManager.getInstance().shotBullet(BulletSide.FRIENDLY, new Vector3(transform.position.x + f.x, 5, transform.position.z + f.y), enemy.transform.position, gunTemp.damage, gunTemp.bulletSpeed, gunTemp.gunType, gunTemp.attackRange, gunTemp.bulletDispersion);
                        gun.ready    = false;
                        gun.shotTime = Time.time;
                    }
                }
            }

            if (underGas)
            {
                if (Time.time >= lastGasBurned + Abilities.GasParameters.gasReuse)
                {
                    Attacked(Abilities.GasParameters.gasDamage);
                    lastGasBurned = Time.time;
                }
            }

            t           += 1f / 151f;
            x            = (1 - t) * (1 - t) * (1 - t) * point1.x + 3 * (1 - t) * (1 - t) * t * point2.x + 3 * (1 - t) * t * t * point3.x + t * t * t * point4.x;
            y            = (1 - t) * (1 - t) * (1 - t) * point1.y + 3 * (1 - t) * (1 - t) * t * point2.y + 3 * (1 - t) * t * t * point3.y + t * t * t * point4.y;
            tmpVec.x     = x;
            tmpVec.y     = 5;
            tmpVec.z     = y;
            curDistance += Vector3.Distance(forDist, tmpVec);
            if (activeAbil == Abilities.AbilityType.halfRoundTurn)
            {
                f2tmp = transform.eulerAngles.y + abilRandonRotateDirection * 180 * Time.fixedDeltaTime / 3;
            }
            else if (activeAbil == Abilities.AbilityType.turnAround)
            {
                f2tmp = transform.eulerAngles.y + abilRandonRotateDirection * 360 * Time.fixedDeltaTime / 3;
            }
            else
            {
                v2tmp1.x = x - transform.position.x;
                v2tmp1.y = y - transform.position.z;
                v2tmp2   = new Vector2(0, 5);
                f1tmp    = (v2tmp2.x * v2tmp1.y - v2tmp2.y * v2tmp1.x);
                f2tmp    = Vector2.Angle(v2tmp2, v2tmp1);
                if (f1tmp > 0)
                {
                    f2tmp = (180 - f2tmp) + 180;
                }
            }

            if (activeAbil == Abilities.AbilityType.homingMissle && t >= 0.5f && !rocketLaunched)
            {
                MisslePoolManager.getInstance().LaunchRocket(MissleSide.FRIENDLY, this);
                rocketLaunched = true;
            }
            else if (activeAbil == Abilities.AbilityType.homingThorpede && t >= 0.5f && !rocketLaunched)
            {
                MisslePoolManager.getInstance().LaunchThorpede(MissleSide.FRIENDLY, this);
                rocketLaunched = true;
            }
            else if (activeAbil == Abilities.AbilityType.gas)
            {
                if (curDistance >= gasLastSpawnDist)
                {
                    MisslePoolManager.getInstance().LaunchGas(MissleSide.FRIENDLY, this);
                    gasLastSpawnDist = curDistance + Abilities.GasParameters.betweenDist;
                }
            }
            else if (activeAbil == Abilities.AbilityType.mines)
            {
                if (curDistance >= gasLastSpawnDist)
                {
                    MisslePoolManager.getInstance().LaunchMine(MissleSide.FRIENDLY, this);
                    gasLastSpawnDist = curDistance + Abilities.MinesParameters.betweenDist;
                }
            }

            transform.eulerAngles = new Vector3(270, f2tmp, 0);
            //Debug.Log("ALLY: "+f2tmp);
            fortestAngle = f2tmp;

            transform.position = tmpVec;
            forDist            = transform.position;
        }
    }
	public void LaunchMine(MissleSide side, Object beh)
	{
		if(side==MissleSide.FRIENDLY)
		{
			friendlyInstance=(FriendlySpaceship) beh;
			misTmp=getFreeMine(side);
			misTmp.gameObject.transform.position=friendlyInstance.transform.position;
			misTmp.gameObject.transform.eulerAngles=new Vector3(270,friendlyInstance.transform.eulerAngles.y,0);
			misTmp.Activate();
			misTmp.gameObject.SetActive(true);
			activeFriendlyMinesList.Add(misTmp);
		}
		if(side==MissleSide.ENEMY)
		{
			enemyInstance=(EnemySpaceship) beh;
			misTmp=getFreeMine(side);
			misTmp.gameObject.transform.position=enemyInstance.transform.position;
			misTmp.gameObject.transform.eulerAngles=new Vector3(270,enemyInstance.transform.eulerAngles.y,0);
			misTmp.Activate();
			misTmp.gameObject.SetActive(true);
			activeEnemyMinesList.Add(misTmp);
		}
	}