public List<ZPoint.Direction> Path(ZPoint start, ZPoint finish, LocalObject t = null) { List<FramedZPoint> visited = new List<FramedZPoint>(); visited.Add(new FramedZPoint(finish, true)); while (!start.IsIn(visited)) { List<FramedZPoint> frontier = (from p in visited where p.onFrontier orderby MyMath.ManhattanDistance(p.data, start) select p) .Cast<FramedZPoint>().ToList(); if (frontier.Count() == 0) return null; foreach (FramedZPoint p in frontier) { p.onFrontier = false; foreach (ZPoint.Direction d in ZPoint.Directions) AddToFrontier(visited, p.data.Shift(d), ZPoint.Opposite(d), start, t); } } List<ZPoint.Direction> result = new List<ZPoint.Direction>(); ZPoint position = start; while (!position.TheSameAs(finish)) { ZPoint.Direction d = position.GetDirection(visited); result.Add(d); position = position.Shift(d); } return result; }
public override bool Contrainte(ZPoint p) { if (base.Contrainte(p) && !_interdit.Contains(p)) { /*Unit ghostUnit = new Unit(_units.Last());//On crée une unité fantome c'est à dire une unité qui n'est pas vraiment * //sur la map, on vérifie si elle n'existe pas * ghostUnit._position = new Vector2(p._x + _posStart, p._y);//On lui donne la position du point à tester * * if(_units.Contains(ghostUnit))//on test si l'unité fantome existe * { * //si oui l'unité ne peut marcher sur une autre unité * _interdit.Add(p); * return false; * }*/ if (_map.getGid(p._x, p._y) == 0 && p.Distance(_depart, _ecart) <= _rayon) { return(true); } else { _interdit.Add(p); return(false); } } return(false); }
public void Draw() { if (MyGame.Instance.dialog == false) return; screen.Fill(new Color(0.2f, 0.2f, 0.2f, 0.9f)); screen.Draw(dialog.texture, new ZPoint(8, 8)); screen.offset = 8; SpriteFont font = MainScreen.Instance.fonts.verdana; screen.DrawString(font, dialogNode.text, new ZPoint(48, screen.offset), Color.White, screen.size.x - 48); screen.DrawString(font, dialogNode.description, new ZPoint(48, screen.offset), Color.Gray, screen.size.x - 48); screen.offset = 80; for (int i = 0; i < dialogNode.responses.Count; i++) { DialogResponse r = dialogNode.responses[i]; ZPoint p = new ZPoint(8, screen.offset); MouseTriggerKeyword.Set("dialog", (i + 1).ToString(), screen.position + p, new ZPoint(font.MeasureString(r.text)) + new ZPoint(20, 0)); var mtk = MouseTrigger.GetUnderMouse<MouseTriggerKeyword>(); Color color = Color.White; if (mtk != null && mtk.name == "dialog" && mtk.parameter == (i + 1).ToString()) color = Color.DodgerBlue; screen.DrawString(font, (i + 1) + ". " + r.text, p, color, screen.size.x - 20); } }
private void DrawBarter(ZPoint position) { toSell.Draw(position); toBuy.Draw(position + new ZPoint(32 * 12 + 16, 0)); barter.inventory.Draw(position + new ZPoint(32 * 24 + 24, 0)); M.DrawRectangle(position + new ZPoint(32 * 31, 0), new ZPoint(32, 32), Stuff.MyColor("Very Dark Grey")); M.Draw(barter.dialog.texture, position + new ZPoint(32 * 31, 0)); MouseTriggerKeyword.Set("trade", position + new ZPoint(0, 40), new ZPoint(32 * 24 + 16, 16)); var mtk = MouseTriggerKeyword.GetUnderMouse("trade"); float loss = toBuy.Value * 2 - toSell.Value * (1 + 0.25f * Max(Skill.Get("Speech"))); Color color = loss < 0 ? mtk != null ? Stuff.MyColor("Light Blue") : Color.Green : Color.Red; M.DrawRectangle(position + new ZPoint(32 * 12 + 7, 0), new ZPoint(2, 56), color); M.DrawRectangle(position + new ZPoint(32 * 12 + 8, 40), new ZPoint((int)(loss), 16), color); if (mtk != null && G.LeftMouseButtonClicked) { List<Item> list = new List<Item>(); foreach (Item item in toSell.Items) list.Add(item); toSell.Clear(); foreach (Item item in toBuy.Items) toSell.Add(item); toBuy.Clear(); foreach (Item item in list) toBuy.Add(item); } }
public void Draw(Screen screen, ZPoint position) { Func<int, ZPoint> aPosition = k => screen.position + position + new ZPoint(48 * k, 0); ZPoint aSize = new ZPoint(48, 48); for (int n = 0; n < 6; n++) MouseTriggerKeyword.Set("ability", n.ToString(), aPosition(n), aSize); var mtk = MouseTriggerKeyword.GetUnderMouse("ability"); int i = 0; foreach (ClassAbility a in list) { bool mouseOn = mtk != null && mtk.parameter == i.ToString(); bool has = Has(a); bool levelup = t.xp != null && t.xp.AbilityPoints > 0; bool passive = a.targetType == Ability.TargetType.Passive; if (has || levelup) { M.Draw(a.texture, aPosition(i), mouseOn ? a.color : Color.White); if (passive || cooldowns[a] > 0) M.DrawRectangle(aPosition(i), aSize, new Color(0, 0, 0, 0.7f)); if (t == B.current && !passive) M.DrawStringWithShading(M.fonts.small, cooldowns[a] > 0 ? "(" + (int)cooldowns[a] + ")" : Stuff.AbilityHotkeys[i].ToString(), aPosition(i), Color.White); if (mouseOn) a.DrawDescription(screen.position + position + new ZPoint(24, 56)); } if (!has && levelup) M.Draw(NamedTexture.Get("other/plus"), aPosition(i)); i++; } }
public ZPoint GetCursorPosition() { ZPoint p = null; Dispatcher.Invoke(new Action(delegate { p = new ZPoint(_cursorX, _cursorY); })); return(p); }
private List <ZPoint> _interdit;//list contenant les bord de la zone public ZoneDeplacement(Texture2D texture, ZEcart ecart, ZTaille taille, ZPoint depart, Map map, int posStart, int rayon) : base(ecart, taille, depart) { _texture = texture; _map = map; _rayon = rayon; _posStart = posStart; _depart = depart; _interdit = new List <ZPoint>(); GetGroupe(depart); }
public void Draw(Texture2D texture, RPoint rPosition, float scaling, Color color) { if (scaling == 1.0f) Draw(texture, rPosition, color); else { int width = (int)(scaling * texture.Width); int height = (int)(scaling * texture.Height); ZPoint center = new ZPoint(GraphicCoordinates(rPosition)) + new ZPoint(16, 32 - height / 2); M.spriteBatch.Draw(texture, new Rectangle(center.x - width/2, center.y - height/2, width, height), color); } }
public void Animate(ZPoint p, float gameTime) { if (t.p.Range == 1) { Vector2 v = p - t.p.value; v.Normalize(); v *= 0.5f; B.combatAnimations.Add(new RMove(t.p.r, v, 0.5f * gameTime)); B.combatAnimations.Add(new RMove(t.p.r, -v, 0.5f * gameTime)); } else B.combatAnimations.Add(new TextureAnimation(NamedTexture.Get("local/arrow"), t.p.GC, Battlefield.GC(p), gameTime)); }
public void MoveOrAttack(ZPoint.Direction d, bool control) { LocalObject o = B.Get(t.p.value.Shift(d)); if (o != null && !o.p.IsWalkable) { if (o.shape != null && o.shape.data.name == "Chest" && t.skills != null && t.skills["Mechanisms"] > 0) { foreach (Item item in o.inventory.Items) B.Add(new LocalObject(item), o.p.value); B.Remove(o); } else if (o.hp != null && t.attack != null) t.attack.Execute(o); } else t.movement.Move(d, control); }
public void Move(ZPoint.Direction d, bool control) { ZPoint destination = t.p.value.Shift(d); if (CanMove && B.IsWalkable(destination, t)) t.p.Set(destination, Time, true); else AnimateFailedMovement(d); t.RemoveEffect("Melded", "Fake Death"); if (control == true && t.initiative.movementCounter > 0) { t.initiative.movementCounter--; t.initiative.ContinueTurn(Time); } else t.initiative.PassTurn(Time); }
bool DFSAddLine(ZPoint p1, ZPoint p2) { ZPoint temp = p1; circlePoint.Push(temp); while (circlePoint.Count != 0) { temp = circlePoint.Peek(); int d = 0; while (d < temp.lines.Count) { if (temp.lines[d].GetComponent <ZLine>().enabled == true) { if (temp.lines[d].GetComponent <ZLine>().isUse == false) { temp.lines[d].GetComponent <ZLine>().isUse = true; foreach (ZPoint p in temp.lines[d].GetComponent <ZLine>().points) { if (p != temp) { temp = p; circlePoint.Push(temp); break; } } if (temp == p2) { return(true); } else { d = 0; } } else { d++; } } else { d++; } } circlePoint.Pop(); } return(false); }
public void DrawRectangle(ZPoint p, ZPoint s, Color color) { ZPoint realPosition = p; ZPoint realSize = s; if (s.x < 0) { realPosition.x = p.x + s.x; realSize.x = -s.x; } if (s.y < 0) { realPosition.y = p.y + s.y; realSize.y = -s.y; } Rectangle rectangle = new Rectangle(position.x + realPosition.x, position.y + realPosition.y, realSize.x, realSize.y); M.spriteBatch.Draw(M.universalTexture, rectangle, color); }
/*public void LoadTextures() { //Texture = M.game.Content.Load<Texture2D>("other/player"); Texture = NamedTexture.Get("other/player"); }*/ public void DrawParty(ZPoint position) { Screen screen = new Screen(position, new ZPoint(1, 1)); int vOffset = 0, iOffset = 0, hiOffset = 40, vStep = 40; MouseTrigger.Clear<MouseTriggerObject<LocalObject>>(); foreach (var c in party) { Screen icon = new Screen(position + new ZPoint(0, vOffset), new ZPoint(32, 32)); icon.Fill(Stuff.MyColor("Very Dark Grey")); icon.Draw(c.GetTexture, ZPoint.Zero); if (c.xp != null) icon.DrawRectangle(new ZPoint(-2, 32), new ZPoint(2, (int)(-32 * ((float)(c.xp.value % c.xp.Max)/c.xp.Max))), Color.Yellow); MouseTriggerObject<LocalObject>.Set(c, icon.position, icon.size); float hpMissing = 1 - (float)c.hp.value / c.hp.Max; float staminaMissing = 1 - (float)c.hp.stamina / c.hp.Max; icon.DrawRectangle(new ZPoint(0, 32), new ZPoint(32, -(int)(staminaMissing * 32)), new Color(0.2f, 0.0f, 0.0f, 0.2f)); icon.DrawRectangle(new ZPoint(0, 32), new ZPoint(32, -(int)(hpMissing * 32)), new Color(0.2f, 0.0f, 0.0f, 0.2f)); if (c.inventory != null) c.inventory.Draw(position + new ZPoint(hiOffset, iOffset)); vOffset += vStep; if (c.inventory != null) iOffset += vStep; } var mtc = MouseTrigger.GetUnderMouse<MouseTriggerObject<LocalObject>>(); if (mtc != null) { LocalObject c = mtc.t; Screen icon = new Screen(position + new ZPoint(0, vStep * party.IndexOf(c)), new ZPoint(32, 32)); icon.DrawString(M.fonts.verySmall, c.hp.stamina.ToString() + "/" + c.hp.value + "/" + c.hp.Max, 27, Color.White); c.DrawInfo(position + new ZPoint(6 * 32 + 48, 40)); } Action<Inventory> draw = i => { i.Draw(position + new ZPoint(hiOffset, iOffset)); iOffset += i.Height * 32 + 8; }; draw(inventory); if (!crafting.IsEmpty) DrawCrafting(screen.position + new ZPoint(240, iOffset)); draw(crafting); if (!ground.IsEmpty) draw(ground); if (barter != null) DrawBarter(new ZPoint(hiOffset + 6 * 32 + 16, 8)); }
public void Draw() { M.Fill(new Color(0, 0, 0, 0.6f)); foreach (LocalObject l in objects) { l.p.animations.Draw(); if (l.initiative != null) l.initiative.animations.Draw(); } for (int j = 0; j < Size.y; j++) for (int i = 0; i < Size.x; i++) { ZPoint p = new ZPoint(i, j); Draw(this[p].texture[data[i, j].variation], p); foreach (var d in ZPoint.Directions) { ZPoint q = p + d; if (!InRange(q)) continue; bool draw = (!this[p].IsWalkable && !this[p].IsFlat && this[q].IsWalkable && this[q].IsFlat) || (this[p].name != "Sky" && this[q].name == "Sky"); if (draw) Draw(NamedTexture.Get("local/wall mask " + (int)d), p); } } if (combatAnimations.IsEmpty) DrawZones(); var query = objects.OrderBy(o => !o.p.IsWalkable).ThenBy(o => o.p.y).ThenBy(o => -o.Importance); foreach (LocalObject l in query) l.drawing.Draw(); combatAnimations.Draw(); scaleAnimations.Draw(); if (ability != null && Mouse.IsIn(AbilityZone)) Draw(NamedTexture.Get("other/target"), Mouse); else if (InRange(Mouse)) Draw(NamedTexture.Get("other/zSelection"), Mouse); if (spotlight != null && spotlight != current) M.Draw(NamedTexture.Get("other/zSelection"), spotlight.p.GC); foreach (DelayedDrawing dd in delayedDrawings) dd.Draw(); delayedDrawings.Clear(); DrawScale(false); spotlight.p.DrawInfo(new ZPoint(M.size.x - 288 - 8, 8)); if (MyGame.Instance.combatLog) log.Draw(); DrawEndButton(); }
public void Use(Ability ability, ZPoint target) { PayAbilityCost(ability); if (ability.targetType == Ability.TargetType.Creature) Use(ability, B.Get(target)); else if (ability.targetType == Ability.TargetType.Direction) Use(ability, ZPoint.GetDirection(target - t.p.value)); else { if (ability is ClassAbility) { ClassAbility ca = ability as ClassAbility; Action<string> log = s => B.log.Add(" " + s, ca.color); if (ca.NameIs("Overgrowth")) { LocalObject o = B.Get(target); if (o == null) { if (B.IsWalkable(target)) { B.Add(new LocalObject(LocalShape.Get("Tree")), target); log("grows a tree."); } } else if (o.TypeName == "Tree" || o.TypeName == "Swamp Tree") { B.Remove(o); B.Add(new LocalObject(LocalShape.Get(o.TypeName == "Tree" ? "Treant" : "Swamp Treant")), target, true, false); log("transforms a tree into a treant!"); } else if (o.TypeName == "Dead Tree") { B.Remove(o); B.Add(new LocalObject(LocalShape.Get("Tree")), target); } else if (o.TypeName == "Poisoned Tree") { B.Remove(o); B.Add(new LocalObject(LocalShape.Get("Dead Tree")), target); } else if (o == t) { t.hp.Add(1, true); log("regenerates."); } else if (o.effects != null) { B.log.RemoveLastLine(); o.effects.Add("Roots", 10); } AnimateByDefault(ability.castTime); } else if (ca.NameIs("Leap")) { t.p.Set(target, ability.castTime, true); log("leaps to a different location."); } } else if (ability is ItemAbility) { ItemAbility ia = ability as ItemAbility; if (ia.name == "Destroy Wall") { var list = (from pair in B.palette.data where pair.Value.type.name == "ground" select pair.Key).ToList(); int r = World.Instance.random.Next(list.Count); B.SetTile(target, list[r]); } else if (ia.name == "Hurl") { if (ia.itemShape.name == "Flashbang") foreach (LocalObject c in B.ActiveObjects.Where(c => c.p.Distance(target) <= 3)) c.effects.Add("Blind", 6); B.combatAnimations.Add(new TextureAnimation(ia.itemShape.texture, t.p.GC, Battlefield.GC(target), ia.castTime)); } } } LocalObject lc = B.Get(target); if (lc != null) lc.RemoveEffect("Sleeping"); B.ability = null; t.initiative.PassTurn(ability.castTime); }
public void Use(Ability ability, ZPoint.Direction direction) { if (ability is ClassAbility) { ClassAbility ca = ability as ClassAbility; Action<string> log = s => B.log.Add(" " + s, ca.color); if (ca.NameIs("Bull Rush")) { Kick(t.p.value, direction, 2, true, ability.castTime); log("bull-rushes somebody."); } else if (ca.NameIs("Kick")) { Kick(t.p.value, direction, 2, false, ability.castTime); log("kicks somebody."); } else if (ca.NameIs("Power Strike")) { t.effects.Add("Power Strike", 10, direction); AnimateByDefault(ability.castTime); LocalObject lc = B.Get(t.p.value + direction); log("prepares to do a powerful attack" + (lc != null ? " on " + lc.CommonName : "") + "."); } else if (ca.NameIs("Hurl Rock")) { ZPoint p = t.p.value + direction; while (B.IsFlat(p) && t.p.Distance(p) <= ability.range) p = p + direction; LocalObject lc = B.Get(p); B.combatAnimations.Add(new TextureAnimation(NamedTexture.Get("local/stone"), t.p.GC, Battlefield.GC(p), 0.5f * ability.castTime)); log("throws a rock and hits"); if (lc != null) { Kick(p, direction, 1, true, 0.5f * ability.castTime); t.p.DoDamage(lc, 2, false); log(lc.CommonName + "."); } else { AnimateByDefault(0.5f * ability.castTime); log("nobody."); } } } else if (ability is ItemAbility) { ItemAbility ia = ability as ItemAbility; if (ability.NameIs("Throw")) { ZPoint p = t.p.value + direction; while (B.IsFlat(p) && t.p.Distance(p) <= ability.range) p = p + direction; LocalObject lc = B.Get(p); B.combatAnimations.Add(new TextureAnimation(ia.itemShape.texture, t.p.GC, Battlefield.GC(p), ability.castTime)); if (ia.itemShape.name == "Net") { if (lc != null) lc.effects.Add("Net", 6); else B.Add(new LocalObject(new Item(ia.itemShape)), p); } else { if (lc != null) t.p.DoDamage(lc, t.attack.Damage * 2, false); B.Add(new LocalObject(new Item(ia.itemShape)), p); } t.inventory.Remove(ia.itemShape); } else if (ability.NameIs("Push")) { ZPoint p = t.p.value + direction; while (B.IsFlat(p) && t.p.Distance(p) <= ability.range) p = p + direction; LocalObject lc = B.Get(p); if (lc != null) Kick(lc.p.value, direction, 2, true, ability.castTime); } else if (ability.NameIs("Power Shot")) { var ray = B.Ray(t.p.value, direction, ability.range, true); B.combatAnimations.Add(new TextureAnimation(NamedTexture.Get("local/arrow"), Battlefield.GC(ray.First()), Battlefield.GC(ray.Last()), ability.castTime)); foreach (LocalObject lc in B.ActiveObjects.Where(c => c.p.value.IsIn(ray) && c != t)) t.p.DoDamage(lc, ia.itemShape.bonus.damage + 1, false); } } }
private void Kick(ZPoint p, ZPoint.Direction d, int distance, bool self, float gameTime) { List<LocalObject> train = new List<LocalObject>(); int i = self ? 0 : 1; while (true) { ZPoint shifted = p.Shift(d, i); LocalObject lc = B.Get(shifted); if (lc == null) break; else train.Add(lc); i++; } if (train.Count > 0) { ZPoint last = train.Last().p.value; i = 1; while (B.IsWalkable(last.Shift(d, i)) || B.IsFlat(last.Shift(d, i))) i++; int shift = Math.Min(i - 1, distance); foreach (LocalObject o in train) { o.p.Set(o.p.value.Shift(d, shift), gameTime, o == train.First()); if (!B.IsWalkable(o.p.value, o)) o.p.Kill(false); } } else AnimateByDefault(gameTime); }
public void SetTile(ZPoint p, char value) { if (InRange(p)) { data[p.x, p.y].tile = value; data[p.x, p.y].variation = R.Next(palette[value].variations); } }
private bool InRange(ZPoint p) { return p.InBoundaries(new ZPoint(0, 0), Size - new ZPoint(1, 1)); }
public void DrawInfo(ZPoint position) { MainScreen M = MainScreen.Instance; Screen screen = new Screen(position, new ZPoint(192, 1)); screen.DrawString(M.fonts.verdanaBold, FullName, ZPoint.Zero, Color.White); if (cclass != null) { screen.DrawString(M.fonts.small, "(" + background.name + ", " + origin.name + ")", new ZPoint(0, screen.offset), Color.White); screen.offset += 8; foreach (Skill skill in BigBase.Instance.skills.data) { int previousOffset = screen.offset; screen.DrawString(M.fonts.small, skill.name, new ZPoint(0, screen.offset), Color.White); int trueOffset = screen.offset; screen.DrawString(M.fonts.small, skills[skill].ToString(), new ZPoint(100, previousOffset), Color.White); screen.offset = trueOffset; } } }
/* * os_read_key * * Read a single character from the keyboard (or a mouse click) and * return it. Input aborts after timeout/10 seconds. * */ public static zword read_key(int timeout, bool cursor) { _screen.RefreshScreen(); _screen.SetInputMode(true, true); if (_setCursorPositionCalled == false) { set_cursor(_newCursorPosition.Y, _newCursorPosition.X); } ZPoint p = _screen.GetCursorPosition(); try { //#if SILVERLIGHT // var sw = new WiredPrairie.Silverlight.Stopwatch(); //#else // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //#endif // sw.Start(); while (true) { do { if (main.abort_game_loop == true) { return(CharCodes.ZC_RETURN); } lock (entries) { if (entries.Count > 0) { break; } //if (sw.Elapsed.TotalSeconds > timeout / 10 && timeout > 0) // return CharCodes.ZC_TIME_OUT; } //System.Threading.Thread.Sleep(10); } while (true); lock (entries) { _setCursorPositionCalled = false; zword c = entries.Dequeue(); int width = _screen.GetStringWidth(((char)c).ToString(), new CharDisplayInfo(ZFont.FIXED_WIDTH_FONT, ZStyles.NORMAL_STYLE, 1, 1)); // _screen.SetCursorPosition(p.X + width, p.Y); _newCursorPosition = new ZPoint(p.X + width, p.Y); return(c); } } } finally { _screen.SetInputMode(false, false); } }
public int Distance(ZPoint p) { return MyMath.ManhattanDistance(value, p); }
public void Set(ZPoint p, float gameTime, bool commonQueue) { if (value == null) value = new ZPoint(); RMove rMove = new RMove(r, p - value, gameTime); if (commonQueue) B.combatAnimations.Add(rMove); else animations.Add(rMove); value = p; }
public override bool Contrainte(int x, int y) { ZPoint p = new ZPoint(x, y); return(Contrainte(p)); }
public bool this[ZPoint p] { get { return W.map.InRange(p) ? visitedLocations[p.x, p.y] : false; } set { if (W.map.InRange(p)) visitedLocations[p.x, p.y] = value; } }
public bool Contains(Vector2 position) { ZPoint p = new ZPoint((int)position.X - _posStart, (int)position.Y); return(_points.Contains(p)); }
/* * os_read_line * * Read a line of input from the keyboard into a buffer. The buffer * may already be primed with some text. In this case, the "initial" * text is already displayed on the screen. After the input action * is complete, the function returns with the terminating key value. * The length of the input should not exceed "max" characters plus * an extra 0 terminator. * * Terminating keys are the return key (13) and all function keys * (see the Specification of the Z-machine) which are accepted by * the is_terminator function. Mouse clicks behave like function * keys except that the mouse position is stored in global variables * "mouse_x" and "mouse_y" (top left coordinates are (1,1)). * * Furthermore, Frotz introduces some special terminating keys: * * ZC_HKEY_PLAYBACK (Alt-P) * ZC_HKEY_RECORD (Alt-R) * ZC_HKEY_SEED (Alt-S) * ZC_HKEY_UNDO (Alt-U) * ZC_HKEY_RESTART (Alt-N, "new game") * ZC_HKEY_QUIT (Alt-X, "exit game") * ZC_HKEY_DEBUG (Alt-D) * ZC_HKEY_HELP (Alt-H) * * If the timeout argument is not zero, the input gets interrupted * after timeout/10 seconds (and the return value is 0). * * The complete input line including the cursor must fit in "width" * screen units. * * The function may be called once again to continue after timeouts, * misplaced mouse clicks or hot keys. In this case the "continued" * flag will be set. This information can be useful if the interface * implements input line history. * * The screen is not scrolled after the return key was pressed. The * cursor is at the end of the input line when the function returns. * * Since Frotz 2.2 the helper function "completion" can be called * to implement word completion (similar to tcsh under Unix). * */ public static zword read_line(int max, zword[] buf, int timeout, int width, bool continued) { // ZC_SINGLE_CLICK || ZC_DOUBLE_CLICK // case VK_DELETE: // case VK_HOME: // case VK_END: // case VK_TAB: List <BufferChars> _buffer = new List <BufferChars>(); _screen.RefreshScreen(); for (int i = 0; i < buf.Length; i++) { buf[i] = 0; } int background; int foreground; _screen.GetColor(out foreground, out background); _screen.SetInputColor(); _screen.SetInputMode(true, true); ZPoint p = _screen.GetCursorPosition(); try { while (true) { if (main.abort_game_loop == true) { return(CharCodes.ZC_RETURN); } while (entries.Count == 0) { if (main.abort_game_loop == true) { return(CharCodes.ZC_RETURN); } //System.Threading.Thread.Sleep(10); } zword c = entries.Dequeue(); switch (c) { case CharCodes.ZC_HKEY_HELP: case CharCodes.ZC_HKEY_DEBUG: case CharCodes.ZC_HKEY_PLAYBACK: case CharCodes.ZC_HKEY_RECORD: case CharCodes.ZC_HKEY_SEED: case CharCodes.ZC_HKEY_UNDO: case CharCodes.ZC_HKEY_RESTART: case CharCodes.ZC_HKEY_QUIT: return(c); } if (c == CharCodes.ZC_SINGLE_CLICK || c == CharCodes.ZC_DOUBLE_CLICK) { // Just discard mouse clicks here continue; } else if (c == CharCodes.ZC_ARROW_UP) { clearInputAndShowHistory(1, _buffer); } else if (c == CharCodes.ZC_ARROW_DOWN) { clearInputAndShowHistory(-1, _buffer); } else if (c == CharCodes.ZC_ARROW_LEFT) { } else if (c == CharCodes.ZC_ARROW_RIGHT) { } else if (c == CharCodes.ZC_RETURN || c == '\n' || c == '\r') { var sb = new System.Text.StringBuilder(); foreach (BufferChars bc in _buffer) { sb.Append((char)bc.Char); } _history.Insert(0, sb.ToString()); _historyPos = 0; return(CharCodes.ZC_RETURN); } else if (c == CharCodes.ZC_BACKSPACE) { if (_buffer.Count > 0) { BufferChars bc = _buffer[_buffer.Count - 1]; _buffer.Remove(bc); p.X -= bc.Width; _screen.SetCursorPosition(p.X, p.Y); _screen.RemoveChars(1); _screen.RefreshScreen(); } } else if (c == '\t') { var sb = new System.Text.StringBuilder(); foreach (BufferChars bc in _buffer) { sb.Append((char)bc.Char); } String temp = sb.ToString(); String word; int result = Text.completion(temp, out word); if (result == 0) { foreach (char c1 in word) { entries.Enqueue(c1); } entries.Enqueue(' '); } else if (result == 1) { beep(0); } else { beep(1); } } else { // buf[pos++] = c; int w = _screen.GetStringWidth(((char)c).ToString(), new CharDisplayInfo(ZFont.TEXT_FONT, ZStyles.NORMAL_STYLE, -1, -1)); p.X += w; _screen.SetCursorPosition(p.X, p.Y); _buffer.Add(new BufferChars(c, w)); _screen.addInputChar((char)c); _screen.RefreshScreen(); } } } finally { _screen.SetColor(foreground, background); _screen.SetInputMode(false, false); for (int i = 0; i < _buffer.Count; i++) { buf[i] = _buffer[i].Char; } } }
void DFSGetBigLine(ZPoint p1, ZPoint p2) { ZPoint temp = p1; bigPoint.Push(p1); while (true) { temp = bigPoint.Peek(); int d = 0; Transform[] t = new Transform[4]; GameObject[] go = new GameObject[2]; foreach (GameObject g in temp.lines) { if (g.GetComponent <ZLine>().enabled == true) { t[d] = g.transform.parent; d++; } } if (d == 2 && t[0] == t[1]) { d = 0; foreach (GameObject g in temp.lines) { if (g.GetComponent <ZLine>().enabled == true) { go[d] = g; d++; } } } else { break; } foreach (GameObject l in go) { if (!bigLine.Contains(l.GetComponent <ZLine>())) { bigLine.Add(l.GetComponent <ZLine>()); foreach (ZPoint p in l.GetComponent <ZLine>().points) { if (p != temp) { bigPoint.Push(p); } } } } } temp = p2; bigPoint.Push(p2); while (true) { temp = bigPoint.Peek(); int d = 0; Transform[] t = new Transform[4]; GameObject[] go = new GameObject[2]; foreach (GameObject g in temp.lines) { if (g.GetComponent <ZLine>().enabled == true) { t[d] = g.transform.parent; d++; } } if (d == 2 && t[0] == t[1]) { d = 0; foreach (GameObject g in temp.lines) { if (g.GetComponent <ZLine>().enabled == true) { go[d] = g; d++; } } } else { break; } foreach (GameObject l in go) { if (!bigLine.Contains(l.GetComponent <ZLine>())) { bigLine.Add(l.GetComponent <ZLine>()); foreach (ZPoint p in l.GetComponent <ZLine>().points) { if (p != temp) { bigPoint.Push(p); } } } } } }
public static int ManhattanDistance(ZPoint p1, ZPoint p2) { return Math.Abs(p1.x - p2.x) + Math.Abs(p1.y - p2.y); }
public bool PassageImpossible(Vector2 position) { ZPoint p = new ZPoint((int)position.X - _posStart, (int)position.Y); return(_interdit.Contains(p)); }
public void Load() { Log.Write("loading the world... "); XmlNode xnode = MyXml.SecondChild("Data/world.xml"); Log.Assert(xnode.Name == "map", "wrong world file format"); int width = MyXml.GetInt(xnode, "width"); int height = MyXml.GetInt(xnode, "height"); map.margin.x = MyXml.GetInt(xnode, "vMargin"); map.margin.y = MyXml.GetInt(xnode, "hMargin"); string method = MyXml.GetString(xnode, "method"); map.Load(width, height, method); xnode = xnode.NextSibling; camera = new ZPoint(MyXml.GetInt(xnode, "x"), MyXml.GetInt(xnode, "y")); player = new Player(); player.SetPosition(camera, 0.01f); player.UpdateVisitedLocations(); for (xnode = xnode.NextSibling.FirstChild; xnode != null; xnode = xnode.NextSibling) { GlobalObject o = new GlobalObject(BigBase.Instance.gShapes.Get(MyXml.GetString(xnode, "name"))); o.uniqueName = MyXml.GetString(xnode, "uniqueName"); string dialogName = MyXml.GetString(xnode, "dialog"); if (dialogName != "") o.dialog = BigBase.Instance.dialogs.Get(dialogName); o.SetPosition(new HexPoint(MyXml.GetInt(xnode, "x"), MyXml.GetInt(xnode, "y")), 0.01f); for (XmlNode xitem = xnode.FirstChild; xitem != null; xitem = xitem.NextSibling) o.inventory.Add(new Item(MyXml.GetString(xitem, "name"), MyXml.GetInt(xitem, "amount", 1))); gObjects.Add(o); } Log.WriteLine("OK"); }
public List<ZPoint> Ray(ZPoint position, ZPoint.Direction d, int range, bool penetration) { List<ZPoint> result = new List<ZPoint>(); ZPoint p = position + d; result.Add(position); while ((IsFlat(p) || (penetration && Get(p) != null)) && MyMath.ManhattanDistance(p, position) <= range) { result.Add(p); p += d; } if (!p.TheSameAs(position)) result.Add(p); return result; }
public void UpdateVisitedLocations() { if (visitedLocations == null) { visitedLocations = new bool[W.map.Size.x, W.map.Size.y]; for (int j = 0; j < W.map.Size.y; j++) for (int i = 0; i < W.map.Size.x; i++) visitedLocations[i, j] = false; //OpenMap(); } for (int j = -2; j <= 2; j++) for (int i = -2; i <=2; i++) { ZPoint p = position + new ZPoint(i, j); if (W.map.IsInView(position, p)) this[p] = true; } ZPoint pvr = new ZPoint(3, 3); if (!((ZPoint)position).InBoundaries(W.camera - W.viewRadius + pvr + new ZPoint(5, 0), W.camera + W.viewRadius - pvr)) W.camera = position; }
public int GetID(Vector2 position) { ZPoint p = new ZPoint((int)position.X - _posStart, (int)position.Y); return(_points.IndexOf(p)); }
public void Draw(ZPoint position) { Screen screen = new Screen(position, new ZPoint(width * 32, height * 32)); if (G.battle) MouseTrigger.Clear<MouseTriggerInventory>(); for (int i = 0; i < Size; i++) MouseTriggerInventory.Set(this, i, screen.position + CellPosition(i), new ZPoint(32, 32)); var mti = MouseTrigger.GetUnderMouse<MouseTriggerInventory>(); if (((mti != null && mti.inventory == this) || !IsEmpty) && name != "" && !G.battle) screen.DrawString(M.fonts.superSmall, name, Color.White); screen.Fill(name == "ground" ? Stuff.MyColor("Very Dark Blue") : Stuff.MyColor("Very Dark Grey")); if (globalOwner == World.Instance.player) screen.DrawRectangle(ZPoint.Zero, new ZPoint(screen.size.x, (int)(Weight * screen.size.y / globalOwner.WeightLimit)), new Color(0.2f, 0.2f, 0.2f, 0.5f)); for (int i = 0; i < Size; i++) { ZPoint p = CellPosition(i); if (data[i] != null) { screen.Draw(data[i].data.texture, p); if (data[i].numberOfStacks > 1) screen.DrawStringWithShading(M.fonts.small, data[i].numberOfStacks.ToString(), p + new ZPoint(24, 18), Color.White); if (G.battle && localOwner == B.current && name == "" && data[i].data.ability != null) screen.DrawStringWithShading(M.fonts.small, data[i].cooldown > 0 ? "(" + (int)data[i].cooldown + ")" : Stuff.ItemHotkeys[i].ToString(), p, Color.White); } } if (mti != null && mti.inventory == this) { screen.Draw(NamedTexture.Get("other/zSelection"), CellPosition(mti.cell)); Item item = mti.GetItem(); if (item != null) { item.data.DrawDescription(G.battle ? name == "ground" ? position + new ZPoint(-168, 88) : position + new ZPoint(24, 88) : new ZPoint(248, 48)); if (G.battle && G.RightMouseButtonClicked && B.current.inventory != null) { Inventory inventory = B.current.inventory; if (this == inventory) { B.Add(new LocalObject(item), B.current.p.value); Remove(mti.cell); } else if (name == "ground" && inventory.CanAdd(item)) { inventory.Add(item); B.RemoveItem(item); } } } } }
public bool IsReachable(ZPoint p, ZPoint q, int range) { if (p.x != q.x && p.y != q.y) return false; if (MyMath.ManhattanDistance(p, q) > range) return false; ZPoint.Direction d = (p - q).GetDirection(); for (ZPoint z = q + d; !z.TheSameAs(p); z += d) if (!IsFlat(z)) return false; return true; }
public void DrawInfo(ZPoint position) { int length = 288, height = 124 + 48; Screen screen = new Screen(position, new ZPoint(length, height)); screen.Fill(Color.Black); if (t.hp != null) { float hpFraction = (float)t.hp.value / t.hp.Max; float staminaFraction = (float)t.hp.stamina / t.hp.Max; screen.DrawRectangle(new ZPoint(0, 0), new ZPoint((int)(hpFraction * length), 20), new Color(0.2f, 0, 0)); screen.DrawRectangle(new ZPoint(0, 0), new ZPoint((int)(staminaFraction * length), 20), new Color(0.4f, 0, 0)); for (int i = 1; i <= t.hp.Max; i++) screen.DrawRectangle(new ZPoint((int)(i * (float)length / t.hp.Max), 0), new ZPoint(1, 20), Color.Black); } SpriteFont font = M.fonts.verdanaBold; screen.DrawString(font, t.FullName, 23, Color.White); if (t.attack != null) { screen.Draw(NamedTexture.Get("other/damage"), new ZPoint(0, 40)); screen.DrawString(font, t.attack.Damage.ToString(), new ZPoint(22, 43), Color.White); screen.DrawString(font, t.attack.Value.ToString() + "/" + t.defence.Value, 43, Color.White); } if (t.hp != null) { screen.DrawString(font, t.hp.Armor.ToString(), new ZPoint(length - 32, 43), Color.White); screen.Draw(NamedTexture.Get("other/armor"), new ZPoint(length - 20, 40)); } if (t.effects != null) t.effects.Draw(screen.position + new ZPoint(0, 60), screen.position + new ZPoint(24, 180)); if (t.inventory != null) t.inventory.Draw(screen.position + new ZPoint(0, 92)); if (t.abilities != null) t.abilities.Draw(screen, new ZPoint(0, 124)); Ground.Draw(screen.position + new ZPoint(192, 92)); }
public bool IsWalkable(ZPoint p, LocalObject t = null) { if (!InRange(p)) return false; LocalObject o = Get(p); if (o != null) return o.p.IsWalkable; else return (t != null && t.HasAbility("Flying")) ? this[p].IsFlat : this[p].IsWalkable; }
public bool TheSameAs(ZPoint p) { return value.TheSameAs(p); }
public List<ZPoint> Range(ZPoint p, int value) { return points.Where(q => MyMath.ManhattanDistance(p, q) <= value).ToList(); }