private ProjectileControl CreateProjectile(double x, double y, double angle, double shipVelocity, double width) { ProjectileControl projectile = new ProjectileControl(); projectile.Width = width; projectile.X = x; projectile.Y = y; projectile.Angle = angle; projectile.SetVelocityBasedOnAngle(shipVelocity + ProjectileDiffVelocity); projectile.OutOfLimits += OnProjectileOutOfLimits; double widthHalved = _width / 2; double heightHalved = _height / 2; Rect limits = new Rect( new Point(-widthHalved - LimitsMargin, -heightHalved - LimitsMargin), new Point(widthHalved + LimitsMargin, heightHalved + LimitsMargin)); projectile.Limits = limits; _projectiles.Add(projectile); gameArea.Children.Add(projectile); return(projectile); }
private void OnProjectileOutOfLimits(object sender, EventArgs e) { ProjectileControl projectile = sender as ProjectileControl; if (projectile != null) { DeleteProjectile(projectile); } }
IEnumerator SpawnBlades() { while (currentSpawnCount < MaxDuration) { var instance = Instantiate(ProjectilePrefab); ProjectileControl p = instance.GetComponent <ProjectileControl>(); p.setUnitType(UnitType.Ally); bool bleed = Random.Range(0, 100) < UpgradedSkill.Upgrades[SkillUpgrade.RoBBleed] * SkillUpgrade.RoBBleed.SpecialAmount;//whether his blade will cause bleed bool piercing = false; int dmgMulti = 1; //fourth big blade counter if (UpgradedSkill.Upgrades[SkillUpgrade.RoBFourth] > 0) { piercing = true; bigBladeCounter++; if (bigBladeCounter == 4) { bigBladeCounter = 0; p.transform.localScale *= 1.5f; dmgMulti = 1 + (int)(UpgradedSkill.Upgrades[SkillUpgrade.RoBFourth] * SkillUpgrade.RoBFourth.SpecialAmount); } } int xDir = Random.Range(-(int)(UpgradedSkill.ProjectileSpeed * 0.6f), (int)(UpgradedSkill.ProjectileSpeed * 0.6f)); p.SetUp(UpgradedSkill.Amount * dmgMulti, new Vector2(xDir, -UpgradedSkill.ProjectileSpeed), piercing, bleed ? 1 : 0, 0); p.transform.position = transform.position; if (UpgradedSkill.Upgrades[SkillUpgrade.RoBSlow] > 0) { p.AddSlow(UpgradedSkill.Upgrades[SkillUpgrade.RoBSlow] * (int)SkillUpgrade.RoBSlow.SpecialAmount); } currentSpawnCount += SpawnInterval; //movement if (movementSpeed > 0 && ClosestEnemy != null) { if (ClosestEnemy.transform.position.x > transform.position.x + 0.5f) { GetComponent <Rigidbody2D>().velocity = new Vector2(movementSpeed, 0); } else if (ClosestEnemy.transform.position.x < transform.position.x - 0.5f) { GetComponent <Rigidbody2D>().velocity = new Vector2(-movementSpeed, 0); } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); } } else { GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); } yield return(new WaitForSeconds(SpawnInterval)); } Destroy(gameObject); }
private void OnNcc1701FireEvent(object sender, EventArgs e) { double angle = ncc1701.Angle; double x = ncc1701.X + 70d * Math.Sin(angle * Math.PI / 180d); double y = ncc1701.Y - 70d * Math.Cos(angle * Math.PI / 180d); ProjectileControl projectile = CreateProjectile(x, y, angle, ncc1701.TotalVelocity(), PhotonTorpedoWidth); projectile.ImageUri = new Uri("ms-appx:///Assets/PhotonTorpedo.png"); }
public void Throw(GameObject projectilePrefab, Vector2 direction) { GameObject projectileObject = Instantiate( projectilePrefab, transform.position, transform.rotation); ProjectileControl projectile = projectileObject.GetComponent <ProjectileControl>(); projectile.Launch(direction, 30 * 3 * 5); }
void OnTriggerExit2D(Collider2D other) { // If the projectile leaves the Collider2D boundary... if (other.GetComponent <Rigidbody2D>() == projectile) { // ... call the Reset() function ProjectileControl pj = FindObjectOfType <ProjectileControl>(); pj.Reset(); } }
private void createGrenade() { GameObject newProjectileGO = (GameObject)Instantiate(grenadePrefab); ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>(); newProjectileScript.youAreA(ProjectileControl.ProjectileType.Grenade, transform.position + 2 * transform.forward + 2 * transform.up, (transform.forward + Vector3.up).normalized, MaxGrenadeSpeed * strengthMeter.relative(), ourOwner); Destroy(strengthMeter); GrenadeDisplayTest.manuallyDestroy(); }
private void OnXwingFireEvent(object sender, EventArgs e) { double angle = xwing.Angle; double offset = _leftXwingCannonIsCurrent ? -15d : 15d; _leftXwingCannonIsCurrent = !_leftXwingCannonIsCurrent; double x = xwing.X + offset * Math.Cos(angle * Math.PI / 180d) + 10d * Math.Sin(angle * Math.PI / 180d); double y = xwing.Y + offset * Math.Sin(angle * Math.PI / 180d) - 10d * Math.Cos(angle * Math.PI / 180d); ProjectileControl projectile = CreateProjectile(x, y, angle, xwing.TotalVelocity(), LaserProjectileWidth); projectile.ImageUri = new Uri("ms-appx:///Assets/LaserProjectile.png"); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Projectile_Asam" || collision.tag == "Projectile_Basa" || collision.tag == "Projectile_Netral") { PlayExplosion(); Destroy(this.gameObject); if (this.gameObject.tag == "Balon_Asam") { ScoreController2 sc = FindObjectOfType <ScoreController2>(); sc.addScore(10); } else if (this.gameObject.tag == "Balon_Basa") { ScoreController2 sc = FindObjectOfType <ScoreController2>(); sc.addScore(10); } else if (this.gameObject.tag == "Balon_Netral") { ScoreController2 sc = FindObjectOfType <ScoreController2>(); sc.addScore(10); } else { ScoreController2 sc = FindObjectOfType <ScoreController2>(); sc.minScore(10); } } if (collision.tag == "Projectile_Asam") { ProjectileControl pj = FindObjectOfType <ProjectileControl>(); pj.Activate_ASAM(false); pj.Reset(); //PauseGame(); } if (collision.tag == "Projectile_Basa") { ProjectileControl pj = FindObjectOfType <ProjectileControl>(); pj.Activate_ASAM(false); pj.Reset(); //PauseGame(); } if (collision.tag == "Projectile_Netral") { ProjectileControl pj = FindObjectOfType <ProjectileControl>(); pj.Activate_ASAM(false); pj.Reset(); // PauseGame(); } }
public void Shoot(SpheroWeaponType type, float direction) { //Get the ProjectileControl object associated with the shooting player String playerName = DeviceName.ToLower().Contains("boo") ? "player1" : "player2"; ProjectileControl playerProjectile = GameObject.Find(playerName).GetComponent <ProjectileControl>(); //Put the direction into the correct range direction += (float)Math.PI; //Covert the direction into a vector Vector3 directionVector = new Vector3((float)Math.Cos(direction), (float)Math.Sin(direction), 0.0f); //Tell the sphero to shoot playerProjectile.Shoot(directionVector); }
private void createGrenade() { //Removes a grenade from the inventory when a grenade is launched myTeamInventory.removeGrenades(1); // GameObject newProjectileGO = (GameObject)Instantiate(grenadePrefab); ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>(); newProjectileScript.youAreA(ProjectileControl.ProjectileType.Grenade, transform.position + 2 * transform.forward + 2 * transform.up, (transform.forward + Vector3.up).normalized, MaxGrenadeSpeed * strengthMeter.relative(), ExplosionPrefab, ourOwner); Destroy(strengthMeter); GrenadeDisplayTest.manuallyDestroy(); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.G)) { GameObject newProjectileGO = (GameObject)Instantiate(grenadePrefab); ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>(); newProjectileScript.youAreA(ProjectileControl.ProjectileType.Grenade, new Vector3(2, 3, 4), new Vector3(1, 0, 0), 5.0f); } else if (Input.GetKeyDown(KeyCode.M)) { GameObject newProjectileGO = (GameObject)Instantiate(grenadePrefab); ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>(); newProjectileScript.youAreA(ProjectileControl.ProjectileType.Missile, new Vector3(-2, 3, 4), new Vector3(0, 1, 0), 15.0f); } }
void Update() { // If we hold down the "R" key... if (Input.GetKeyDown(KeyCode.R)) { // ... call the Reset() function ProjectileControl pj = FindObjectOfType <ProjectileControl>(); pj.Reset(); } // If the spring had been destroyed (indicating we have launched the projectile) and our projectile's velocity is below the threshold... if (spring == null && projectile.velocity.sqrMagnitude < resetSpeedSqr) { // ... call the Reset() function ProjectileControl pj = FindObjectOfType <ProjectileControl>(); pj.Reset(); } }
private void OnTriggerEnter(Collider collider) { if (collider.tag == "Player" && isConsumable) { PlayerControl controller = collider.GetComponent <PlayerControl>(); changeParticle.Play(); controller.consumeStar(this.state); Destroy(this.gameObject); ++GameData.Instance.consume; } if (collider.tag == "Projectile") { ProjectileControl controller = collider.GetComponent <ProjectileControl>(); if (hp > 0) { hp -= controller.getDamage(state); } } }
void Detonate() { GetComponent <Animator>().Play("Spring"); canDetect = false; if (spikes > 0) { for (int i = 0; i < spikes; i++) { var instance = Instantiate(spikePrefab); ProjectileControl p = instance.GetComponent <ProjectileControl>(); p.setUnitType(UnitType.Ally); float xDir = Random.Range(-20, 20); float yDir = 20 - Mathf.Abs(xDir); p.SetUp(5, new Vector2(xDir, yDir), true, 0, 0); p.DontCollideWithWalls(1); p.transform.position = transform.position; } } }
void OnTriggerEnter(Collider other) { if (other.tag == "Asteroid") { return; } //Collisions with the player buildings. Calls for a game over check if (other.tag == "Player") { other.gameObject.SetActive(false); GetComponent <AsteroidControl>().Impact(); gameController.CheckGameOverConditions(); } //Collisions with the shield. Applies its damage value to the shield if (other.tag == "Shield") { other.GetComponent <ShieldControl>().RegisterShieldHit(scoreValue); GetComponent <AsteroidControl>().Impact(); } //Collisions with a missile. Takes the damage value of the missile and calls it to detonate. if (other.tag == "Missile") { MissileControl mc = other.GetComponent <MissileControl>(); currentDmg -= mc.missileDamage; mc.DetonateMissile(); } //Collision with a projectile. Takes the damage value of the projectile and calls for it //to be destroyed if (other.tag == "Projectile") { ProjectileControl pc = other.GetComponent <ProjectileControl>(); currentDmg -= pc.damageValue; pc.Destroy(); } //Collision with the game surface. Nothing to see here. if (other.tag == "TargetSurface") { gameObject.GetComponent <AsteroidControl>().DisableAsteroid(); } }
// FIRING CURRENT BELT public void Fire() { if (unitReloaded) { // SHOT CAN BE DONE lastShotTime = Time.time; unitReloaded = false; unitReloadSounded = false; //Vector3 projectileGlobalPos = thisBeltUnit.transform.TransformPoint(unitDirTransf.position); // MAKING SOUND unitSound.PlayOneShot(beltParams.unitParams.unitSound, beltParams.unitParams.unitSoundVolume); // CREATING PROJECTILE OBJECT Quaternion fireSpread = Quaternion.Euler(UnityEngine.Random.Range(-beltParams.unitParams.fireSpreadAngle, beltParams.unitParams.fireSpreadAngle), UnityEngine.Random.Range(-beltParams.unitParams.fireSpreadAngle, beltParams.unitParams.fireSpreadAngle), 0); GameObject newProjectile = Instantiate(projectilePrefab, unitDirTransf.position, unitDirTransf.rotation * fireSpread, null); newProjectile.tag = "FlyingProjectile"; // CUSTOMIZATION OF PROJECTILE CLASH LIGHT Light[] lights = newProjectile.GetComponentsInChildren <Light>(); foreach (Light light in lights) { if (light.tag == "ClashLight") { light.intensity = beltParams.unitParams.explosionLightIntensity; light.range = beltParams.unitParams.explosionLightRadius; } } // TRANSFERRING PARAMETERS TO SCRIPT ProjectileControl newProjectileControl = newProjectile.GetComponent <ProjectileControl>(); newProjectileControl.parentUnitParams = beltParams.unitParams; newProjectileControl.poleModif = poleModif; newProjectileControl.infoText = globalObjects.infoText; // GENERATING RECOIL parentPole.GetComponent <PoleControl>().recoilSpeed = -newProjectile.transform.forward.normalized * beltParams.unitParams.recoil; } }
// Update is called once per frame void Update() { ProjectileControl pj = FindObjectOfType <ProjectileControl>(); pj.Reset(); }
private void OnEnable() { control = GetComponent <ProjectileControl>(); }
// Update is called once per frame void Update() { if (ourOwner.isWormActive()) { //Checks if G is pressed and that the team's inventory has a grenade if (Input.GetKey(KeyCode.G) && (myTeamInventory.getGrenades() > 0)) { if (GrenadeDisplayTest) // grenade strength being calculated { GrenadeDisplayTest.setDisplay(((int)(strengthMeter.relativePercentage())).ToString()); //strengthMeterDisplay.transform.localPosition += 0.5f * Vector3.up; I tried to make the grenade strength meter go above the health but i think ill just go for hiding the health and making it re-appear // strengthMeterDisplay.transform.position += 0.5f * Vector3.up; if (strengthMeter.relative() > 1.0f) { createGrenade(); } } else // Start of launch grenade { GrenadeDisplayTest = gameObject.AddComponent <PowerDisplay>(); strengthMeter = gameObject.AddComponent <TimeAndDisplayCountup>(); strengthMeter.setDuration(5.0f); strengthMeter.startTimer(); //strengthMeterDisplay.transform.localPosition = 2.5f * Vector3.up; } } else if (myTeamInventory.getGrenades() == 0) { Debug.Log("No Grenades in Inventory (P to add)"); } else { if (strengthMeter) { createGrenade(); } } if (Input.GetKey(KeyCode.M)) { if (ourAimCam) { print("Camera made"); ourAimCam.updateHorizontalAngle(Input.GetAxis("Horizontal")); ourAimCam.updateVerticalAngle(Input.GetAxis("Vertical")); if (crosshairs) { crosshairs.transform.position = ourAimCam.target; } if (Input.GetMouseButtonDown(0)) { GameObject newProjectileGO = (GameObject)Instantiate(grenadePrefab); ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>(); newProjectileScript.youAreA(ProjectileControl.ProjectileType.Missile, ourAimCam.transform.position, (ourAimCam.target - ourAimCam.transform.position).normalized, 15.0f, ExplosionPrefab, ourOwner); DestroyAimCam(); // ourOwner.setActive(false); } } else { print("Adding Aim Camera"); GameObject cam = new GameObject("Aiming Camera"); cam.AddComponent <Camera>(); ourAimCam = cam.gameObject.AddComponent <AimCameraControl>(); ourAimCam.transform.position = transform.position + 2.0f * Vector3.up - 2.0f * transform.forward; ourAimCam.transform.rotation = transform.rotation; ourAimCam.target = transform.position + 50 * transform.forward; crosshairs = GameObject.CreatePrimitive(PrimitiveType.Sphere); firingMissile = true; } } else // M released (or not pressed) { if (firingMissile) { Destroy(ourAimCam.gameObject); Destroy(crosshairs); firingMissile = false; } } //Fire Bullet if (Input.GetKey(KeyCode.F)) { if (ourAimCam) { ourAimCam.transform.Rotate(Vector3.up, Input.GetAxis("Horizontal")); ourAimCam.transform.Rotate(transform.right, Input.GetAxis("Vertical")); if (crosshairs) { crosshairs.transform.position = ourAimCam.transform.position + 50.0f * ourAimCam.transform.forward; } if (Input.GetMouseButtonDown(0)) { Debug.DrawRay(ourAimCam.transform.position, ourAimCam.transform.forward * 1000, Color.blue, 10.0f); Ray bullets = new Ray(ourAimCam.transform.position, ourAimCam.transform.forward); RaycastHit info = new RaycastHit(); if (Physics.Raycast(bullets, out info)) { Health healthOfVictim = info.collider.GetComponent <Health>(); if (healthOfVictim) { healthOfVictim.adjustHealth(-20); } } DestroyAimCam(); ourOwner.setActive(false); } } else { GameObject cam = new GameObject("Bullet Camera"); cam.AddComponent <Camera>(); ourAimCam = cam.gameObject.AddComponent <AimCameraControl>(); ourAimCam.transform.position = transform.position + 2.0f * Vector3.up - 2.0f * transform.forward; ourAimCam.transform.rotation = transform.rotation; crosshairs = GameObject.CreatePrimitive(PrimitiveType.Cylinder); firingBullet = true; } } else // F released (or not pressed) { if (firingBullet) { firingBullet = false; Destroy(ourAimCam.gameObject); Destroy(crosshairs); } } } }
// Use this for initialization void Start() { ourControl = gameObject.GetComponent <ProjectileControl>(); }
// Update is called once per frame void Update() { if (ourOwner.isWormActive()) { if (Input.GetKey(KeyCode.G)) { //Checks that the player inventory has a grenade //if (player.allTeams[player.current_Team_Index].teamInventory.getGrenades() > 0) //{ if (GrenadeDisplayTest) // grenade strength being calculated { GrenadeDisplayTest.setDisplay(((int)(strengthMeter.relativePercentage())).ToString()); //strengthMeterDisplay.transform.localPosition += 0.5f * Vector3.up; I tried to make the grenade strength meter go above the health but i think ill just go for hiding the health and making it re-appear // strengthMeterDisplay.transform.position += 0.5f * Vector3.up; if (strengthMeter.relative() > 1.0f) { createGrenade(); } } else // STart of launch grenade { GrenadeDisplayTest = gameObject.AddComponent <PowerDisplay>(); strengthMeter = gameObject.AddComponent <TimeAndDisplayCountup>(); strengthMeter.setDuration(5.0f); strengthMeter.startTimer(); //strengthMeterDisplay.transform.localPosition = 2.5f * Vector3.up; } //} //Removes a grenade from the inventory //player.allTeams[player.current_Team_Index].teamInventory.removeGrenades(1); //} //else //{ //Debug.Log("No Grenades in Inventory (P to add)"); //} } else { if (strengthMeter) { createGrenade(); } } if (Input.GetKey(KeyCode.M)) { if (ourAimCam) { ourAimCam.transform.Rotate(Vector3.up, Input.GetAxis("Horizontal")); ourAimCam.transform.Rotate(transform.right, Input.GetAxis("Vertical")); if (crosshairs) { crosshairs.transform.position = ourAimCam.transform.position + 50.0f * ourAimCam.transform.forward; } if (Input.GetMouseButtonDown(0)) { GameObject newProjectileGO = (GameObject)Instantiate(grenadePrefab); ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>(); newProjectileScript.youAreA(ProjectileControl.ProjectileType.Missile, ourAimCam.transform.position, ourAimCam.transform.forward, 15.0f, ourOwner); DestroyAimCam(); ourOwner.setActive(false); } } else { GameObject cam = new GameObject(); cam.AddComponent <Camera>(); ourAimCam = cam.gameObject.AddComponent <AimCameraControl>(); ourAimCam.transform.position = transform.position + 2.0f * Vector3.up - 2.0f * transform.forward; ourAimCam.transform.rotation = transform.rotation; crosshairs = GameObject.CreatePrimitive(PrimitiveType.Sphere); } } else // M released (or not pressed) { if (ourAimCam) { Destroy(ourAimCam.gameObject); Destroy(crosshairs); } } } }
private void DeleteProjectile(ProjectileControl projectile) { gameArea.Children.Remove(projectile); _projectiles.Remove(projectile); }