public override void Update () { base.Update (); if (alien == null) { alien = gs.aliens [gameObject] as Alien; } else if (alien.state == Alien.AlienState.SEARCHING && !alien.movingToResource) { alien.Search (); } else if (alien.state == Alien.AlienState.CARRYING) { alien.CarryResource (); } else if (alien.state == Alien.AlienState.FLEEING) { alien.Flee(); } if (alien.movingToResource) CheckDistToResource(); if (movingToShipWithResource) CheckDistToShip(); if (movingToShipToLeave) CheckDistToShip(); if (alien.Infected && infectionReady) { infectionReady = false; StartCoroutine(InfectionDamage(3)); } }
protected void Initialize() { agent = GetComponent<NavMeshAgent>(); player = FindObjectOfType<PlayerController>().gameObject; alienComponent = GetComponent<Alien>(); controller = GetComponent<AlienController>(); currentState = State.Patrol; waypoints = GameObject.FindGameObjectsWithTag("waypoint"); }
public override void Start () { base.Start (); ui = GameObject.Find("UI").GetComponent<UIManager>(); alien = gs.aliens[gameObject] as Alien; gameObject.GetComponent<SphereCollider>().radius = alien.VisionRange; gameObject.transform.Find("Fleeing").GetComponent<MeshRenderer>().enabled = false; resourceSource = gameObject.AddComponent<AudioSource>(); resourceSound = (AudioClip)Resources.Load ("resource"); resourceSource.clip = resourceSound; resourceSource.playOnAwake = false; }
public void Attack(Alien a) { if (AttackReady && GameObject.tag != "Dead") { state = MonsterState.ATTACKING; a.TakeDamage(AttackDamage, this); if (isContagious && !a.Infected) { a.Infected = true; a.GameObject.transform.Find("Infection").GetComponent<ParticleSystem>().Play(); } GameObject.GetComponent<Animation>().CrossFade("Attack", 0.1f, PlayMode.StopAll); if((GameObject.transform.position - a.GameObject.transform.position).sqrMagnitude > 2f) MoveTo(a.GameObject.transform.position); // Start cooldown of attack AttackReady = false; GameObject.GetComponent<MonsterHelper>().StartCoolDown(COOLDOWN, this); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); p.Load(Content); p.SetPlayerPos(spriteBatch); hud.Load(Content); mainMenu = new MainMenu(Content, graphics, ch); intro.Load(Content, graphics); oMenu.Load(); mainMenu.Load(Content, graphicsDevice); background = new Background(GraphicsDevice, Content); loadingScreen = new LoadingScreen(Content, graphics.GraphicsDevice); alien = new Alien(Content.Load<Texture2D>("AlienShip"), new Vector2(50, 100), Vector2.Zero, 0f, 2f, Content.Load<Texture2D>("AlienBullet")); foreach (Weapon wep in p.weapList) { wep.Load(Content, p.GetDirection()); } }
private void btgenTest_Click(object sender, RoutedEventArgs e) { BtSave.IsEnabled = true; BtSave.Visibility = Visibility.Visible; BtUpdate.IsEnabled = false; BtUpdate.Visibility = Visibility.Hidden; BtDelete.IsEnabled = false; BtDelete.Visibility = Visibility.Hidden; _alien = new Alien(); DataContext = _alien; CbChemicalBasis.ItemsSource = _alien.TypesofLifeDict; CbChemicalBasis.DisplayMemberPath = "Value"; CbChemicalBasis.SelectedValuePath = "Key"; CbChemicalBasis.SelectedValue = _alien.ChemicalBase; CbLandOrWater.ItemsSource = _alien.LandWaterDict; CbLandOrWater.DisplayMemberPath = "Value"; CbLandOrWater.SelectedValuePath = "Key"; CbLandOrWater.SelectedValue = _alien.LandOrWater; CbLandHabitat.ItemsSource = _alien.TypesofLandHabitatsDict; CbLandHabitat.DisplayMemberPath = "Value"; CbLandHabitat.SelectedValuePath = "Key"; CbLandHabitat.SelectedValue = _alien.LandHabitat; CbWaterHabitat.ItemsSource = _alien.TypesofWaterHabitatsDict; CbWaterHabitat.DisplayMemberPath = "Value"; CbWaterHabitat.SelectedValuePath = "Key"; CbWaterHabitat.SelectedValue = _alien.WaterHabitat; CbThrophicDiet.ItemsSource = _alien.TrophicDietDict; CbThrophicDiet.DisplayMemberPath = "Value"; CbThrophicDiet.SelectedValuePath = "Key"; CbThrophicDiet.SelectedValue = _alien.TrophicDiet; CbPrimaryLocomotion.ItemsSource = _alien.LocomotionDict; CbPrimaryLocomotion.DisplayMemberPath = "Value"; CbPrimaryLocomotion.SelectedValuePath = "Key"; CbPrimaryLocomotion.SelectedValue = _alien.PrimaryLocomotion; CbSecondaryLocomotion.ItemsSource = _alien.LocomotionDict; CbSecondaryLocomotion.DisplayMemberPath = "Value"; CbSecondaryLocomotion.SelectedValuePath = "Key"; CbSecondaryLocomotion.SelectedValue = _alien.SecondaryLocomotion; CheckHasSecondaryLocmotion.IsChecked = _alien.HasSecondaryLocomotion; CbSizeClass.ItemsSource = _alien.SizeClassDict; CbSizeClass.DisplayMemberPath = "Value"; CbSizeClass.SelectedValuePath = "Key"; CbSizeClass.SelectedValue = _alien.SizeClass; CbSize.Text = _alien.Size.ToString(CultureInfo.InvariantCulture); CbSymmetry.ItemsSource = _alien.SymmetryDict; CbSymmetry.DisplayMemberPath = "Value"; CbSymmetry.SelectedValuePath = "Key"; CbSymmetry.SelectedValue = _alien.Symmetry; CbSides.Text = _alien.Sides.ToString(); CbLimbSegments.Text = _alien.LimbSegments.ToString(); CbTails.ItemsSource = _alien.TailsDict; CbTails.DisplayMemberPath = "Value"; CbTails.SelectedValuePath = "Key"; CbTails.SelectedValue = _alien.Tail; CbManipulators.Text = _alien.Manipulators.ToString(); CbSkeleton.ItemsSource = _alien.SkeletonDict; CbSkeleton.DisplayMemberPath = "Value"; CbSkeleton.SelectedValuePath = "Key"; CbSkeleton.SelectedValue = _alien.Skeleton; CbSkinClass.ItemsSource = _alien.SkinTypeDict; CbSkinClass.DisplayMemberPath = "Value"; CbSkinClass.SelectedValuePath = "Key"; CbSkinClass.SelectedValue = _alien.SkinClass; CbSkin.ItemsSource = _alien.SkinDict; CbSkin.DisplayMemberPath = "Value"; CbSkin.SelectedValuePath = "Key"; CbSkin.SelectedValue = _alien.Skin; CbBreathing.ItemsSource = _alien.BreathingMethodDict; CbBreathing.DisplayMemberPath = "Value"; CbBreathing.SelectedValuePath = "Key"; CbBreathing.SelectedValue = _alien.Breathing; CbTemperture.ItemsSource = _alien.TemperatureDict; CbTemperture.DisplayMemberPath = "Value"; CbTemperture.SelectedValuePath = "Key"; CbTemperture.SelectedValue = _alien.Temperture; CbGrowthRate.ItemsSource = _alien.GrowthDict; CbGrowthRate.DisplayMemberPath = "Value"; CbGrowthRate.SelectedValuePath = "Key"; CbGrowthRate.SelectedValue = _alien.Growth; CbSexes.ItemsSource = _alien.SexesDict; CbSexes.DisplayMemberPath = "Value"; CbSexes.SelectedValuePath = "Key"; CbSexes.SelectedValue = _alien.Sex; CbGestation.ItemsSource = _alien.GestationDict; CbGestation.DisplayMemberPath = "Value"; CbGestation.SelectedValuePath = "Key"; CbGestation.SelectedValue = _alien.Gestation; CbStrategy.ItemsSource = _alien.StrategyDict; CbStrategy.DisplayMemberPath = "Value"; CbStrategy.SelectedValuePath = "Key"; CbStrategy.SelectedValue = _alien.Strategy; CbOffspringCount.Text = _alien.OffspringCount.ToString(); CbPrimarySense.ItemsSource = _alien.PrimarySenseDict; CbPrimarySense.DisplayMemberPath = "Value"; CbPrimarySense.SelectedValuePath = "Key"; CbPrimarySense.SelectedValue = _alien.PrimarySense; CbVision.ItemsSource = _alien.VisionDict; CbVision.DisplayMemberPath = "Value"; CbVision.SelectedValuePath = "Key"; CbVision.SelectedValue = _alien.Vision; CbHearing.ItemsSource = _alien.HearingDict; CbHearing.DisplayMemberPath = "Value"; CbHearing.SelectedValuePath = "Key"; CbHearing.SelectedValue = _alien.Hearing; CbTouch.ItemsSource = _alien.TouchDict; CbTouch.DisplayMemberPath = "Value"; CbTouch.SelectedValuePath = "Key"; CbTouch.SelectedValue = _alien.Touch; CbTasteSmell.ItemsSource = _alien.TasteSmellDict; CbTasteSmell.DisplayMemberPath = "Value"; CbTasteSmell.SelectedValuePath = "Key"; CbTasteSmell.SelectedValue = _alien.TasteSmell; CbIntelligence.ItemsSource = _alien.IntelligenceDict; CbIntelligence.DisplayMemberPath = "Value"; CbIntelligence.SelectedValuePath = "Key"; CbIntelligence.SelectedValue = _alien.Intelligence; CbIntelligenceValue.Text = _alien.IntelligenceValue.ToString(); CbMatingBehaviour.ItemsSource = _alien.MatingBahaviourDict; CbMatingBehaviour.DisplayMemberPath = "Value"; CbMatingBehaviour.SelectedValuePath = "Key"; CbMatingBehaviour.SelectedValue = _alien.MatingBahavior; CbSocialOrganization.ItemsSource = _alien.SocialOrganizationDict; CbSocialOrganization.DisplayMemberPath = "Value"; CbSocialOrganization.SelectedValuePath = "Key"; CbSocialOrganization.SelectedValue = _alien.SocialOrganization; CbSocialGroupSize.Text = _alien.SocialGroupSize.ToString(); CbConcentration.ItemsSource = _alien.ConcentrationDict; CbConcentration.DisplayMemberPath = "Value"; CbConcentration.SelectedValuePath = "Key"; CbConcentration.SelectedValue = _alien.Concentration; CbCuriosity.ItemsSource = _alien.CuriosityDict; CbCuriosity.DisplayMemberPath = "Value"; CbCuriosity.SelectedValuePath = "Key"; CbCuriosity.SelectedValue = _alien.Curiosity; CbEgoism.ItemsSource = _alien.EgoismDict; CbEgoism.DisplayMemberPath = "Value"; CbEgoism.SelectedValuePath = "Key"; CbEgoism.SelectedValue = _alien.Egoism; CbEmpathy.ItemsSource = _alien.EmpathyDict; CbEmpathy.DisplayMemberPath = "Value"; CbEmpathy.SelectedValuePath = "Key"; CbEmpathy.SelectedValue = _alien.Empathy; CbGegariousness.ItemsSource = _alien.GegariousnessnessDict; CbGegariousness.DisplayMemberPath = "Value"; CbGegariousness.SelectedValuePath = "Key"; CbGegariousness.SelectedValue = _alien.Gegariousness; CbImagination.ItemsSource = _alien.ImaginationDict; CbImagination.DisplayMemberPath = "Value"; CbImagination.SelectedValuePath = "Key"; CbImagination.SelectedValue = _alien.Imagination; CbChauvinism.ItemsSource = _alien.ChauvinismDict; CbChauvinism.DisplayMemberPath = "Value"; CbChauvinism.SelectedValuePath = "Key"; CbChauvinism.SelectedValue = _alien.Chauvinism; CbSuspicion.ItemsSource = _alien.SuspicionDict; CbSuspicion.DisplayMemberPath = "Value"; CbSuspicion.SelectedValuePath = "Key"; CbSuspicion.SelectedValue = _alien.Suspicion; CbPlayfulness.ItemsSource = _alien.PlayfulnessDict; CbPlayfulness.DisplayMemberPath = "Value"; CbPlayfulness.SelectedValuePath = "Key"; CbPlayfulness.SelectedValue = _alien.Playfulness; }
public AlienViewModel(Alien alien) { this.Alien = new AlienLite(); this.Alien.CopyFrom(alien); }
//Set the Alien class object instance associated with the alien public void setAlien(Alien setAlien) { alien = setAlien; }
public void SetRight(Alien alien) { rightMostAlien = alien; }
// Use this for initialization void Start() { a = transform.parent.gameObject.GetComponent <Alien> (); maxHealth = a.information.health; healthPercent = a.information.health / maxHealth; }
public IActionResult PostAlien([FromBody] Alien alien) { _context.Aliens.Add(alien); _context.SaveChanges(); return(Ok()); }
//Instantiate aliens private void instantiateAliens() { //Set camera vision to alien start vision camera angles transform.RotateAround(transform.position,Vector3.up,90); targetRotation = transform.rotation; vision+=1; //Create aliens numbCharacters = 8; aliens = new Alien[numbCharacters]; for(int i = 0;i<numbCharacters;i++){ aliens[i]= new Alien(0); availableId++; Vector3 spawnPos = getRandomAlienSpawnPoint(); GameObject tempAlien = (GameObject)Network.Instantiate(alien1Prefab as GameObject, spawnPos, Quaternion.identity,0); prefabs[i]=((GetSoldier) tempAlien.GetComponent(typeof(GetSoldier))).getSoldier(); //GameObject tempSeekingSphere=(GameObject)Network.Instantiate(seekingSpherePrefab as GameObject, spawnPos, Quaternion.identity,2); //Get Seeker and set seeking sphere to soldier ((Seeker) prefabs[i].GetComponent(typeof(Seeker))).activateNetwork(); ((Seeker) prefabs[i].GetComponent(typeof(Seeker))).setCurAlien(aliens[i]); //Sets soldier in soldier state of the soldier prefab ((AlienState) prefabs[i].GetComponent(typeof(AlienState))).setAlien(aliens[i]); ((AlienState) prefabs[i].GetComponent(typeof(AlienState))).setNetwork(); } selected=0; ((AlienState) prefabs[selected].GetComponent(typeof(AlienState))).selectCharacter(); isSoldier=false; }
public static bool Forward(byte[] id) { Alien alien = Query(id); if (alien == null) { Runtime.Notify("Invalid id"); return(false); } uint encounter = D6(); switch (encounter) { case 0: // Strength check, remove some obstacle in the way OnEncounterTriggered("strength", id); alien = Check(alien, getStrength(alien)); break; case 1: // Speed check, run through dangerous area OnEncounterTriggered("speed", id); alien = Check(alien, getSpeed(alien)); break; case 2: // Weight check, get across a weak bridge OnEncounterTriggered("weight", id); int modifier = 99 - getWeight(alien); alien = Check(alien, modifier); break; case 3: // Battle encounter OnEncounterTriggered("battle", id); byte[] enemyId = DN(getCounter()).ToByteArray(); Alien enemy = Query(enemyId); if (enemy == null) { break; } alien = Fight(alien, enemy); break; case 4: // Find treasure OnEncounterTriggered("reward", id); alien = Reward(alien); break; case 5: // Fall into trap OnEncounterTriggered("punish", id); alien = Punish(alien); break; default: return(false); } // Store the modified alien StorageMap alienMap = Storage.CurrentContext.CreateMap(nameof(alienMap)); alienMap.Put(id, Helper.Serialize(alien)); return(true); }
public static int getWeight(Alien a) { return((int)(a.Xna % 100)); // digits (7-8) }
public static int getSpeed(Alien a) { return((int)(a.Xna % 10000 / 100)); // digits (5-6) }
// Methods for getting the attributes of aliens public static int getStrength(Alien a) { return((int)(a.Xna % 1000000 / 10000)); // digits (3-4) }
public void setCurAlien(Alien newAlien) { curAlien = newAlien; }
private static bool AlienDead(Alien a) { return a.dead; }
public void AddAlien(Alien alien) { aliens.Add(alien); alien.transform.SetParent(child.transform, true); alien.SetBlackHole(); }
void SpawnAliens(int count) { for (int i = 0; i < count; i++) { var rotation = Random.Range(0.03f, 0.1f); Vector3 sec_pos = Vector3.RotateTowards(GameValues.ShipPos, new Vector3(0,0,5) * GameValues.ShipPos.magnitude, rotation, GameValues.ShipPos.magnitude); float angle = i * 360.0f/count; var detail_pos = Quaternion.AngleAxis(angle, GameValues.ShipPos) * sec_pos; Alien a = new Alien (health: 100, speed: 2f, range: 7); a.GameObject = Creator.Create ("Alien_withDying", detail_pos, "Alien"); gs.aliens.Add (a.GameObject, a); gs.creatures.Add(a.GameObject, a as Creature); a.GameObject.transform.up = -(transform.position - GameValues.ShipPos).normalized; a.Search(); } // Tell UI that aliens have been spawned ui.SetAlienSlider(); ui.SetResourceSlider(); }
public AlienSprite(Game game, Alien alien, Texture2D texture) : base(game) { this.alien = alien; this.texture = texture; }
// Update is called once per frame void Update() { currentUpgradeTime += Time.deltaTime; /* * if(currentUpgradeTime > actualUpgradeTime) * { * if (!spawnedUpgrade) * { * int randomNumber = Random.Range(0, spawnPoints.Length - 1); * GameObject spawnLocation = spawnPoints[randomNumber]; * GameObject upgrade = Instantiate(upgradePrefab) as GameObject; * } */ currentSpawnTime += Time.deltaTime; if (currentSpawnTime > generatedSpawnTime) { currentSpawnTime = 0; } generatedSpawnTime = Random.Range(minSpawnTime, maxSpawnTime); if (aliensPerSpawn > 0 && aliensOnScreen < totalAliens) { List <int> previousSpawnLocations = new List <int>(); if (aliensPerSpawn > spawnPoints.Length) { aliensPerSpawn = spawnPoints.Length - 1; } aliensPerSpawn = (aliensPerSpawn > totalAliens) ? aliensPerSpawn - totalAliens : aliensPerSpawn; for (int i = 0; i < aliensPerSpawn; i++) { if (aliensOnScreen < maxAliensOnScreen) { aliensOnScreen += 1; } int spawnPoint = -1; while (spawnPoint == -1) { int randomNumber = Random.Range(0, spawnPoints.Length - 1); if (!previousSpawnLocations.Contains(randomNumber)) { previousSpawnLocations.Add(randomNumber); spawnPoint = randomNumber; } } GameObject spawnLocation = spawnPoints[spawnPoint]; GameObject newAlien = Instantiate(alien) as GameObject; newAlien.transform.position = spawnLocation.transform.position; Alien alienScript = newAlien.GetComponent <Alien>(); alienScript.target = player.transform; Vector3 targetRotation = new Vector3(player.transform.position.x, newAlien.transform.position.y, player.transform.position.z); newAlien.transform.LookAt(targetRotation); } } }
void Awake() { //This is the start of the Game. Period. Application.targetFrameRate = 60; DontDestroyOnLoad(gameObject); Application.LoadLevel("SplashScreen"); BRAIN = gameObject.GetComponent<MasterController>(); pHelper = new PreferencesManager(); sbHelper = new SkyBoxManager(_skyBoxes); pcHelper = new PCInterface(gameObject); mHelper = new Mathius(_mathius); tHelper = new TileManager(pHelper); sHelper = new ScoreManager(mHelper,pHelper); hHelper = new HighScoreManager(); aHelper = new Alien(_alien); iHelper = new HighScoreInitials(3); UI_MAIN_MENU = new Vector3(0.0f,1.0f,-13.75854f); UI_CAMERA_ALT = new Vector3(0.0f,1.0f,-10.0f); pcHelper.set_using_PCI(pHelper.get_usePerceptual()); }
public void SetLeft(Alien alien) { leftMostAlien = alien; }
IEnumerator MoveAllWithDelay(float amountPerFrame, bool downMove) { aliens[0].GetComponent <Alien>().PlayMoveSound(); if (downMove && moveDownAtStartAmount == 0) { direction = -direction; speed += 0.05F; Alien.nextFrameMove = 0; Alien.InvertAlienNumbers(); } int alreadyMovedAmount = 0; for (int row = 0; row < SpaceInvaders.VerticalMax; row++) { for (int column = 0; column < SpaceInvaders.HorizontalMax; column++) { if (row == SpaceInvaders.VerticalMax - 1 && column == SpaceInvaders.HorizontalMax - 1) { countingAllowed = true; } int alienIndex = Alien.alienArray[row, column]; if (alienIndex != -1) { if (aliens[alienIndex - 1].GetComponent <Alien>().thisCompleted == false) { if (downMove) { aliens[alienIndex - 1].transform.Translate(0, -0.35F, 0); } else { aliens[alienIndex - 1].transform.Translate(0.2F * direction, 0, 0); } aliens[alienIndex - 1].GetComponent <Alien>().thisCompleted = true; aliens[Alien.alienArray[row, column] - 1].GetComponent <Alien>().ChangeSprite(); alreadyMovedAmount++; } } if (alreadyMovedAmount >= amountPerFrame) { alreadyMovedAmount = 0; yield return(new WaitForFixedUpdate()); } } } for (int row = 0; row < SpaceInvaders.VerticalMax; row++) { for (int column = 0; column < SpaceInvaders.HorizontalMax; column++) { if (Alien.alienArray[row, column] != -1) { if (aliens[Alien.alienArray[row, column] - 1].GetComponent <Alien>().thisCompleted == true) { aliens[Alien.alienArray[row, column] - 1].GetComponent <Alien>().thisCompleted = false; } else { /*if (downMove) * aliens[Alien.alienArray[row, column] - 1].transform.Translate(0, -0.5F, 0); * else*/ if (!downMove) { aliens[Alien.alienArray[row, column] - 1].transform.Translate(0.2F * direction, 0, 0); aliens[Alien.alienArray[row, column] - 1].GetComponent <Alien>().ChangeSprite(); } } } } } }
// Update is called once per frame void Update() { if (player == null) { return; } currentSpawnTime += Time.deltaTime; currentUpgradeTime += Time.deltaTime; if (currentUpgradeTime > actualUpgradeTime) { if (!spawnedUpgrade) { int randomNumber = Random.Range(0, spawnPoints.Length - 1); GameObject spawnLocation = spawnPoints [randomNumber]; GameObject upgrade = Instantiate(upgradePrefab) as GameObject; Upgrade upgradeScript = upgrade.GetComponent <Upgrade> (); upgradeScript.gun = gun; upgrade.transform.position = spawnLocation.transform.position; spawnedUpgrade = true; SoundManager.Instance.PlayOneShot(SoundManager.Instance.powerUpAppear); } } if (currentSpawnTime > generatedSpawnTime) { currentSpawnTime = 0; generatedSpawnTime = Random.Range(minSpawnTime, MaxSpawnTime); if (aliensPerSpawn > 0 && aliensOnScreen < totalAliens) { List <int> previousSpawnLocations = new List <int>(); if (aliensPerSpawn > spawnPoints.Length) { aliensPerSpawn = spawnPoints.Length - 1; } aliensPerSpawn = (aliensPerSpawn > totalAliens) ? aliensPerSpawn - totalAliens : aliensPerSpawn; for (int i = 0; i < aliensPerSpawn; i++) { if (aliensOnScreen < maxAliensOnscreen) { aliensOnScreen += 1; int spawnPoint = -1; while (spawnPoint == -1) { int randomNumber = Random.Range(0, spawnPoints.Length - 1); if (!previousSpawnLocations.Contains(randomNumber)) { previousSpawnLocations.Add(randomNumber); spawnPoint = randomNumber; } } GameObject spawnLocation = spawnPoints [spawnPoint]; GameObject newAlien = Instantiate(alien) as GameObject; newAlien.transform.position = spawnLocation.transform.position; Alien alienScript = newAlien.GetComponent <Alien> (); alienScript.target = player.transform; Vector3 targetRotation = new Vector3(player.transform.position.x, newAlien.transform.position.y, player.transform.position.z); newAlien.transform.LookAt(targetRotation); alienScript.OnDestroy.AddListener(AlienDestroyed); } } } } }
// Update is called once per frame void Update() { if (isGaming && !isGameOver) //main Gaming loop { labelScore.text = gameScene.Score.ToString(); ShipControl sc = spaceShip.GetComponent <ShipControl>(); #region input and moving if (strikeTrg.IsPressed) { InputStrike(); } if (Input.GetKey("d") || toRight.IsPressed) { InputRight(); } if (Input.GetKey("a") || toLeft.IsPressed) { InputLeft(); } if (Input.GetKeyDown("w") || !toRun.IsPressed) { aForceEngine = 1; } if (Input.GetKey("w") || toRun.IsPressed) { InputRun(); } #endregion ShipControl ship = spaceShip.GetComponent <ShipControl>(); ship.Move(shipSpeedVector); #region передвижение объектов foreach (Transform t in sceneObjects.GetComponentInChildren <Transform>()) { Asteroid aster = t.gameObject.GetComponent <Asteroid>(); if (aster != null) { aster.Move(); aster.Rotate(); } else { Alien alien = t.gameObject.GetComponent <Alien>(); if (alien != null) { alien.Move(); } } } #endregion if (Time.time > gameScene.timeNextGenAster) { gameScene.SetNextTimeGenAster(); if (true) { GenerateAsteroidInScene(); } } if (Time.time > gameScene.timeNextGenALien) { gameScene.SetNextTimeGenALien(); GenerateAlienInScene(); } } if (isGameOver) { } }
// Update is called once per frame void Update() { //Adds the amount of time from the past frame currentUpgradeTime += Time.deltaTime; if (currentUpgradeTime > actualUpgradeTime) { // 1 if (!spawnedUpgrade) { // 2 int randomNumber = Random.Range(0, spawnPoints.Length - 1); GameObject spawnLocation = spawnPoints[randomNumber]; // 3 GameObject upgrade = Instantiate(upgradePrefab) as GameObject; Upgrade upgradeScript = upgrade.GetComponent <Upgrade>(); upgradeScript.gun = gun; upgrade.transform.position = spawnLocation.transform.position; // 4 spawnedUpgrade = true; SoundManager.Instance.PlayOneShot(SoundManager.Instance.powerUpAppear); } } currentSpawnTime += Time.deltaTime; //This is our spawn time randomizer if (currentSpawnTime > generatedSpawnTime) { currentSpawnTime = 0; } generatedSpawnTime = Random.Range(minSpawnTime, maxSpawnTime); //This is the logic that determines if an alien should spawn if (aliensPerSpawn > 0 && aliensOnScreen < totalAliens) { //Keeps track of previous alien spawns so aliens don't spawn at the same time in the same place List <int> previousSpawnLocations = new List <int>(); //Limiting the amount of aliens by the number of spawn points if (aliensPerSpawn > spawnPoints.Length) { aliensPerSpawn = spawnPoints.Length - 1; } //spawning will never exceed the max amount configured aliensPerSpawn = (aliensPerSpawn > totalAliens) ? aliensPerSpawn - totalAliens : aliensPerSpawn; for (int i = 0; i < aliensPerSpawn; i++) { //Increment if the amount is less than the total aliens on screen if (aliensOnScreen < maxAliensOnScreen) { aliensOnScreen += 1; } //1 -1 indicates a spawn has not been picked yet int spawnPoint = -1; //2 Loop runs until it finds a spawn that is not -1 while (spawnPoint == -1) { //3 Looks for a random number as a spawn point int randomNumber = Random.Range(0, spawnPoints.Length - 1); //4 Checks to see if location was a previous spawn point already if (!previousSpawnLocations.Contains(randomNumber)) { previousSpawnLocations.Add(randomNumber); spawnPoint = randomNumber; } } //Grabs a spawn based on the index generated previously GameObject spawnLocation = spawnPoints[spawnPoint]; //Creates an instance of the alien prefab GameObject newAlien = Instantiate(alien) as GameObject; //Positions the alien at the spawn point newAlien.transform.position = spawnLocation.transform.position; //Gets a reference to the alien script Alien alienScript = newAlien.GetComponent <Alien>(); //Sets target to marine's current position alienScript.target = player.transform; //Rotate the alien towards the marine Vector3 targetRotation = new Vector3(player.transform.position.x, newAlien.transform.position.y, player.transform.position.z); newAlien.transform.LookAt(targetRotation); } } }
//Initialize all objects and variables for the game void Start() { victory= false; failed = false; aborted= false; areYouSureAbort = false; areYouSureExit = false; shootingMode=false; targetPosition = transform.position; targetRotation = transform.rotation; vision=0; Destroy(loadingScript.Instance); //AudioSource.PlayClipAtPoint(audioSource.clip, Camera.main.transform.position, 0.1f); //audio.Play(); BuildGraph.instance.Scan(); startTime = Time.time; List<Base> bases = gameManager.Instance.getBases(); Base tempBase=null; foreach (Base b in bases){ if(b.getHiredSoldiers().Count>0){ tempBase=b; break; } } if(tempBase!=null){ //TEMPORARY DECLARATION OF NUMBER OF SOLDIERS numbSoldier = tempBase.getHiredSoldiers().Count; if(numbSoldier>8){ numbSoldier=8; } // TODO shouldn't this be using aircraft soldiers? Soldier[] baseSoldiers = new Soldier[tempBase.getHiredSoldiers().Count]; tempBase.getHiredSoldiers().CopyTo(baseSoldiers,0); int tempX = 30,tempZ=120; int tempId=0; SeekerSoldier tempSeeker; selectedSoldier=0; if(gameManager.Instance.getActiveLevel().Equals("Terrain")){ while(tempId<numbSoldier){ soldiers[tempId]=baseSoldiers[tempId]; soldiers[tempId].setAmmoLeft(soldiers[tempId].getWeapon().getMaxAmmo()); soldiers[tempId].setWeaponRange(soldiers[tempId].getWeapon().getRange()); Vector3 spawnPos = new Vector3(tempX, 25.5f, tempZ); soldierPrefabs[tempId]=(GameObject)Instantiate(soldierPrefab as GameObject, spawnPos, Quaternion.identity); //soldierPrefabs[tempId].name = "Soldier"+tempId; seekingSpherePrefabs[tempId]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, spawnPos, Quaternion.identity); //Get Seeker and set seeking sphere to soldier tempSeeker = (SeekerSoldier) soldierPrefabs[tempId].GetComponent(typeof(SeekerSoldier)); tempSeeker.setTarget(seekingSpherePrefabs[tempId]); ((SeekerSoldier) soldierPrefabs[tempId].GetComponent(typeof(SeekerSoldier))).setCurSoldier(soldiers[tempId]); //Sets soldier in soldier state of the soldier prefab ((SoldierState) soldierPrefabs[tempId].GetComponent(typeof(SoldierState))).setSoldier(soldiers[tempId]); //Get next position for next soldier switch (tempX){ case 30: tempX=38; break; case 38: if(tempZ==120){ tempX=30; tempZ=112; }else{ tempX=34; tempZ=116; } break; case 34: tempX=42; break; case 42: tempX=34; tempZ=108; break; } tempId++; } }else{ soldiers = new Soldier[numbSoldier]; for(int i = 0;i<numbSoldier;i++){ soldiers[i]= baseSoldiers[i]; soldiers[tempId].setAmmoLeft(soldiers[tempId].getWeapon().getMaxAmmo()); soldiers[tempId].setWeaponRange(soldiers[tempId].getWeapon().getRange()); Vector3 spawnPos = getRandomSoldierSpawnPoint(); soldierPrefabs[i] =(GameObject)Instantiate(soldierPrefab as GameObject, spawnPos, Quaternion.identity); //GameObject tempSeekingSphere=(GameObject)Network.Instantiate(seekingSpherePrefab as GameObject, spawnPos, Quaternion.identity,2); //Get Seeker and set seeking sphere to soldier seekingSpherePrefabs[i]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, spawnPos, Quaternion.identity); //Get Seeker and set seeking sphere to soldier tempSeeker = (SeekerSoldier) soldierPrefabs[i].GetComponent(typeof(SeekerSoldier)); tempSeeker.setTarget(seekingSpherePrefabs[i]); ((SeekerSoldier) soldierPrefabs[i].GetComponent(typeof(SeekerSoldier))).setCurSoldier(soldiers[i]); //Sets soldier in soldier state of the soldier prefab ((SoldierState) soldierPrefabs[i].GetComponent(typeof(SoldierState))).setSoldier(soldiers[i]); } } } selectedSoldier = 0; ((SoldierState) soldierPrefabs[selectedSoldier].GetComponent(typeof(SoldierState))).selectCharacter(); setInGameWeapons(); //Create all aliens on field Vector3 [] positions = new Vector3[28]; positions[0] = new Vector3(105,25.5f,10); positions[1] = new Vector3(100,25.5f,10); positions[2] = new Vector3(95,25.5f,10); positions[3] = new Vector3(102.5f,25.5f,15); positions[4] = new Vector3(97.5f,25.5f,15); positions[5] = new Vector3(105,25.5f,20); positions[6] = new Vector3(100,25.5f,20); positions[7] = new Vector3(95,25.5f,20); positions[8] = new Vector3(102.5f,25.5f,25); positions[9] = new Vector3(97.5f,25.5f,25); positions[10] = new Vector3(105,25.5f,30); positions[11] = new Vector3(100,25.5f,30); positions[12] = new Vector3(95,25.5f,30); positions[13] = new Vector3(102.5f,25.5f,35); positions[14] = new Vector3(97.5f,25.5f,35); //Randomize nubmer of aliens on map int numbAlien1 = Random.Range(3,6); int numbAlien2 = Random.Range (0,5); int numbAlien3 = Random.Range (1,3); numbAliens = numbAlien1+numbAlien2+numbAlien3; int index = 0; aliens = new Alien[numbAliens]; alienPrefabs= new GameObject[numbAliens]; alienSeekingSpherePrefabs = new GameObject[numbAliens]; for(int i = 0;i<numbAliens;i++,index++){ //Set alien type if(i<numbAlien1){ aliens[i] = new Alien(0); if(gameManager.Instance.getActiveLevel().Equals("Terrain")){ alienPrefabs[i] = (GameObject)Instantiate(alien1, positions[index], Quaternion.identity); alienSeekingSpherePrefabs[i]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, positions[index], Quaternion.identity); }else{ alienPrefabs[i] = (GameObject)Instantiate(alien1, getRandomAlienSpawnPoint()+(new Vector3(0,2,0)), Quaternion.identity); alienSeekingSpherePrefabs[i]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, alienPrefabs[i].transform.position, Quaternion.identity); } }else if(i<numbAlien1+numbAlien2){ aliens[i] = new Alien(1); if(gameManager.Instance.getActiveLevel().Equals("Terrain")){ alienPrefabs[i] = (GameObject)Instantiate(alien2, positions[index], Quaternion.identity); alienSeekingSpherePrefabs[i]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, positions[index], Quaternion.identity); }else{ alienPrefabs[i] = (GameObject)Instantiate(alien2, getRandomAlienSpawnPoint()+(new Vector3(0,2,0)), Quaternion.identity); alienSeekingSpherePrefabs[i]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, alienPrefabs[i].transform.position, Quaternion.identity); } }else{ aliens[i] = new Alien(2); if(gameManager.Instance.getActiveLevel().Equals("Terrain")){ alienPrefabs[i] = (GameObject)Instantiate(alien3, positions[index], Quaternion.identity); alienSeekingSpherePrefabs[i]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, positions[index], Quaternion.identity); }else{ alienPrefabs[i] = (GameObject)Instantiate(alien3, getRandomAlienSpawnPoint()+(new Vector3(0,2,0)), Quaternion.identity); alienSeekingSpherePrefabs[i]=(GameObject)Instantiate(seekingSpherePrefab as GameObject, alienPrefabs[i].transform.position, Quaternion.identity); } } //Get Seeker and set seeking sphere to alien ((Seeker) alienPrefabs[i].GetComponent(typeof(Seeker))).setTarget(alienSeekingSpherePrefabs[i]); ((AlienState) alienPrefabs[i].GetComponent(typeof(AlienState))).setInvisible(); ((AlienState) alienPrefabs[i].GetComponent(typeof(AlienState))).setAlien (aliens[i]); } }
public AlienLite(Alien alien) { this.CopyFrom(alien); }
public void CreateNonHumanCharacter() { Character newCharacter = new Alien(); }
/// <summary> /// Returns an instance of a usable alien instance. Prefers reusing an existing (dead) /// alien over creating a new instance. /// </summary> /// <returns>An alien ready to place into the world.</returns> Alien CreateAlien() { Alien b = null; for (int i = 0; i < aliens.Count; ++i) { if (aliens[i].IsAlive == false) { b = aliens[i]; break; } } if (b == null) { b = new Alien(); aliens.Add(b); } b.IsAlive = true; return b; }
void Start() { start_spawn = true; ai = MasterController.BRAIN.al(); }
protected override void ProjectileInit(GameObject proj, Alien target) { Projectile data = proj.GetComponent <Projectile>(); data.Init(AreaOfEffect, target, Constants.bulletVelocity, Damage); }
public static void Main(string[] args) { var man = new Man(); var kart = new Kart(); var alien = new Alien(); }
private void trapAlien(Alien alien) { alien.gameObject.GetComponent<AlienAnimation>().isRagdoll = true; foreach (Rigidbody body in alien.gameObject.GetComponentsInChildren<Rigidbody>()) body.useGravity = false; alien.GetComponent<NavMeshAgent>().enabled = false; alien.gameObject.GetComponent<BaseFSM>().enabled = false; trappedRigidbodies.Add(alien.gameObject.transform.FindChild("Bip001").FindChild("Bip001 Pelvis").rigidbody); trappedRigidbodies.Add(alien.gameObject.transform.FindChild("Bip001").FindChild("Bip001 Pelvis").FindChild("Bip001 Spine").FindChild("Bip001 Spine1").rigidbody); alien.gameObject.transform.FindChild("Bip001").FindChild("Bip001 Pelvis").rigidbody.AddForce(Vector3.up * 0.5f, ForceMode.Impulse); trappedAliens.Add(alien); }
public void GameUpdate(PenguinData charData, InputsManager input, ref Data data, Settings settings, World world) { wandangle = charData.wandAngle; bool movingRight = (data.xPush < -0.001f); bool movingLeft = (data.xPush > 0.001f); if (movingRight) { penguinRenderer.flipX = false; } else if (movingLeft) { penguinRenderer.flipX = true; } if (input.quak) { anime.PlayInFixedTime("idle"); world.quack.Play(); } if (input.actionButton) { if (wandangle >= -30 && wandangle < 30) { penguinRenderer.flipX = false; anime.PlayInFixedTime(forward); animationCurrent = forward; } else if (wandangle >= 30 && wandangle < 60) { penguinRenderer.flipX = false; anime.PlayInFixedTime(dforward); animationCurrent = dforward; } else if (wandangle >= 60 && wandangle < 120) { penguinRenderer.flipX = false; anime.PlayInFixedTime(upward); animationCurrent = upward; } else if ((wandangle >= 120 && wandangle < 150)) { penguinRenderer.flipX = true; anime.PlayInFixedTime(dforward); animationCurrent = dforward; } else if (wandangle >= 150 || wandangle < -150) { penguinRenderer.flipX = true; anime.PlayInFixedTime(forward); animationCurrent = forward; } data.disableWalk = true; disableWalkingAnim = true; StopAllCoroutines(); StartCoroutine(forward_pose()); } // Enemy deaths int alienPoolLen = world.alienPool.Count; for (int i = 0; i < alienPoolLen; i++) { Alien movingAlien = world.alienPool[i]; if (!movingAlien.active) { continue; } Vector3 alienPosition = movingAlien.transform.localPosition; float xDist = (alienPosition.x - this.transform.localPosition.x); float yDist = (alienPosition.y - this.transform.localPosition.y); float distance = xDist * xDist + yDist * yDist; if (distance < 0.8f) { world.gameOver.Play(); // Debug.Log("dead"); anime.PlayInFixedTime(die); data.gameStatus = GameState.GAME_OVER; } else { //Debug.Log("alive"); } } if (disableWalkingAnim) { return; } data.disableWalk = false; movingRight = (input.movement.x > 0) || (data.xPush < -0.001f); movingLeft = (input.movement.x < 0) || (data.xPush > 0.001f); if (movingRight) { penguinRenderer.flipX = false; if (animationCurrent != walk) { anime.Play(walk); animationCurrent = walk; // Debug.Log("walllll"); } } else if (movingLeft) { penguinRenderer.flipX = true; if (animationCurrent != walk) { anime.Play(walk); animationCurrent = walk; Debug.Log("walllll"); } } else { if (animationCurrent != idle) { anime.Play(idle); animationCurrent = idle; Debug.Log("idl"); } } }
public PlayerBullet(Vector2 position, Alien target, SpaceGame parent) { this.position = position; this.target = target; timePassed = Game1.GameRandom.Next() % 1000; this.parent = parent; }
public void setAlien(Alien a) { alien=a; }
/// <summary> /// This is where all the drawings actually take place. By going through for loops and constantly changing the values /// of x and y of the images we can make it appear that the ships, bullets and aliens are moving. We also use this method /// to show the highscore, current score, lives and levels. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void GameCanvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args) { GSM.gameLevel(); //intializes the backgrounds args.DrawingSession.DrawImage(Scaling.img(BG)); //draws the backgrounds Alien.createAliens(); //additional things to draw if the game is over if (RoundEnded == true) { if (lives == 0) { Storage.UpdateScore(); } //When a new Highscore is reached if (Storage.update == true) { Storage.ReadFile(); CanvasTextLayout textLayout1 = new CanvasTextLayout(args.DrawingSession, "Score\n" + MyScore.ToString(), new CanvasTextFormat() { FontSize = (35 * scaleHeight), WordWrapping = CanvasWordWrapping.NoWrap }, 0.0f, 0.0f); //Positions the current high score after game CanvasTextLayout textLayout2 = new CanvasTextLayout(args.DrawingSession, "High Score\n" + Storage.highScore.ToString(), new CanvasTextFormat() { FontSize = (35 * scaleHeight), WordWrapping = CanvasWordWrapping.NoWrap }, 0.0f, 0.0f); //Displays if a new high score is reached CanvasTextLayout textLayout3 = new CanvasTextLayout(args.DrawingSession, "NEW HIGHSCORE!!!!!", new CanvasTextFormat() { FontSize = (50 * scaleHeight), WordWrapping = CanvasWordWrapping.NoWrap }, 0.0f, 0.0f); args.DrawingSession.DrawTextLayout(textLayout1, ((DesignWidth * scaleWidth) / 2) - ((float)textLayout1.DrawBounds.Width / 2), 400 * scaleHeight, Colors.White); args.DrawingSession.DrawTextLayout(textLayout2, ((DesignWidth * scaleWidth) / 2) - ((float)textLayout1.DrawBounds.Width / 2), 560 * scaleHeight, Colors.White); args.DrawingSession.DrawTextLayout(textLayout3, ((float)bounds.Width / 2) - 160, 50 * scaleHeight, Colors.Red); } //Every other time else { Storage.ReadFile(); CanvasTextLayout textLayout1 = new CanvasTextLayout(args.DrawingSession, "Score\n" + MyScore.ToString(), new CanvasTextFormat() { FontSize = (35 * scaleHeight), WordWrapping = CanvasWordWrapping.NoWrap }, 0.0f, 0.0f); //Positions the current high score after game CanvasTextLayout textLayout2 = new CanvasTextLayout(args.DrawingSession, "High Score\n" + Storage.highScore.ToString(), new CanvasTextFormat() { FontSize = (35 * scaleHeight), WordWrapping = CanvasWordWrapping.NoWrap }, 0.0f, 0.0f); args.DrawingSession.DrawTextLayout(textLayout1, ((DesignWidth * scaleWidth) / 2) - ((float)textLayout1.DrawBounds.Width / 2), 400 * scaleHeight, Colors.White); args.DrawingSession.DrawTextLayout(textLayout2, ((DesignWidth * scaleWidth) / 2) - ((float)textLayout1.DrawBounds.Width / 2), 560 * scaleHeight, Colors.White); } } else { if (GameState > 1) { //Positions the level number during game args.DrawingSession.DrawText("Level: " + GSM.level.ToString(), (float)bounds.Width / 2 - 185, (float)bounds.Height - 35, Color.FromArgb(255, 255, 255, 255)); // Positions the score board during game args.DrawingSession.DrawText("Score: " + MyScore.ToString(), (float)bounds.Width / 2 - 40, (float)bounds.Height - 35, Color.FromArgb(255, 255, 255, 255)); // Positions the highscore board during game args.DrawingSession.DrawText("High Score: " + Storage.STRHighScore, (float)bounds.Width / 2 - 430, (float)bounds.Height - 35, Color.FromArgb(255, 255, 255, 255)); myShip.MoveShip(); //Displaying life count args.DrawingSession.DrawText("Lives: ", (float)bounds.Width / 2 + 150, (float)bounds.Height - 35, Color.FromArgb(255, 255, 255, 255)); for (int i = 0; i < lives; i++) { args.DrawingSession.DrawImage(Scaling.img(Heart), (float)bounds.Width / 2 + (210 + (50 * i)), (float)bounds.Height - 40); } //displays the explosion of ship and alien or bullet and alien if (boomX > 0 && boomY > 0 && boomCount > 0) { args.DrawingSession.DrawImage(Scaling.img(Boom), boomX, boomY); boomCount--; } //otherwise resets coordinates else { boomCount = 60; boomX = 0; boomY = 0; } //moving alien fleet if (alienList.Count > 0) { alienList[0].MoveFleet(); } //Enemies for (int j = 0; j < alienList.Count; j++) { if (alienList[j].AlienType == 1) { ALIEN_IMG = Enemy1; } if (alienList[j].AlienType == 2) { ALIEN_IMG = Enemy2; } //moving aliens and drawing alienList[j].MoveAlien(); args.DrawingSession.DrawImage(Scaling.img(ALIEN_IMG), alienList[j].AlienXPOS, alienList[j].AlienYPOS); //alien projectiles for (int a = 0; a < alienList[j].getShootX().Count; a++) { args.DrawingSession.DrawImage(Scaling.img(AlienLaser), alienList[j].getShootX()[a], alienList[j].getShootY()[a]); //alien projectile collision if (alienList[j].getShootX()[a] - (25 * scaleWidth) >= myShip.ShipXPOS && alienList[j].getShootX()[a] <= myShip.ShipXPOS + (110 * scaleWidth) && alienList[j].getShootY()[a] + (60 * scaleHeight) >= myShip.ShipYPOS && alienList[j].getShootY()[a] <= myShip.ShipYPOS + (110 * scaleHeight)) { boomX = myShip.ShipXPOS; boomY = myShip.ShipYPOS; alienList[j].removeShoot(a); lives--; if (lives == 0) { RoundEnded = true; } } } } //Display Projectiles for (int i = 0; i < myShip.getBulletX().Count; i++) { //Beam.png needs no dimension scaling args.DrawingSession.DrawImage(Scaling.img(Photon), myShip.getBulletX()[i], myShip.getBulletY()[i]); for (int h = 0; h < alienList.Count; h++) { //70 and 77 are dimensions from boom.png if (myShip.getBulletX()[i] >= alienList[h].AlienXPOS && myShip.getBulletX()[i] <= alienList[h].AlienXPOS + (70 * scaleWidth) && myShip.getBulletY()[i] >= alienList[h].AlienYPOS && myShip.getBulletY()[i] <= alienList[h].AlienYPOS + (77 * scaleHeight)) { //50 is half of boom.png width 100 and 91 is also from boom.png boomX = alienList[h].AlienXPOS; boomY = alienList[h].AlienYPOS; MyScore = MyScore + alienList[h].AlienScore; //increases score based on the alien type destroyed liveScore = liveScore + alienList[h].AlienScore; //keeps track of score for gaining lives alienList.RemoveAt(h); myShip.removeBullet(i); //If not the first time receiving a bonus life then life is incremented every 1300000 points if (liveScore >= 65000 && firstBonus == false && lives < 6) { lives++; liveScore -= 65000; } if (liveScore >= 32000 && firstBonus == true) { lives++; firstBonus = false; } if (alienList.Count == 0) { RoundEnded = true; } break; } } } //Ship/alien collision and decremention of life. Ends game when lives get to zero for (int i = 0; i < alienList.Count; i++) { if (alienList[i].AlienXPOS + (70 * scaleWidth) >= myShip.ShipXPOS && alienList[i].AlienXPOS <= myShip.ShipXPOS + (110 * scaleWidth) && alienList[i].AlienYPOS + (77 * scaleHeight) >= myShip.ShipYPOS && alienList[i].AlienYPOS <= myShip.ShipYPOS + (110 * scaleHeight)) { boomX = myShip.ShipXPOS; boomY = myShip.ShipYPOS; alienList.RemoveAt(i); lives--; if (alienList.Count == 0) { RoundEnded = true; } else if (lives == 0) { RoundEnded = true; } } } //Draws ship args.DrawingSession.DrawImage(Scaling.img(MyShip), myShip.ShipXPOS, myShip.ShipYPOS); } } //Redraws everything GameCanvas.Invalidate(); }
IEnumerator BeamAlienToShip(Alien a) { a.GameObject.transform.Find ("Beam").GetComponent<ParticleSystem> ().Play (); yield return new WaitForSeconds(1f); a.GameObject.transform.position = GameValues.ShipPos; }
private void spawnAlien() { // Check if elapsed time is greater than the randomly generated if (currentSpawnTime > generatedSpawnTime) { // Reset the timer currentSpawnTime = 0; // This is the spawn-time randomizer generatedSpawnTime = Random.Range(minSpawnTime, maxSpawnTime); // Whether to spawn if (aliensPerSpawn > 0 && aliensOnScreen < totalAliens) { // Array to keep track of spawning spots List <int> previousSpawnLocations = new List <int>(); #region Prevent from disaster // limit the number of aliens you can spawn by the number of spawn points if (aliensPerSpawn > spawnPoints.Length) { aliensPerSpawn = spawnPoints.Length - 1; } // a spawning event will never create more aliens than the maximum amount that you've configured aliensPerSpawn = (aliensPerSpawn > totalAliens) ? aliensPerSpawn - totalAliens : aliensPerSpawn; #endregion Prevent from disaster // Iterates once for each spawned alien for (int i = 0; i < aliensPerSpawn; i++) { // Don't let the bastards grind you down if (aliensOnScreen < maxAliensOnScreen) { aliensOnScreen += 1; #region Find a spawn point // the generated spawn point number int spawnPoint = -1; // loop runs until it finds a spawn point while (spawnPoint == -1) { // possible spawn point int randomNumber = Random.Range(0, spawnPoints.Length - 1); // checks the previousSpawnLocations array to see if that random number is an active spawn point if (!previousSpawnLocations.Contains(randomNumber)) { previousSpawnLocations.Add(randomNumber); spawnPoint = randomNumber; } } #endregion Find a spawn point #region Spawn the alien // grab the spawn point GameObject spawnLocation = spawnPoints[spawnPoint]; // create an instance of alien prefab GameObject newAlien = ObjectPooler.SharedInstance.GetPooledObject("Alien"); if (newAlien != null) { newAlien.SetActive(true); // position the alien in the spawn location newAlien.transform.position = spawnLocation.transform.position; #region Set Alien target Alien alienScript = newAlien.GetComponent <Alien>(); alienScript.target = player.transform; // Rotate towards target Vector3 targetRotation = new Vector3(player.transform.position.x, newAlien.transform.position.y, player.transform.position.z); newAlien.transform.LookAt(targetRotation); alienScript.OnDisable.AddListener(AlienKilled); alienScript.GetDeathParticles().SetDeathFloor(deathFloor); #endregion Set Alien target } #endregion Spawn the alien } } } } }
void Start() { m_alien = transform.parent.GetComponent<Alien> (); }
// Update is called once per frame void Update() { if (player == null) { return; } // adds the amount of time from the past frame currentUpgradeTime += Time.deltaTime; // accumulates amount of time that's passed between each frame currentSpawnTime += Time.deltaTime; if (currentUpgradeTime > actualUpgradeTime) { // 1 after random time period passes, check if upgrade has spawned if (!spawnedUpgrade) { // 2 upgrade will appear in one alien position int randomNumber = Random.Range(0, spawnPoints.Length - 1); GameObject spawnLocation = spawnPoints[randomNumber]; // 3 handles the business of spawning the upgrade and associating gun with it GameObject upgrade = Instantiate(upgradePrefab) as GameObject; Upgrade upgradeScript = upgrade.GetComponent <Upgrade>(); upgradeScript.gun = gun; upgrade.transform.position = spawnLocation.transform.position; // 4 informs the code that upgrade has been spawned spawnedUpgrade = true; SoundManager.Instance.PlayOneShot(SoundManager.Instance.powerUpAppear); } } // spawn randomizer if (currentSpawnTime > generatedSpawnTime) { currentSpawnTime = 0; // spawn-time randomizer generatedSpawnTime = Random.Range(minSpawnTime, maxSpawnTime); // stops spawning when the maximum number of aliens are present if (aliensPerSpawn > 0 && aliensOnScreen < totalAliens) { // creates array used to keep track of where you spawn aliens each wave List <int> previousSpawnLocations = new List <int>(); // limits number of aliens you can spawn by the number of spawn points if (aliensPerSpawn > spawnPoints.Length) { aliensPerSpawn = spawnPoints.Length - 1; } // if aliensPerSpawn exceeds maximum, then the amount of spawns will reduce aliensPerSpawn = (aliensPerSpawn > totalAliens) ? aliensPerSpawn - totalAliens : aliensPerSpawn; for (int i = 0; i < aliensPerSpawn; i++) { // checks if aliensOnScreen is less than max, then increments the total screen amount if (aliensOnScreen < maxAliensOnScreen) { aliensOnScreen += 1; // 1 generated spawn point number int spawnPoint = -1; // 2 loop runs until it finds a spawn point or the spawn point is no longer -1 while (spawnPoint == -1) { // 3 produces a random number as a possible spawn point int randomNumber = Random.Range(0, spawnPoints.Length - 1); // 4 checks the previousSpawnLocations array to see if that number is an active spawn // number is added to the array and the spawnPoint is set, breaking the loop // if it finds a match, the loop iterates again if (!previousSpawnLocations.Contains(randomNumber)) { previousSpawnLocations.Add(randomNumber); spawnPoint = randomNumber; } } // grabs the spawn point based on the index that was generated GameObject spawnLocation = spawnPoints[spawnPoint]; // Instantiate() will create an instance of any prefab passed into it // it'll create an object that is type Object, so it must be cast into a GameObject GameObject newAlien = Instantiate(alien) as GameObject; // positions the alien at the spawn point newAlien.transform.position = spawnLocation.transform.position; // gets reference to the Alien script Alien alienScript = newAlien.GetComponent <Alien>(); // sets the target to the space marine's current position alienScript.target = player.transform; // rotates the alien towards the hero using the alien's Y-axis position Vector3 targetRotation = new Vector3(player.transform.position.x, newAlien.transform.position.y, player.transform.position.z); newAlien.transform.LookAt(targetRotation); // whenever this event occurs, the GameManager gets a notification alienScript.OnDestroy.AddListener(AlienDestroyed); alienScript.GetDeathParticles().SetDeathFloor(deathFloor); } } } } }