/// <summary> /// there are four steps for the server /// (1) read xml to get necessary information /// (2)initalize a new world and add info to the new world /// (3)uisng serverawaitClientloop to awit client join in /// (4)using update method to send update info to the client /// </summary> /// <param name="args"></param> static void Main(string[] args) { xmlRead(); watch = new Stopwatch(); list = new LinkedList <SocketState>(); watch.Start(); liveStar = new Stopwatch(); liveStar.Start(); theworld = new world(); sta.setLoc(new Vector2D(200, -200)); star ss = new star(1, new Vector2D(200, 200), 0.01); theworld.addStar(sta); theworld.addStar(ss); theworld.setSize(UniverSize); theworld.setRespawn(RespawnRate); theworld.setFrame(MSperFrame); NController.ServerAwaitClientLoop(HandleNewClient); Console.WriteLine("our server start, and client could join in now"); //create a new thread to update the world and send the updated info to the client Task task = new Task(() => { while (true) { update(); } }); task.Start(); Console.Read(); }
/// <summary> /// Fires the projectile in a line from the ship, straight. /// </summary> /// <param name="proj"></param> private void updateProjectileLocation(projectile proj, star starry) { if (bulletGravity == false) { Vector2D direction = proj.GetDirections(); // We have the direction direction *= projectileSpeed; proj.loc = proj.loc + direction;// Apply new velocity to position. checkIfOffScreen(proj, touhouMode); } else { Vector2D gravity = starry.loc - proj.loc; // Find the vector from the ship to the star. gravity.Normalize(); // Turn the vector into a unit-length direction by normalizing. gravity *= starry.mass; // Adjust strentth of vector by multiplying star's mass. Vector2D thrust = new Vector2D(0, 0); // no thrust for you. Vector2D acceleration = gravity + thrust; // combine all forces. proj.velocity += acceleration; // Add acceleration to velocity. proj.loc = proj.loc + proj.velocity; // Apply new velocity to position. checkIfOffScreen(proj, touhouMode); // Wraparound if offscreen. } }
//button listener public void clickStar(star star) { if (currentlySelected == star) { currentlySelected.setNormal(); currentlySelected = null; } //if currently selecting a star else if (currentlySelected != null) { if (currentlySelected.connectedTo.Contains(star)) { return; } //connect two stars; connect(currentlySelected, star); //make both uninteractable; // currentlySelected.GetComponent<Button>().interactable = false; // star.GetComponent<Button>().interactable = false; //set animator to connected; set currentlySelected = null currentlySelected.setConnected(star); star.setConnected(currentlySelected); currentlySelected = null; } else { //else, currentlySelected = star currentlySelected = star; currentlySelected.animator.SetTrigger("Pressed"); } }
public static void initStars() { for (var i = 0; i < sc; i++) { stars[i] = new star(JLib.rollDice(50) - 25, JLib.rollDice(50) - 25, JLib.rollDice(31)); } }
/// <summary> /// Uses vector math to update the ship's location. /// </summary> /// <param name="shippyUpdate">Ship to be updated.</param> /// <param name="starry">star for gravity</param> private void updateShipLocation(ship shippyUpdate, star starry) { Vector2D gravity = starry.loc - shippyUpdate.loc; // Find the vector from the ship to the star. gravity.Normalize(); // Turn the vector into a unit-length direction by normalizing. gravity *= starry.mass; // Adjust strentth of vector by multiplying star's mass. Vector2D thrust; //We need to only do this thrus if the ship is thrusting, otherwise the star will only have the impact on the ship if (shippyUpdate.getThrust() == true) { thrust = shippyUpdate.GetDirections(); // So long as rotate is only ever applied, should always be normalized. thrust = thrust * (engineStrength); // Adjust the length of the vector by multiplying by the engine strength. shippyUpdate.setThrust(false); } else { thrust = new Vector2D(0, 0); // no thrust for you. } Vector2D acceleration = gravity + thrust; // combine all forces. shippyUpdate.velocity += acceleration; // Add acceleration to velocity. shippyUpdate.loc = shippyUpdate.loc + shippyUpdate.velocity; // Apply new velocity to position. checkIfOffScreen(shippyUpdate); // Wraparound if offscreen. }
float starscore(star s) { Vector3 v = s.vec - loc; v /= v.magnitude; return(-Vector3.Dot(v, vector)); }
/// <summary> /// Adds a star to the game world. /// </summary> /// <param name="size"></param> /// <param name="xLocation"></param> /// <param name="yLocation"></param> public void addStar(double size, int xLocation, int yLocation) { star st = new star(size, xLocation, yLocation, starsInWorld.Count); starsInWorld.Add(countOfStart, st); countOfStart++; }
private static string majorElement(star canidate, HashSet <star> stars) { int i = 0; int c = 0; int k = stars.Count; if (canidate == null) { return("No"); } else { foreach (star el in stars) { if (canidate.distanceSQRD(el) <= distanceSQRD) { c++; } else { i++; } } if (c > k / 2) { return(c.ToString()); } else { return("No"); } } }
public bool checkLines(star one, star two) { foreach (line check in lines) { if ((check.one == one && check.two == two) || (check.one == two && check.two == one)) { if (check.isActive == false) { countToComplete++; //check if all are completed if (countToComplete == completionCount) { isComplete = true; ((constalationHolder)this.transform.parent.GetComponent(typeof(constalationHolder))).completedConstalation(); endImage.enabled = true; PlayerPrefs.SetInt(Application.loadedLevelName.ToString() + this.name.ToString(), 1); this.audio.Play(); } ((LineRenderer)check.GetComponent(typeof(LineRenderer))).enabled = true; check.isActive = true; return(true); } } } if (isComplete == false && isHardMode == true) { clearLines(); return(false); } return(false); }
protected override void LoadContent() { rand = new Random(); spriteBatch = new SpriteBatch(GraphicsDevice); star = Content.Load <Texture2D>("Bitmap1"); STAR = new star(rand, star); }
public void TestProjectileMethod() { world world1 = new world(); projectile p = new projectile(0, new Vector2D(0, 0), new Vector2D(0, 0), true, 1); star s = new star(0, new Vector2D(0, 0), 1); world1.addStar(s); String A = p.ToString(); projectile s1 = JsonConvert.DeserializeObject <projectile>(A); world1.setFrame(50); world1.setRespawn(300); world1.setSize(750); world1.update(); Assert.AreEqual(p.getID(), 0); Assert.AreEqual(new Vector2D(0, 0), p.getloc()); Assert.AreEqual(new Vector2D(0, 0), p.getdir()); Assert.AreEqual(p.checkAlive(), true); Assert.AreEqual(p.getOwner(), 1); p = new projectile(0, new Vector2D(0, 0), new Vector2D(0, 0), true, 1); p.update(750, world1.getStar().Values); p.die(); projectile p1 = new projectile(1, new Vector2D(0, 376), new Vector2D(0, 0), true, 2); p1.update(750, world1.getStar().Values); }
/* * public void read_csv(string path) { * var starlist = new System.Collections.Generic.List<star>(); * path = Path.Combine(path, "star\\star.csv"); * using(var sr = new StreamReader(new FileStream(path, System.IO.FileMode.Open))) { * string line; * line = sr.ReadLine(); * if(line != EXPECTED_LINE) * throw new Exception("wrong first line"); * while((line = sr.ReadLine()) != null) { * star s = new star(line); * starlist.Add(s); * } * } * stars = starlist.ToArray(); * Debug.Log(String.Format("{0} stars", starlist.Count)); * } */ public void read_dat(string path) { var starlist = new System.Collections.Generic.List <star>(); string path1 = Path.Combine(path, "star\\star.dat"); string path2 = Path.Combine(path, "star\\star.string"); FileStream fs = File.OpenRead(path2); var unicodeencode = new System.Text.UTF8Encoding(); Func <UInt32, UInt32, string> getstring = delegate(UInt32 offset, UInt32 length) { fs.Seek(offset, SeekOrigin.Begin); byte[] str = new byte[length]; fs.Read(str, 0, checked ((int)length)); return(unicodeencode.GetString(str)); }; using (var br = new BinaryReader(new FileStream(path1, System.IO.FileMode.Open))) { try { while (true) { star s = star.makestar(br, getstring); starlist.Add(s); GameDad.starprogress++; } } catch (EndOfStreamException) {} } stars = starlist.ToArray(); Debug.Log(String.Format("{0} stars", starlist.Count)); }
public Unifiable GetStarContent_S() { XmlNode starNode = getNode("<star/>"); star recursiveStar = new star(this.bot, this.user, this.query, this.request, this.result, starNode); return(((TextTransformer)recursiveStar).Transform()); }
/// <summary> /// drawing the star /// </summary> /// <param name="o"></param> /// <param name="e"></param> private void drawStar(object o, PaintEventArgs e) { int starWidth = 35; star s = o as star; Image image = Image.FromFile("../../../Resources/Images/star.jpg"); e.Graphics.DrawImage(image, 0 - (starWidth / 2), 0 - (starWidth / 2), starWidth + 5, starWidth + 5); }
void InitStars() { for (int loop = 0; loop < num; loop++) { var nc = Color.FromArgb(rng.Next() % 256, rng.Next() % 256, rng.Next() % 256); stars [loop] = new star(nc, ((float)loop / num) * 5, 0); } }
private void DrawStar(star star) { float starsize = Map(star.Z, 0, pictureBox1.Width, 5, 0); float X = Map(star.X / star.Z, 0, 1, 0, pictureBox1.Width) + pictureBox1.Width / 2; float Y = Map(star.Y / star.Z, 0, 1, 0, pictureBox1.Height) + pictureBox1.Height / 2; graphics.FillEllipse(Brushes.WhiteSmoke, X, Y, starsize, starsize); }
private void starDrawer(object o, PaintEventArgs e) { star oStar = o as star; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Image i = overarchingImages[8][0]; // [8][0] is the constant location of the sun image. Won't change. e.Graphics.DrawImage(i, i.Width / -8, i.Height / -8, i.Width / 4, i.Height / 4); // And blits the image. }
static void Main(string[] args) { bassisclass myBasisClass = new bassisclass(); mushroom myMushroom = new mushroom(); star myStar = new star(); banana myBanana = new banana(); myStar.onHit(); myMushroom.boost(); myBanana.slippery(); }
private void MoveStar(star star) { star.Z -= 2; if (star.Z < 1) { star.X = random.Next(-pictureBox1.Width, pictureBox1.Width); star.Y = random.Next(-pictureBox1.Height, pictureBox1.Height); star.Z = random.Next(1, pictureBox1.Width); } }
public void starMass() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); star sh = new star(5.0, 8, 8, 1); Assert.AreEqual(5.0, sh.mass); }
public void starYLocation() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); star sh = new star(5.0, 8, 8, 1); Assert.AreEqual(8, sh.loc.GetY()); }
private void connect(star one, star two) { UILineRenderer line = lines[0]; line.Points = new Vector2[] { one.RectTransform.anchoredPosition, two.RectTransform.anchoredPosition }; line.gameObject.SetActive(true); lines.RemoveAt(0); if (lines.Count == 0) { Done(); } }
public void TestStarMethod() { world world1 = new world(); star s = new star(0, new Vector2D(200, 200), 1); world1.addStar(s); world1.setFrame(50); world1.setRespawn(300); world1.setSize(750); world1.update(); s.update(51); s.update(102); s.update(160); s.update(230); }
ParticleSystem.Particle get_particle_from_star(star st) { float lum = Mathf.Exp(-st.absmag / 5 * Mathf.Log(100)); lum = Mathf.Pow(lum, 1f / 4); /* Ballesteros' formula (from Wikipedia) */ double T = 4600 * (1 / (0.92 * st.ci + 1.7) + 1 / (0.92 * st.ci + 0.62)); Color temp = Mathf.CorrelatedColorTemperatureToRGB((float)T); return(new ParticleSystem.Particle { position = star_to_position_in_particle_reference_frame(st), startLifetime = Mathf.Infinity, startSize = Mathf.Max(st.part_of_group? 0.001f: 0.003f, 0.02f * lum), //startSize = Mathf.Max(0.002f, 0.004f * Mathf.Sqrt(star.radius)), startColor = temp }); }
public void TestShipMethod() { world world1 = new world(); star s = new star(0, new Vector2D(200, 200), 1); world1.addStar(s); world1.setFrame(50); world1.setRespawn(300); world1.setSize(750); Ship ship = world1.generateShip("ship"); ship.hpdecrease(); Assert.AreEqual(ship.getHp(), 4); ship.getDeath(); Assert.AreEqual(ship.getDeath(), 0); }
void init_star(out star star) { int sx = (int)(theWidth * .7); int sy = (int)(theHeight * .7); float x = (float)(RandomClass.Next(sx)); float y = (float)(RandomClass.Next(sy)); star.xpos = (float)(Math.Cos(x) * y * 2500); star.ypos = (float)(Math.Sin(x) * y * 2500); star.zpos = RandomClass.Next(80, 160) << 6; star.speed = RandomClass.Next(5, 15); star.color = Color.FromArgb(RandomClass.Next(255), RandomClass.Next(255), 255); star.bright = .001; }
public IEnumerable <int> stars_near_vec(Vector3 th, float dist) { int ns = nstars(); for (int j = 0; j < ns; j++) { star s = getstar(j); if (s.part_of_group) { continue; } if (Vector3.Distance(s.vec, th) < dist) { yield return(j); } } }
public void TestStar1Method() { world world1 = new world(); star s = new star(0, new Vector2D(0, -200), 1); s.setLoc(new Vector2D(0, 0)); Assert.AreEqual(new Vector2D(0, 0), s.getloc()); world1.addStar(s); world1.setFrame(50); world1.setRespawn(300); world1.setSize(750); world1.update(); s.update(51); s.update(102); s.update(160); s.update(230); }
public redstar_organizer(int star, Vector3 _vector) { candidates = new SortedDictionary <float, int>(); starmap sm = GameDad.manystars; loc = sm.getstar(star).vec; vector = _vector; foreach (var ix in sm.stars_near_vec(loc, 4f)) { if (ix == star) { continue; } star s = sm.getstar(ix); candidates[starscore(s)] = ix; } }
public void TestStar2Method() { world world1 = new world(); star s = new star(0, new Vector2D(0, 200), 1); String A = s.ToString(); star s1 = JsonConvert.DeserializeObject <star>(A); world1.addStar(s); world1.setFrame(50); world1.setRespawn(300); world1.setSize(750); world1.update(); s.update(51); s.update(102); s.update(160); s.update(230); }
void InitStars () { for (int loop = 0; loop < num; loop++) { var nc = Color.FromArgb (rng.Next () % 256, rng.Next () % 256, rng.Next () % 256); stars [loop] = new star (nc, ((float)loop / num) * 5, 0); } }