void Update() { allObjects.Sort((obj1, obj2) => obj1.transform.position.y.CompareTo(obj2.transform.position.y)); int order = allObjects.Count; foreach (GameObject obj in allObjects) { order--; if (obj.tag == "Player") { Player objSprite = obj.GetComponent <Player>(); objSprite.sprite.sortingOrder = order; } else if (obj.tag == "enemy") { Enemy objSprite = obj.GetComponent <Enemy>(); objSprite.sprite.sortingOrder = order; } else if (obj.tag == "firefly") { Firefly objSprite = obj.GetComponent <Firefly>(); objSprite.sprite.sortingOrder = order; } } }
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { // Parse Navigation Args List <object> itemPageNavList = (List <object>)e.NavigationParameter; pivotPageRef = (PivotPage)itemPageNavList.ElementAt <object>(0); fireflyClicked = (Firefly)itemPageNavList.ElementAt <object>(1); // Load details tblId.Text = fireflyClicked.Id; if (fireflyClicked.Attribute != "") { txtAttribute.Text = fireflyClicked.Attribute; txtAttribute.FontStyle = Windows.UI.Text.FontStyle.Normal; } else { txtAttribute.Text = "Not set!"; txtAttribute.FontStyle = Windows.UI.Text.FontStyle.Italic; } if (fireflyClicked.LastUpdateTime != new DateTime(0)) { tblLastUpdate.Text = fireflyClicked.LastUpdateTime.ToString(); tblLastUpdate.FontStyle = Windows.UI.Text.FontStyle.Normal; } else { tblLastUpdate.Text = "Unknown"; tblLastUpdate.FontStyle = Windows.UI.Text.FontStyle.Italic; } setLocationText(); }
// Shoot fireflies public void Fireflash() { // shoots 6 fireflies int angle_degree = 30; for (int i = 0; i < Constantes.N_LUCIOLES; i++) { // Instantiate firefly GameObject ffGO = (GameObject)Instantiate(fireflyPrefab, sourcePoint, Quaternion.Euler(new Vector3(0, 0, angle_degree))); ffGO.name = "firefly" + i.ToString(); Firefly ff = ffGO.GetComponent <Firefly>(); // Set intensity ff.intensity = this.power; // Set velocity float vx = Mathf.Cos(Mathf.Deg2Rad * angle_degree) * Mathf.Sqrt(3) / 2 / Constantes.TURN_DURATION; float vz = Mathf.Sin(Mathf.Deg2Rad * angle_degree) * Mathf.Sqrt(3) / 2 / Constantes.TURN_DURATION; ff.velocity = new Vector3(vx, 0, vz); // Let fly (or not yet) ff.WaveForward(); // select next angle angle_degree += 60; } }
void OnTriggerStay2D(Collider2D other) { MouseController m = other.GetComponent <MouseController>(); if (Input.GetKeyDown("f") && m != null) { foreach (string item in itemRequirements) { if (!inventory.hasItem(item)) { reqs = false; } } if (!inventory.held().Equals(heldReq) && heldReq != "") { reqs = false; } if (reqs) { inventory.itemAdded(itemName, gameObject); Firefly fly = GetComponent <Firefly>(); Firefly2 fly2 = GetComponent <Firefly2>(); if (fly != null) { fly.catchFly(); } if (fly2 != null) { fly2.catchFly(); } } reqs = true; } }
static void Main(string[] args) { string[] lines = File.ReadAllLines(InputFile); int testCaseCount = Int32.Parse(lines[0]); int currentLine = 1; File.WriteAllText(OutputFile, String.Empty); for (int i = 0; i < testCaseCount; ++i) { int fireflyCount = Int32.Parse(lines[currentLine++]); List <Firefly> fireflies = new List <Firefly>(); for (int j = 0; j < fireflyCount; ++j) { string[] split = lines[currentLine++].Split(); Firefly firefly = new Firefly(); firefly.X = Int32.Parse(split[0]); firefly.Y = Int32.Parse(split[1]); firefly.Z = Int32.Parse(split[2]); firefly.VX = Int32.Parse(split[3]); firefly.VY = Int32.Parse(split[4]); firefly.VZ = Int32.Parse(split[5]); fireflies.Add(firefly); } double distance, time; FindDistanceAndTime(fireflies, out distance, out time); File.AppendAllText( OutputFile, String.Format(CultureInfo.InvariantCulture, "Case #{0}: {1:0.00000000} {2:0.00000000}\n", i + 1, distance, time)); } }
public D1(Game game, Camera camera) : base(game, camera) { position = new Vector3(-391, 140, 345); yrotation = -MathHelper.PiOver2; type = TrialType.DRAGDROP; GEntity cage = new Cage(game, new Vector3(-476, 116, 326.5f), camera); cage.yrotation = MathHelper.Pi; cage.scale = 8; draggableList.Add(cage); for (int i = 0; i < fireflyLimit; i++) { GEntity firefly = new Firefly(game, new Vector3(-476, Game1.random.Next(ymin, ymax), Game1.random.Next(zmin, zmax)), camera); firefly.scale = 4; firefly.standardColor = i == 0 ? Color.Orange : Color.Yellow; firefly.selectedColor = Color.Red; selectableList.Add(firefly); } trialState = TrialState.INT; inTrialInstructions = "Select the orange firefly, and drag it into the cage."; Game1.wandCursor.DisplayingWithoutGesture = false; renderRequested = true; }
public void OnFireflyDestroyed(Firefly firefly) { fireflies.Remove(firefly); world.RemoveObject(firefly.gameObject); fireflyExists = false; Spawn(); }
public void UpdateFireflyLocation(string spaceName, Firefly firefly) { firefly.location = int.Parse(spaceName); ShowGridColor(firefly.GetColorName(), firefly.location); CheckForWin(); }
void Start() { //transform.parent.GetComponent<WorldPlayAudio>().play(); ff = GetComponent <Firefly>(); theta = 0; radius = 0; dt = 0; dr = 0; }
void OnTriggerExit(Collider other) { Firefly ffCol = other.gameObject.GetComponent <Firefly>(); if (ffCol != null) { // unregister entitesInTrigger.Remove(ffCol); } }
//Functions==================================================================== private double CalculateDistanceBetweenFireflies(Firefly firefly1, Firefly firefly2) { double distanceSum = 0; for (int i = 0; i < this.ranges.Count; i++) { distanceSum += Math.Pow(firefly1.Position.Axis.Values[i] - firefly2.Position.Axis.Values[i], 2); } return(Math.Sqrt(distanceSum)); }
private void addSampleFireflies() { Firefly firefly = new Firefly("123", "Thermometer 1"); fireflies.Add(firefly); firefly = new Firefly("456", "Air bed 2"); fireflies.Add(firefly); firefly = new Firefly("789", "Clipboard 3"); fireflies.Add(firefly); }
IEnumerator Spawn() { Firefly flyInstance = Instantiate(Fireflies[Random.Range(0, Fireflies.Length)], new Vector3(transform.position.x, transform.position.y + Random.Range(-2, 2)), Quaternion.identity); int power = Random.Range(2, 6); flyInstance.setup(power, transform.right); yield return(new WaitForSeconds(Random.Range(0, 6))); StartCoroutine(Spawn()); }
public void LoadEventInterface(object Target, EventArgs Args) { if (onUpdate != null) { Firefly.AddToUpdateList(this); } if (onLoad != null) { onLoad.Invoke(); } }
public void init() { wpa = transform.parent.GetComponent <WorldPlayAudio>(); collected = false; ff = GetComponent <Firefly>(); ff.color = Color.green; theta = Random.Range(0, Mathf.PI * 2); radius = Random.Range(minR, maxR); dt = getRandomBand(1, maxSpeed); dr = getRandomBand(1, maxSpeed); }
public override void OnInspectorGUI() { Firefly t = (Firefly)target; t.size = EditorGUILayout.FloatField("Size", t.size); t.color = EditorGUILayout.ColorField("Color", t.color); if (GUI.changed) { EditorUtility.SetDirty(target); } }
private void OnTriggerEnter2D(Collider2D collision) { Firefly b = collision.GetComponent <Firefly>(); if (b) { if (list[1].Contains(b)) { list[1].Remove(b); } } }
private void OnTriggerExit2D(Collider2D collision) { Firefly b = collision.GetComponent <Firefly>(); if (b) { if (!list[1].Contains(b) && list[0].Contains(b)) { list[1].Add(b); } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.F)) { if (Time.time - timer > CD) { Firefly temp = GameObject.Instantiate <Firefly>(Firefly); temp.gameObject.transform.position = Player.LoadObj.transform.position; temp.Rbody2D.AddForce(new Vector2(Force.x * (Player.isfacingright() ? 1 : -1), Force.y)); timer = Time.time; } } }
public override Value Invoke(List Arguments) { var list = Arguments.GetValues(); if (list[0] is Function) { onLoad = list[0] as Function; } if (list[1] is Function) { onUpdate = list[1] as Function; } Firefly.Initialize(800, 500, "Firefly Window", LoadEventInterface, true); return(this); }
public override Value Invoke(List Arguments) { Shape = new ColoredShape(); Firefly.AddToRenderList(Shape); FilledPoly = new Array(); OutlinePoly = new Array(); Identifiers["FilledPolygons"] = new Reference(FilledPoly); Identifiers["OutlinePolygons"] = new Reference(OutlinePoly); Identifiers["SetPolygons"] = new Reference(new ExternalFunction("SetPolygons", false, SetPolygons)); Identifiers["X"] = new Reference(new ExternalProperty("X", false, XChange, () => new Number(Shape.X))); Identifiers["Y"] = new Reference(new ExternalProperty("Y", false, YChange, () => new Number(Shape.Y))); Identifiers["Rotation"] = new Reference(new ExternalProperty("Rotation", false, X => Shape.Rotation = (float)((Number)X).Val, () => new Number(Shape.Rotation))); return(this); }
void OnTriggerEnter(Collider other) { Firefly ffCol = other.gameObject.GetComponent <Firefly>(); if (ffCol != null) { int age = other.GetComponent <Firefly>().age; this.ageShown = GameManager.time - age; // Register entitesInTrigger.Add(ffCol); ffCol.OnDestroy += () => entitesInTrigger.Remove(ffCol); } }
public async void putFireflyAttribute(Firefly fireflyToUpate) { // PUT data Uri uri = new Uri(monitorUri + "firefly/" + fireflyToUpate.Id); string usrData = "attribute=" + fireflyToUpate.Attribute; // Http PUT Request HttpStringContent content = new HttpStringContent(usrData, UnicodeEncoding.Utf8, CURL_MEDIA_TYPE); HttpResponseMessage response = await client.PutAsync(uri, content); if (response.IsSuccessStatusCode) // Success { Debug.WriteLine("Info: Put Success: " + fireflyToUpate.Id); } else { Debug.WriteLine("Error: Put Fail: " + fireflyToUpate.Id); } }
private void Init() { const int FirefliesCount = 100; Random Randomer = new Random(); for (int i = 0; i < FirefliesCount; ++i) { Firefly CurrentFirefly = new Firefly(); CurrentFirefly.Speed = Randomer.Next(1, 3); CurrentFirefly.Body = new Ellipse(); CurrentFirefly.Body.Margin = new Thickness(Randomer.Next(10, (int)MainCanvas.ActualWidth - 10), Randomer.Next(10, (int)MainCanvas.ActualHeight - 10), 0, 0); CurrentFirefly.Body.Fill = Brushes.Black; CurrentFirefly.Body.Height = MainCanvas.ActualHeight / 4; CurrentFirefly.Body.Width = 1.5 * CurrentFirefly.Body.Height; MainCanvas.Children.Add(CurrentFirefly.Body); } }
public void Test() { Firefly fire = new Firefly(); IOptiTestFunc f = new Weierstrass(); fire.dimension = 10; fire.searchSpace = f.SearchSpace; double[] res = fire.Opti(f.Func); double val = f.Func(res); Assert.AreEqual(f.MinimumValue, val, 5); fire = new Firefly(); f = new SumSquares(); fire.dimension = 10; fire.searchSpace = f.SearchSpace; res = fire.Opti(f.Func); val = f.Func(res); Assert.AreEqual(f.MinimumValue, val, 5); }
// Update is called once per frame void Update() { Firefly nearest = fireflyManager.GetNearest(); bool exist = (nearest != null); arrow.gameObject.SetActive(exist); if (!exist) { return; } Vector3 dir = nearest.transform.position - player.transform.position; float _r = Mathf.Atan2(dir.y, dir.x); float _d = (_r / Mathf.PI) * 180; arrow.transform.eulerAngles = new Vector3(0, 0, _d); }
//Only active on the birthday day, send a message at 9:00 private void OnTimeChanged(object sender, TimeChangedEventArgs e) { // Message at 9:00 if (e.NewTime == 900) { //Send a message to all Game1.addHUDMessage(new HUDMessage("Birthday celebration has started in town!", 1)); // Flag to check if the birthday has been started this.alreadyStarted = true; } // Birthday at 9:10 if (e.NewTime == 910) { this.StartBirthdayEvent(); } // Add fireflies around the NPC every 30 minutes if (alreadyStarted && every30Minutes % 3 == 0) { Random rnd = new Random(); for (int i = 0; i < 50; i++) { Firefly f = new Firefly(new Vector2(rnd.Next((int)(npcPosition.X - 15), (int)(npcPosition.X + 15)), rnd.Next((int)(npcPosition.Y - 15), (int)(npcPosition.Y + 15)))); Game1.getLocationFromName("Town").addCritter(f); } } every30Minutes += 1; //Debug GameLocation location = Game1.currentLocation; int playerX = (int)Math.Floor(Game1.player.Position.X / Game1.tileSize); int playerY = (int)Math.Floor(Game1.player.Position.Y / Game1.tileSize); this.Monitor.Log($"Player at ({playerX}, {playerY}) name {location.Name}", LogLevel.Info); }
public void Spawn() { if (fireflyExists) { return; } float randomXOffset = Random.Range(player.lightVicinity + 5, 40); bool randomBool = (Random.value < 0.5); if (randomBool) { randomXOffset *= -1; } float posX = player.transform.position.x + randomXOffset; float minPosY = world.groundMinY; float maxPosY = world.groundMaxY; float posY = Random.Range(minPosY, maxPosY); Vector3 spawnPosition = new Vector3(posX, posY, 0); // Makes sure that firefly is not spawned inside lit area if (Vector3.Distance(spawnPosition, player.transform.position) < player.lightVicinity) { Spawn(); } Firefly newFirefly = Instantiate(firefly, spawnPosition, Quaternion.identity); newFirefly.fireflyManager = this; newFirefly.transform.parent = world.transform; fireflies.Add(newFirefly); world.AddObject(newFirefly.gameObject); fireflyExists = true; }
public double[] search() { Firefly[] firefly = new Firefly [B]; for (int i = 0; i < B; i++) { firefly[i].point = new Point(argCnt); } Firefly best = new Firefly(); for(int i = 0; i < B; i++) { firefly[i] = getRandomFirefly(); } for(int iter = 0; iter < iterMax; iter++) { for(int i = 0; i < B; i++) { for (int j = 0; j < B; j++) { if (firefly[j].intensity > firefly[i].intensity) { moveFirefly(ref firefly[i], ref firefly[j]); firefly[i].intensity = getIntensity(firefly[i].point); } } } best = firefly[0]; for(int i = 0; i < B; i++) { if (firefly[i].intensity > best.intensity) { best = firefly[i]; } } } return best.point.x; }
void Start() { score = 0; ff = GetComponent <Firefly>(); updateSize(); }
private void moveFirefly(ref Firefly a, ref Firefly b) { double dist2 = getDestination2(a, b); double currRand = rand.NextDouble(); for (int i = 0; i < argCnt; i++) { a.point[i] += beta0 * Math.Exp(-gamma * dist2) * (b.point[i] - a.point[i]) + alpha * (currRand - 0.5); } checkRange(ref a); }
private Firefly getRandomFirefly() { Firefly tmp = new Firefly(argCnt); for (int i = 0; i < argCnt; i++) { tmp.point[i] = rand.NextDouble() * (rangeMax[i] - rangeMin[i]) + rangeMin[i]; } tmp.intensity = getIntensity(tmp.point); return tmp; }
private void Player_Warped(object sender, StardewModdingAPI.Events.WarpedEventArgs e) { _RemoveGoblinNose(); _gettingKickedOut = false; // If we registered the weird light update, just remove it if we warp. if (e.IsLocalPlayer && _registeredUpdate) { Helper.Events.GameLoop.UpdateTicking -= UpdateWeirdLights; setGoblinNosePosition = null; _registeredUpdate = false; } if (e.IsLocalPlayer && e.NewLocation != null && e.NewLocation.Name.Equals("Sewer") && IsShadowFestivalToday() ) { setGoblinNosePosition += SetGoblinNosePosition; // Setup the Sewer Map for us if (e.Player.mailReceived.Contains("ShadowFestivalVisited")) { e.Player.mailReceived.Add("ShadowFestivalVisited"); } Helper.Reflection.GetField <Color>(e.NewLocation, "steamColor").SetValue(new Color(240, 180, 240)); // Repatch the two tiles that Sewers.resetLocalState() changes on us. // Beware if that part of our map is edited, we need to manually change these here too. e.NewLocation.setMapTileIndex(31, 16, 77, "Front", 1); e.NewLocation.setMapTileIndex(31, 17, 85, "Buildings", 1); e.NewLocation.setTileProperty(31, 17, "Buildings", "Action", "FestivalDialogue BigShadow"); // Check for Krobus and make him scarce if (e.NewLocation.characters != null) { foreach (NPC npc in e.NewLocation.characters) { if (npc.Name == "Krobus") { npc.setTilePosition(3, 20); break; } } } // Let's add critters. Start with a frog along the entry hall List <Critter> critters = Helper.Reflection.GetField <List <Critter> >(e.NewLocation, "critters").GetValue(); if (critters == null) { Helper.Reflection.GetField <List <Critter> >(e.NewLocation, "critters").SetValue(new List <Critter>()); } e.NewLocation.addCritter(new Frog(new Vector2(4, ModEntry.Random.Next(26, 31)), true, false)); e.NewLocation.addCritter(new Frog(new Vector2(15, 26), true, true)); e.NewLocation.addCritter(new Frog(new Vector2(18, 27), true, false)); // Add a bunch of fireflies. for (int i = 0; i < 60; i++) { Firefly firefly = new Firefly(new Vector2(ModEntry.Random.Next(3, 34), ModEntry.Random.Next(10, 44))); // These fireflies have weird colors. var light_source = Helper.Reflection.GetField <LightSource>(firefly, "light"); int color = ModEntry.Random.Next(0, 3); if (color == 0) { light_source.GetValue().color.Value = new Color(0, 0, 255); } else if (color == 1) { light_source.GetValue().color.Value = new Color(0, 255, 0); } else if (color == 2) { light_source.GetValue().color.Value = new Color(255, 0, 0); } light_source.GetValue().radius.Value = 0.75F; e.NewLocation.addCritter(firefly); } _weirdLights.Clear(); // Set up the lights in the scene. for (int x = 0; x < e.NewLocation.Map.Layers[0].LayerWidth; x++) { for (int y = 0; y < e.NewLocation.Map.Layers[0].LayerHeight; y++) { xTile.Tiles.Tile tile = e.NewLocation.Map.GetLayer("Front").Tiles[x, y]; xTile.Tiles.Tile tile_2 = e.NewLocation.Map.GetLayer("AlwaysFront").Tiles[x, y]; // Weird lamp things. if ((tile != null && tile.TileIndex == 122 && tile.TileSheet.Id == "Spirit_Sewer") || (tile_2 != null && tile_2.TileIndex == 122 && tile_2.TileSheet.Id == "Spirit_Sewer")) { AddWeirdLight(e.NewLocation, x, y); } // Weird hanging lights (Left) if ((tile != null && tile.TileIndex == 65 && tile.TileSheet.Id == "Spirit_Sewer") || (tile_2 != null && tile_2.TileIndex == 65 && tile_2.TileSheet.Id == "Spirit_Sewer")) { Game1.currentLightSources.Add(new LightSource(1, new Vector2((x + 0.5F) * Game1.tileSize, (y + 0.5F) * Game1.tileSize), 0.25F, new Color(255, 255, 255))); } // Middle if ((tile != null && tile.TileIndex == 66 && tile.TileSheet.Id == "Spirit_Sewer") || (tile_2 != null && tile_2.TileIndex == 66 && tile_2.TileSheet.Id == "Spirit_Sewer")) { Game1.currentLightSources.Add(new LightSource(6, new Vector2((x + 0.5F) * Game1.tileSize, (y + 0.75F) * Game1.tileSize), 0.5F, new Color(255, 10, 255))); } // Right if ((tile != null && tile.TileIndex == 67 && tile.TileSheet.Id == "Spirit_Sewer") || (tile_2 != null && tile_2.TileIndex == 67 && tile_2.TileSheet.Id == "Spirit_Sewer")) { Game1.currentLightSources.Add(new LightSource(1, new Vector2((x + 0.5F) * Game1.tileSize, (y + 0.5F) * Game1.tileSize), 0.25F, new Color(255, 10, 10))); } } } Game1.changeMusicTrack("WizardSong"); // The Sewers class overrides the lighting, so override it again. Game1.ambientLight = new Color(190, 190, 150); // Register the weird light update. This causes those weird lights to kind of pulse. Helper.Events.GameLoop.UpdateTicking += UpdateWeirdLights; _registeredUpdate = true; } }
private void checkRange(ref Firefly a) { for (int i = 0; i < argCnt; i++) { a.point[i] = (a.point[i] < rangeMin[i]) ? rangeMin[i] : a.point[i]; a.point[i] = (a.point[i] > rangeMax[i]) ? rangeMax[i] : a.point[i]; } return; }
double getDestination2(Firefly a, Firefly b) { double d = 0; for (int i = 0; i < argCnt; i++) { d += (a.point[i] - b.point[i]) * (a.point[i] - b.point[i]); } return d; }