コード例 #1
0
ファイル: GDKnyttArea.cs プロジェクト: akien-mga/yknytt
    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));
    }
コード例 #2
0
    public GDKnyttBaseObject getNode(GDKnyttObjectLayer layer, KnyttPoint coords)
    {
        var node = scene.Instance() as GDKnyttBaseObject;

        node.initialize(object_id, layer, coords);
        return(node);
    }
コード例 #3
0
        protected void pageOut(KnyttPoint location)
        {
            T area = this.Areas[location];

            this.Areas.Remove(location);
            this.OnPageOut?.Invoke(location, area);
        }
コード例 #4
0
    // 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);
    }
コード例 #5
0
    // 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);
    }
コード例 #6
0
ファイル: GDKnyttBaseObject.cs プロジェクト: akien-mga/yknytt
 public void initialize(KnyttPoint object_id, GDKnyttObjectLayer layer, KnyttPoint coords)
 {
     SetPhysicsProcess(false);
     this.Layer    = layer;
     this.ObjectID = object_id;
     this.Coords   = coords;
     this._Initialize();
 }
コード例 #7
0
ファイル: Trigger.cs プロジェクト: youkaicountry/yknytt
    private void addObject(KnyttPoint coords)
    {
        var bundle = GDKnyttObjectFactory.buildKnyttObject(trigger.ObjectID);

        if (bundle != null)
        {
            Layer.addObject(coords, bundle);
        }
    }
コード例 #8
0
    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");
    }
コード例 #9
0
 public void destroyArea(KnyttPoint point, GDKnyttArea area)
 {
     if (area == null)
     {
         return;
     }
     area.destroyArea();
     area.QueueFree();
 }
コード例 #10
0
ファイル: GDKnyttWorld.cs プロジェクト: youkaicountry/yknytt
    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);
    }
コード例 #11
0
        public void setLocation(KnyttPoint location)
        {
            if (this.current_location.Equals(location))
            {
                return;
            }

            this._handlePaging(location);
            this.current_location = location;
        }
コード例 #12
0
ファイル: MapPanel.cs プロジェクト: youkaicountry/yknytt
    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);
                }
            }
        }
    }
コード例 #13
0
ファイル: GDKnyttGame.cs プロジェクト: youkaicountry/yknytt
    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);
    }
コード例 #14
0
    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));
    }
コード例 #15
0
ファイル: MapPanel.cs プロジェクト: youkaicountry/yknytt
    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);
    }
コード例 #16
0
    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);
    }
コード例 #17
0
    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();
    }
コード例 #18
0
ファイル: GDKnyttGame.cs プロジェクト: youkaicountry/yknytt
    // 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);
        }
    }
コード例 #19
0
ファイル: GDKnyttGame.cs プロジェクト: youkaicountry/yknytt
    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);
    }
コード例 #20
0
        // 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);
            }
        }
コード例 #21
0
 public void returnObject(KnyttPoint object_id)
 {
     ObjectCache.DecObject(object_id);
 }
コード例 #22
0
 public GDKnyttObjectBundle GetObject(KnyttPoint object_id)
 {
     return(ObjectCache.IncObject(object_id));
 }
コード例 #23
0
 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));
 }
コード例 #24
0
    public GDKnyttBaseObject findObject(KnyttPoint obj_id)
    {
        var finds = findObjects(obj_id);

        return(finds.Count != 0 ? finds[0] : null);
    }
コード例 #25
0
 public KnyttRectPaging(KnyttPoint border_size)
 {
     this.BorderSize = border_size;
 }
コード例 #26
0
ファイル: LocationLabel.cs プロジェクト: youkaicountry/yknytt
 public void updateLocation(KnyttPoint location)
 {
     this.Text = location.ToString();
     this.showLocation();
 }
コード例 #27
0
ファイル: GDKnyttWorld.cs プロジェクト: youkaicountry/yknytt
 public GDKnyttArea getArea(KnyttPoint area)
 {
     return(this.Areas.Areas[area]);
 }
コード例 #28
0
 public GDKnyttObjectBundle(KnyttPoint object_id, PackedScene scene, Texture icon = null)
 {
     this.object_id = object_id;
     this.scene     = scene;
     this.icon      = icon;
 }
コード例 #29
0
 public void moveToPosition(GDKnyttArea area, KnyttPoint position)
 {
     GlobalPosition = (area.getTileLocation(position) + (velocity.y < 0 ? -1 : 1) * BaseCorrection);
 }
コード例 #30
0
ファイル: GDKnyttGame.cs プロジェクト: youkaicountry/yknytt
 public void changeAreaDelta(KnyttPoint delta, bool force_jump = false, bool regenerate_same = true)
 {
     this.changeArea(this.CurrentArea.Area.Position + delta, force_jump);
 }