private IEnumerator Get(string url) { UnityWebRequest request = UnityWebRequest.Get(url); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { UnityEngine.Debug.LogError(request.error); EditorApplication.isPlaying = false; } else { byte[] data = request.downloadHandler.data; // TODO #if true Buzzard.WorkerThread(() => { Buzzard.BuzzardImageLoadTextureData(0, (byte[])data, OnLoadTextureData); }); #else Texture2D texture = new Texture2D(0, 0, TextureFormat.RGBA32, false); ImageConversion.LoadImage(texture, (byte[])data, false); SetTexture(s_RawImage, texture); #endif } }
/// <summary> /// Runs when the EggHatched fires. It updates the graphic /// of the Control to a hatched Mik and creates a Buzzard to /// pick up the Mik. /// </summary> public void NotifyHatch(object sender, EventArgs e) { Egg egg = sender as Egg; Point p = new Point(0, egg.coords.y - 70); // Create a new Buzzard Buzzard b = new Buzzard(); b.coords = p; b.angle = 0; b.droppedEgg = true; // Set state to Pickup state b.state = new BuzzardPickupState() { Angle = (int)b.angle, TargetEgg = egg, StateEnemy = b }; b.state.Setup(); // Create a new BuzzardControl BuzzardControl eCtrl = new BuzzardControl(b.imagePath); // Subscribe to event handlers b.BuzzardMoveEvent += eCtrl.NotifyMoved; b.BuzzardStateChange += eCtrl.NotifyState; b.BuzzardDropEgg += eCtrl.NotifyDrop; b.BuzzardDestroyed += eCtrl.NotifyDestroy; Canvas.SetTop(eCtrl, b.coords.y); Canvas.SetLeft(eCtrl, b.coords.x); Canvas canvas = Parent as Canvas; canvas.Children.Add(eCtrl); }
static private void OnLoadTextureData(int id, int width, int height, IntPtr texture_data_p, int texture_data_size) { byte[] texture_data = Buzzard.ToBytes(texture_data_p, texture_data_size); Buzzard.MainThread(() => { Texture2D texture = new Texture2D(width, height, TextureFormat.RGBA32, false); texture.LoadRawTextureData(texture_data); texture.Apply(false, false); SetTexture(s_RawImage, texture); }); }
/// <summary> /// Runs when the BuzzardStateChange fires. It updates the graphic /// of the Control to that of the model's state. /// </summary> public void NotifyState(object sender, EventArgs e) { Buzzard buzzard = sender as Buzzard; if (buzzard.stateMachine.currentState is EnemySpawningState) { Clip = new RectangleGeometry(new System.Windows.Rect(0, 0, ActualWidth, buzzard.respawning / 2)); } else { Clip = new RectangleGeometry(new System.Windows.Rect(0, 0, ActualWidth, ActualHeight)); } Source = new BitmapImage(new Uri(buzzard.imagePath, UriKind.Relative)); }
/// <summary> /// Runs when the BuzzardMoveEvent fires. It updates the position /// of the Control to that of the model. /// </summary> public void NotifyMoved(object sender, EventArgs e) { Buzzard buzzard = sender as Buzzard; // Determine the endpoint of the move vector double xPos = Canvas.GetLeft(this) + buzzard.speed * Math.Cos(((buzzard.angle + 180) * Math.PI / 180)); double yPos = Canvas.GetTop(this) + buzzard.speed * Math.Sin(((buzzard.angle + 180) * Math.PI / 180)); buzzard.coords = new Point(xPos, yPos); // Flipping the image to turn left or right if (xPos < Canvas.GetLeft(this)) { LayoutTransform = new ScaleTransform() { ScaleX = -1 } } ; else { LayoutTransform = new ScaleTransform() { ScaleX = 1 } }; // Handles transporting the Control from one side of the screen to the other if (xPos > (1440 - Width)) { xPos -= 1440 - Width; } else if (xPos < 0) { xPos += 1440 - Width; } if (yPos >= 0 && yPos <= 900 - Height) { Canvas.SetTop(this, yPos); } Canvas.SetLeft(this, xPos); }
/// <summary> /// Runs when the EggHatched fires. It updates the graphic /// of the Control to a hatched Mik and creates a Buzzard to /// pick up the Mik. /// </summary> public void NotifyHatch(object sender, EventArgs e) { Egg egg = sender as Egg; int spawnX = 0; int spawnY = 0; Console.WriteLine("SpawnPoints = " + World.Instance.SpawnPoints.Count); //egg crash??? int randNum = new Random().Next(World.Instance.SpawnPoints.Count - 1); Point[] pArray = World.Instance.SpawnPoints[randNum]; spawnX = (int)(((pArray[1].x - pArray[0].x) / 2) + (pArray[0].x - 10)); spawnY = (int)pArray[0].y; Point p = new Point(spawnX, spawnY); // Create a new Buzzard Buzzard b = new Buzzard(); b.coords = p; b.angle = 0; b.droppedEgg = true; // Set state to Pickup state b.stateMachine.Change("spawn"); b.pickupEgg = egg; b.stateMachine.currentState.Update(); // Create a new BuzzardControl BuzzardControl eCtrl = new BuzzardControl(b.imagePath); // Subscribe to event handlers b.BuzzardMoveEvent += eCtrl.NotifyMoved; b.BuzzardStateChange += eCtrl.NotifyState; b.BuzzardDropEgg += eCtrl.NotifyDrop; b.BuzzardDestroyed += eCtrl.NotifyDestroy; Canvas.SetTop(eCtrl, b.coords.y); Canvas.SetLeft(eCtrl, b.coords.x); Canvas canvas = Parent as Canvas; canvas.Children.Add(eCtrl); }
/// <summary> /// Runs when the BuzzardDropEgg fires. It creates an Egg object /// and sends it in the direction the Buzzard was going. The graphic /// is changed to just the Buzzard as it flies to the left of the screen /// and disappears. /// </summary> public void NotifyDrop(object sender, EventArgs e) { Buzzard buzzard = sender as Buzzard; // Create a new Egg Egg egg = new Egg(); egg.coords = buzzard.coords; egg.speed = buzzard.speed; if (buzzard.angle > 90 && buzzard.angle < 270) { egg.stateMachine.Change("fall_left"); } else if (buzzard.angle > 270 && buzzard.angle < 90) { egg.stateMachine.Change("fall_right"); } else { egg.stateMachine.Change("fall"); } // Create a new EggControl EggControl eCtrl = new EggControl(egg.imagePath); // Subscribe to the event handlers egg.EggMoveEvent += eCtrl.NotifyMoved; egg.EggStateChange += eCtrl.NotifyState; egg.EggHatched += eCtrl.NotifyHatch; egg.EggDestroyed += eCtrl.NotifyDestroy; Canvas.SetTop(eCtrl, egg.coords.y); Canvas.SetLeft(eCtrl, egg.coords.x); Canvas canvas = Parent as Canvas; canvas.Children.Add(eCtrl); Task.Run(() => { PlaySounds.Instance.Play_Drop(); }); }
/// <summary> /// Runs when the BuzzardDropEgg fires. It creates an Egg object /// and sends it in the direction the Buzzard was going. The graphic /// is changed to just the Buzzard as it flies to the left of the screen /// and disappears. /// </summary> public void NotifyDrop(object sender, EventArgs e) { Buzzard buzzard = sender as Buzzard; // Create a new Egg Egg egg = new Egg(); egg.coords = buzzard.coords; // Set to a downwards angle if (buzzard.angle > 180) { egg.angle = buzzard.angle; } else { egg.angle = buzzard.angle + 180; } egg.speed = buzzard.speed; egg.state = new EnemyFallingState() { Angle = buzzard.state.Angle, StateEnemy = egg }; // Create a new EggControl EggControl eCtrl = new EggControl(egg.imagePath); // Subscribe to the event handlers egg.EggMoveEvent += eCtrl.NotifyMoved; egg.EggStateChange += eCtrl.NotifyState; egg.EggHatched += eCtrl.NotifyHatch; egg.EggDestroyed += eCtrl.NotifyDestroy; Canvas.SetTop(eCtrl, egg.coords.y); Canvas.SetLeft(eCtrl, egg.coords.x); Canvas canvas = Parent as Canvas; canvas.Children.Add(eCtrl); }
public void WorldObjectControlFactory(WorldObject worldObject) { string woString = worldObject.ToString(); Image i; switch (woString) { case "Ostrich": Ostrich o = worldObject as Ostrich; i = new OstrichControl(o.imagePath); OstrichControl oC = i as OstrichControl; o.ostrichMoved += oC.NotifyMoved; break; case "Buzzard": Buzzard b = worldObject as Buzzard; i = new BuzzardControl(b.imagePath); BuzzardControl bC = i as BuzzardControl; // Used to update the view with model updates b.BuzzardMoveEvent += bC.NotifyMoved; b.BuzzardStateChange += bC.NotifyState; b.BuzzardDropEgg += bC.NotifyDrop; b.BuzzardDestroyed += bC.NotifyDestroy; // Used to update all enemies in the world //DispatcherTimer moveTimer = new DispatcherTimer(); //moveTimer.Interval = new TimeSpan(0, 0, 0, 0, 33); //moveTimer.Tick += World.Instance.UpdateAllEnemies_Position; //moveTimer.Start(); /* Comment: Clayton Cockrell * The Random object in Buzzard would give the same random number to all the * Buzzard objects if their creation was not halted for a little bit of time. */ Thread.Sleep(20); break; case "Pterodactyl": PterodactylControl pCtrl = new PterodactylControl("Images/Enemy/pterodactyl.fly1"); i = pCtrl; /* Comment: Clayton Cockrell * Pterodactyls spawn after a certain number of minutes. I currently have it set * to 1 minute. (To change, see PTERODACTYL_SPAWN_MINUTES constant in World class) */ World.Instance.SpawnPterodactyl += pCtrl.NotifySpawn; break; case "Egg": Egg e = worldObject as Egg; i = new EggControl(e.imagePath); EggControl eC = i as EggControl; break; case "Platform": Platform pl = worldObject as Platform; i = new PlatformControl(pl.imagePath); PlatformControl pC = i as PlatformControl; break; case "Respawn": Respawn r = worldObject as Respawn; i = new RespawnControl(r.imagePath); RespawnControl rC = i as RespawnControl; break; default: Base ba = worldObject as Base; i = new BaseControl(ba.imagePath); BaseControl baC = i as BaseControl; break; } canvas.Children.Add(i); Canvas.SetTop(i, worldObject.coords.y); Canvas.SetLeft(i, worldObject.coords.x); //Title_Screen(null, EventArgs.Empty); //Finish_HighScores(null, EventArgs.Empty); // called when game end conditions have been met }
/// <summary> /// Runs when the BuzzardStateChange fires. It updates the graphic /// of the Control to that of the model's state. /// </summary> public void NotifyState(object sender, EventArgs e) { Buzzard buzzard = sender as Buzzard; Source = new BitmapImage(new Uri(buzzard.imagePath, UriKind.Relative)); }
void OnDestroy() { Buzzard.End(); }
void Awake() { s_RawImage = GameObject.Find("RawImage").GetComponent <RawImage>(); Buzzard.Begin(); }