public Vector2 getTileLocation(KnyttPoint point) { var gp = GlobalPosition; return(new Vector2(gp.x + GDKnyttAssetManager.TILE_WIDTH * point.x + GDKnyttAssetManager.TILE_WIDTH / 2f, gp.y + GDKnyttAssetManager.TILE_HEIGHT * point.y + GDKnyttAssetManager.TILE_HEIGHT / 2f)); }
public GDKnyttBaseObject getNode(GDKnyttObjectLayer layer, KnyttPoint coords) { var node = scene.Instance() as GDKnyttBaseObject; node.initialize(object_id, layer, coords); return(node); }
protected void pageOut(KnyttPoint location) { T area = this.Areas[location]; this.Areas.Remove(location); this.OnPageOut?.Invoke(location, area); }
// TODO: Add icons to a layer public void addObject(KnyttPoint coords, GDKnyttObjectBundle bundle) { var node = bundle.getNode(this, coords); node.Position = new Vector2(coords.x * GDKnyttAssetManager.TILE_WIDTH, coords.y * GDKnyttAssetManager.TILE_HEIGHT); this.AddChild(node); }
// Changes the current area public void changeArea(KnyttPoint new_area, bool force_jump = false, bool regenerate_same = true) { // Regenerate current area if no change, else deactivate old area if (this.CurrentArea != null) { if (CurrentArea.Area.Position.Equals(new_area)) { if (regenerate_same) { CurrentArea.regenerateArea(regenerate_same: regenerate_same); } return; } CurrentArea.scheduleDeactivation(); } // Update the paging GDWorld.Areas.setLocation(new_area); var area = GDWorld.getArea(new_area); if (area == null) { return; } this.CurrentArea = area; this.CurrentArea.activateArea(); this.beginTransitionEffects(force_jump); Juni.stopHologram(cleanup: true); }
public void initialize(KnyttPoint object_id, GDKnyttObjectLayer layer, KnyttPoint coords) { SetPhysicsProcess(false); this.Layer = layer; this.ObjectID = object_id; this.Coords = coords; this._Initialize(); }
private void addObject(KnyttPoint coords) { var bundle = GDKnyttObjectFactory.buildKnyttObject(trigger.ObjectID); if (bundle != null) { Layer.addObject(coords, bundle); } }
public void playEffect(KnyttPoint point = default(KnyttPoint), Vector2 offset = default(Vector2)) { var sprite = GetNode <Sprite>("EffectSprite"); var player = sprite.GetNode <AnimationPlayer>("AnimationPlayer"); sprite.GlobalPosition = getTileLocation(point) + offset; player.Stop(); player.Play("collect"); }
public void destroyArea(KnyttPoint point, GDKnyttArea area) { if (area == null) { return; } area.destroyArea(); area.QueueFree(); }
public GDKnyttArea instantiateArea(KnyttPoint point) { var area = this.KWorld.getArea(point) ?? new KnyttArea(point, KWorld); var area_node = this.area_scene.Instance() as GDKnyttArea; area_node.loadArea(this, area); this.GetNode("Areas").AddChild(area_node); return(area_node); }
public void setLocation(KnyttPoint location) { if (this.current_location.Equals(location)) { return; } this._handlePaging(location); this.current_location = location; }
public void init(KnyttWorld world, Juni juni) { SetProcessInput(false); SetProcess(false); SetPhysicsProcess(false); if (world == null || juni == null) { return; } this.world = world; this.juni = juni; this.RectSize = new Vector2( (world.MaxBounds.x - world.MinBounds.x + 1) * XSIZE, (world.MaxBounds.y - world.MinBounds.y + 1) * YSIZE); foreach (var area in world.Map) { if (area?.ExtraData == null) { continue; } var coord = area.Position; int?map_x = int.TryParse(area.ExtraData["MapX"], out var i) ? i : null as int?; int?map_y = int.TryParse(area.ExtraData["MapY"], out i) ? i : null as int?; if (map_x != null || map_y != null) { spoofing[coord] = new KnyttPoint(map_x ?? coord.x, map_y ?? coord.y); } if (area.ExtraData["MapVisible"]?.ToLower() == "true") { visible[coord] = true; } if (area.ExtraData["MapVisible"]?.ToLower() == "false") { visible[coord] = false; } int?color = int.TryParse(area.ExtraData["MapColor"], out i) ? i : null as int?; if (color != null) { if (color == 64) { visible[coord] = false; } else { colors[coord] = new Color((color.Value % 4) / 3f, ((color.Value / 4) % 4) / 3f, ((color.Value / 16) % 4) / 3f); } } } }
public void saveGame(KnyttPoint area, KnyttPoint position, bool write) { var save = GDWorld.KWorld.CurrentSave; save.setArea(area); save.setAreaPosition(position); Juni.Powers.writeToSave(save); if (!write) { return; } saveGame(save); }
public static GDKnyttObjectBundle buildKnyttObject(KnyttPoint object_id) { if (!ObjectLookup.ContainsKey(object_id)) { GD.Print($"Object {object_id.x}:{object_id.y} unimplemented."); return(null); } string fname = $"res://knytt/objects/banks/bank{object_id.x}/{ObjectLookup[object_id]}.tscn"; var scene = ResourceLoader.Load <PackedScene>(fname); return(new GDKnyttObjectBundle(object_id, scene)); }
public override void _Draw() { KnyttPoint pos = juni.GDArea.Area.Position; if (spoofing.ContainsKey(pos)) { pos = spoofing[pos]; } float xsize = XSIZE * RectScale.x; float ysize = YSIZE * RectScale.y; foreach (var area in world.Map) { if (area == null) { continue; } var coord = area.Position; if (spoofing.ContainsKey(coord) && !(visible.ContainsKey(coord) && visible[coord])) { coord = spoofing[coord]; } bool is_visited = juni.Powers.isVisited(area); if (!juni.Powers.getPower(JuniValues.PowerNames.Map) && !is_visited) { continue; } if (visible.ContainsKey(coord) && !visible[coord]) { continue; } Rect2 r = new Rect2((coord.x - world.MinBounds.x) * xsize, (coord.y - world.MinBounds.y) * ysize, xsize - 1, ysize - 1); DrawRect(r, is_visited ? (colors.ContainsKey(coord) ? colors[coord] : VISITED_COLOR) : (colors.ContainsKey(coord) ? makeGrey(colors[coord]) : NOT_VISITED_COLOR)); if (coord.Equals(pos)) { DrawRect(r, CURRENT_BORDER, filled: false, width: 2); } } RectPosition = new Vector2( (world.MinBounds.x - pos.x) * xsize * RectScale.x + (GetParentAreaSize().x - xsize) / 2, (world.MinBounds.y - pos.y) * ysize * RectScale.y + (GetParentAreaSize().y - ysize) / 2); }
public List <GDKnyttBaseObject> findObjects(KnyttPoint obj_id) { List <GDKnyttBaseObject> finds = new List <GDKnyttBaseObject>(); foreach (var layer in GDArea.Objects.Layers) { foreach (GDKnyttBaseObject knytt_object in layer.GetChildren()) { if (obj_id.x == knytt_object.ObjectID.x && obj_id.y == knytt_object.ObjectID.y) { finds.Add(knytt_object); } } } return(finds); }
public void saveGame(KnyttPoint area, KnyttPoint position, bool write) { var save = GDWorld.KWorld.CurrentSave; save.setArea(area); save.setAreaPosition(position); Juni.Powers.writeToSave(save); if (!write) { return; } var f = new File(); f.Open($"user://Saves/{save.SaveFileName}", File.ModeFlags.Write); f.StoreString(save.ToString()); f.Close(); }
// Changes the current area public void changeArea(KnyttPoint new_area, bool force_jump = false, bool regenerate_same = true) { // Regenerate current area if no change, else deactivate old area if (this.CurrentArea != null) { if (CurrentArea.Area.Position.Equals(new_area)) { if (regenerate_same) { CurrentArea.regenerateArea(regenerate_same: regenerate_same); } return; } CurrentArea.scheduleDeactivation(); Juni.juniInput.altInput.ClearInput(); } // Update the paging GDWorld.Areas.setLocation(new_area); var area = GDWorld.getArea(new_area); if (area == null) { return; } int change_distance = CurrentArea == null ? 0 : CurrentArea.Area.Position.manhattanDistance(new_area); this.CurrentArea = area; this.CurrentArea.activateArea(); this.beginTransitionEffects(force_jump || change_distance > 1); // never scroll if jump distance is over 1 Juni.stopHologram(cleanup: true); if (area.Area.ExtraData?.ContainsKey("Attach") ?? false) { Juni.enableAttachment(area.Area.getExtraData("Attach")); } if (hasMap()) { Juni.Powers.setVisited(CurrentArea.Area); } }
public KnyttPoint?getFlagWarp(KnyttPoint area_coords, Juni juni) { var area = GDWorld.KWorld.getArea(area_coords); if (area == null) { return(null); } var all_flag_warp = area.FlagWarps[(int)KnyttArea.FlagWarpID.All]; bool some_check_failed = false; KnyttPoint?found_warp = null; foreach (var flag_warp in area.FlagWarps) { if (flag_warp != null) { if (juni.Powers.check(flag_warp.flag)) { if (flag_warp == all_flag_warp && flag_warp.flag.true_flag) // Special case { if (some_check_failed) { continue; } else { found_warp = null; } // Use previous found warp; else override } found_warp = found_warp ?? new KnyttPoint( flag_warp.xArtifactMode ? juni.Powers.getArtifactsCount(flag_warp.x - 1) : flag_warp.x, flag_warp.yArtifactMode ? juni.Powers.getArtifactsCount(flag_warp.y - 1) : flag_warp.y); } else { some_check_failed = true; } } } return(found_warp); }
// This is O(n) time protected override void _handlePaging(KnyttPoint location) { List <KnyttPoint> q_remove = new List <KnyttPoint>(); List <KnyttPoint> q_add = new List <KnyttPoint>(); // Iterate over the current set, and remove foreach (var l in this.Areas.Keys) { if (!isIn(l, location)) { q_remove.Add(l); } } // Iterate over the new area and add any that aren't in this.Areas for (int y = location.y - BorderSize.y; y <= location.y + BorderSize.y; y++) { for (int x = location.x - BorderSize.x; x <= location.x + BorderSize.x; x++) { var kp = new KnyttPoint(x, y); if (!Areas.ContainsKey(kp)) { q_add.Add(kp); } } } // Now just parse the queues foreach (var l in q_remove) { pageOut(l); } foreach (var l in q_add) { pageIn(l); } }
public void returnObject(KnyttPoint object_id) { ObjectCache.DecObject(object_id); }
public GDKnyttObjectBundle GetObject(KnyttPoint object_id) { return(ObjectCache.IncObject(object_id)); }
private bool isIn(KnyttPoint location, KnyttPoint test_location) { return(location.x >= (test_location.x - BorderSize.x) && location.x <= (test_location.x + BorderSize.x) && location.y >= (test_location.y - BorderSize.y) && location.y <= (test_location.y + BorderSize.y)); }
public GDKnyttBaseObject findObject(KnyttPoint obj_id) { var finds = findObjects(obj_id); return(finds.Count != 0 ? finds[0] : null); }
public KnyttRectPaging(KnyttPoint border_size) { this.BorderSize = border_size; }
public void updateLocation(KnyttPoint location) { this.Text = location.ToString(); this.showLocation(); }
public GDKnyttArea getArea(KnyttPoint area) { return(this.Areas.Areas[area]); }
public GDKnyttObjectBundle(KnyttPoint object_id, PackedScene scene, Texture icon = null) { this.object_id = object_id; this.scene = scene; this.icon = icon; }
public void moveToPosition(GDKnyttArea area, KnyttPoint position) { GlobalPosition = (area.getTileLocation(position) + (velocity.y < 0 ? -1 : 1) * BaseCorrection); }
public void changeAreaDelta(KnyttPoint delta, bool force_jump = false, bool regenerate_same = true) { this.changeArea(this.CurrentArea.Area.Position + delta, force_jump); }