Example #1
0
        public static GameObject CreateInstance(UndertaleResources.UObject uobj, float x, float y)
        {
            GameObject o = new GameObject();

            o.Name     = uobj.Name;
            o.Index    = uobj.Index;
            o.Position = new Vector2(x, y);
            if (uobj.Sprite != null)
            {
                o.ImageIndex = uobj.Sprite.Index;
            }
            o.Depth      = uobj.Depth; //  Global.DepthToMonoDepth(uobj.Depth);
            o.Solid      = uobj.Solid;
            o.Visible    = uobj.Visible;
            o.Persistant = uobj.Persistent; // not sure how to handle this
            o.Alarms     = new AlarmIndexer();
            if (o.Name == "OBJ_WRITER")
            {
                o.DrawDelegate             = UndertaleScript.GetDelegate("gml_Object_OBJ_WRITER_Draw_0");
                o.UpdateDelegate           = UndertaleScript.GetDelegate("gml_Object_OBJ_WRITER_Step_1");
                o.StartUpdateDelegate      = UndertaleScript.GetDelegate("gml_Object_OBJ_WRITER_Step_0");
                o.Alarms.AlarmDelegates[0] = UndertaleScript.GetDelegate("gml_Object_OBJ_WRITER_Alarm_0");
                //         UndertaleScript.StartDebugger(UndertaleScript.L,false);
                var value = UndertaleScript.L.DoString("return GetSprite('spr_brattyface',0)");
                UndertaleScript.DebugRunDelegate("gml_Object_OBJ_WRITER_Create_0", UserData.Create(o));
            }
            o.Create();
            Debug.Assert(!o.Persistant);
            // need to handle mask too
            return(o);
        }
Example #2
0
        public void Draw(SpriteBatch batch)
        {
            if (Visible)
            {
                if (DrawDelegate != null)
                {
                    UndertaleScript.TryDelegate(DrawDelegate, self);
                }

                else if (Sprite != null)
                {
                    var f = Sprite.Frames[_currentFrame];
                    batch.Draw(f.Texture, Position, null, f.Origin, null, _direction, ScaleVector, Color, SpriteEffects.None);
                }
                InternalDraw(batch);
            }
        }
Example #3
0
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            Global.WhitePixel = new Texture2D(GraphicsDevice, 1, 1);
            Global.WhitePixel.SetData(new[] { Color.White });
            mousePos = new Vector2(graphics.GraphicsDevice.Viewport.
                                   Width / 2,
                                   graphics.GraphicsDevice.Viewport.
                                   Height / 2);

            UndertaleScript.StartUpLua();
            UndertaleScript.DoFile("scr_gamestart.lua");
            UndertaleScript.DoFile("scr_text.lua");
            //     UndertaleScript.DoFile("gameobject.lua");



            //  var chunk = L.CompileChunk(ProgramSource, "test.lua", new LuaCompileOptions() { DebugEngine = LuaStackTraceDebugger.Default }); // compile the script with debug informations, that is needed for a complete stack trace

            //  DG.dochunk(test);
            // G.DoChunk(test);
            //   Fonts[0] = Content.Load<SpriteFont>("fnt_wingdings");
            //   Fonts[1] = Content.Load<SpriteFont>("fnt_main");
            //   Fonts[2] = Content.Load<SpriteFont>("fnt_maintext");
            //   Fonts[3] = Content.Load<SpriteFont>("fnt_small");
            //   Fonts[4] = Content.Load<SpriteFont>("fnt_plain");
            //   Fonts[5] = Content.Load<SpriteFont>("fnt_plainbig");
            //  Fonts[6] = Content.Load<SpriteFont>("fnt_curs");
            //  Fonts[8] = Content.Load<SpriteFont>("fnt_comicsans");
            //  Fonts[9] = Content.Load<SpriteFont>("fnt_papyrus");
            //  Fonts[10] = Content.Load<SpriteFont>("fnt_maintext_2");

            UndertaleScript.L.Globals["draw_set_font"] = new Action <DynValue>((DynValue o) =>
            {
                if (o.Type == DataType.Number)
                {
                    currentFont = FontSpritesIndex[(int)o.Number];
                }
                else if (o.Type == DataType.String)
                {
                    currentFont = FontSpritesName[o.String];
                }
            });
            UndertaleScript.L.Globals["random"] = new Func <int, int>((int i) =>
            {
                return(random.Next(i));
            });
            UndertaleScript.L.Globals["draw_text_color"] = new Action <DynValue>((DynValue o) =>
            {
                currentFontColor.PackedValue = (uint)o.Number;
            });
            UndertaleScript.L.Globals["draw_set_color"] = new Action <DynValue>((DynValue o) =>
            {
                currentFontColor.PackedValue = (uint)o.Number;
            });
            UndertaleScript.L.Globals["draw_text"] = new Action <float, float, string>((float x, float y, string s) =>
            {
                if (currentFont == null)
                {
                    return;
                }
                if (s == null)
                {
                    return;
                }
                if (s.Length == 1)
                {
                    Sprite.Frame f = currentFont[s[0]];
                    spriteBatch.Draw(f.Texture, new Vector2(x, y), f.Origin, currentFontColor);
                    // spriteBatch.Draw(f.Texture, new Vector2(x, y),null, null,0.0f,null, currentFontColor,SpriteEffects.None,0);
                    // spriteBatch.Draw(f.Texture, new Vector2(x, y), null, f.Origin, null, 0.0f, null, currentFontColor, SpriteEffects.None, 0);
                }
                else
                {
                    Debug.WriteLine("meh draw_text");
                }
                //  spriteBatch.DrawString(currentFont, s, new Vector2(x, y), currentFontColor);
                // draw_set_font(self.myfont)

                //  draw_set_color(self.mycolor)
            });
            UndertaleScript.L.Globals["draw_text_ext"] = new Action <object>((object o) =>
            {
                Debug.WriteLine("draw_text_ext");
            });
            UndertaleScript.L.Globals["draw_sprite"] = new Action <int, int, float, float>((int spriteIndex, int subimg, float x, float y) =>
            {
                Sprite sprite  = Sprite.LoadSprite(spriteIndex);
                Sprite.Frame f = sprite.Frames[subimg % sprite.Frames.Length];
                spriteBatch.Draw(f.Texture, new Vector2(x, y), f.Origin, Color.White);
                Debug.WriteLine("draw_text_ext");
            });
            UndertaleScript.L.Globals["draw_sprite_ext"] = new Action <int, int, float, float, float, float, float, int, float>(
                (int spriteIndex, int subimg, float x, float y, float xscale, float yscale, float rot, int color, float alpha) =>
            {
                Sprite sprite  = Sprite.LoadSprite(spriteIndex);
                Sprite.Frame f = sprite.Frames[subimg % sprite.Frames.Length];
                Color c        = new Color();
                c.PackedValue  = (uint)color;
                c = new Color(c, alpha);
                spriteBatch.Draw(f.Texture, new Vector2(x, y), null, f.Origin, null, rot, new Vector2(xscale, yscale), c);
                Debug.WriteLine("draw_text_ext");
            });
            camera = new Camera2D();
            camera.Initialize(graphics.GraphicsDevice);
            base.Initialize();
        }