示例#1
0
 public static void Clamp(VByte v, U8 low, U8 high)
 {
     If.Block(c => c
              .True(() => A.Set(v).LessThan(low), () => v.Set(low))
              .True(() => A.GreaterThan(high), () => v.Set(high))
              );
 }
 public void ExecuteBlockWrapper(Action block)
 {
     If.Block(c => c
              .True(() => _pauseCount.Equals(0), block)
              .Else(() => {
         _pauseCount.Dec();
         GoTo(_executeLoopBreak);
     })
              );
 }
 public void ExecuteBlockWrapper(Action block)
 {
     If.Block(c => c
              .True(() => _pauseCount.Equals(0), block)
              .Else(() => {
         _pauseCount.Dec();
         Queue.Break();
     })
              );
 }
示例#4
0
            public void Move()
            {
                PosX.Set(z => A.Set(z).Add(LabelFor(MoveX)[Index]));
                PosY.Set(z => A.Set(z).Add(LabelFor(MoveY)[Index]));

                //60 to 180
                If.Block(c => c
                         .True(() => A.Set(PosY).GreaterThan(160),
                               () => PosY.Set(z => z.Subtract(100)))
                         .True(() => A.Set(PosY).LessThan(60),
                               () => PosY.Set(z => z.Add(100)))
                         );
            }
        public void Decompress(Action <RegisterA> block)
        {
            U8 compressionIndicator = 255;

            _temp.Set(TempPtr0[Y.Set(0)]);
            Loop.AscendWhile(Y.Increment(), () => Y.LessThan(_temp), _ => {
                If.Block(c => c
                         .True(() => A.Set(TempPtr0[Y]).Equals(compressionIndicator), () => {
                    Y.State.Unsafe(() => {
                        Y.Increment();
                        X.Set(A.Set(TempPtr0[Y]));
                        Y.Increment();
                        Loop.Descend_Post(X, _ => block(A.Set(TempPtr0[Y])));
                    });
                })
                         .Else(() => block(A.Set(TempPtr0[Y])))
                         );
            });
        }
示例#6
0
        public static void RLEDecompress(/*Action dataAction,*/ VByte temp, Action <RegisterA> block)
        {
            //var lbl = LabelFor(dataAction);
            //TempPtr0.PointTo(lbl);
            byte compressionIndicator = 255;
            var  length = temp.Set(TempPtr0[Y.Set(0)]);

            Loop.AscendWhile(Y.Increment(), () => Y.LessThan(length), _ => {
                If.Block(c => c
                         .True(() => A.Set(TempPtr0[Y]).Equals(compressionIndicator), () => {
                    Y.State.Unsafe(() => {
                        Y.Increment();
                        X.Set(A.Set(TempPtr0[Y]));
                        Y.Increment();
                        Loop.Descend_Post(X, _ => block(A.Set(TempPtr0[Y])));
                    });
                })
                         .Else(() => block(A.Set(TempPtr0[Y])))
                         );
            });
        }
示例#7
0
        static void Main(string[] args)
        {
            Console.Write("=== "); Console.Write("Cake", ConsoleColor.Red); Console.Write("Lang", ConsoleColor.White); Console.WriteLine(" Demo ===");

            Console.WriteLine("For version: " + CakeLang.CakeLang.Version.ToString() + '\n', ConsoleColor.DarkYellow);

            // --- Data Pack Code -----------------------------------------

            DataPack demoPack = new DataPack("Demo Pack", "A demonstration of CakeLang!", "demopack");

            string message = "Hello friend";

            demoPack.Functions.Add(new Function("fun2",
                                                AsAt("s", Run(
                                                         Tellraw('s', JSON.Text(message, JSON.StyleFormattings.Color(Colors.Aqua), JSON.StyleFormattings.Bold))
                                                         ))
                                                ));
            demoPack.Functions.Add(new Function("flying",
                                                If.Block("~ ~-1 ~", Namespace("air"),
                                                         Run(
                                                             Tellraw('s', JSON.Text("Bro, you're flying!", JSON.StyleFormattings.Color(Colors.Yellow), JSON.StyleFormattings.Italic))
                                                             )
                                                         ),
                                                Unless.Block("~ ~-1 ~", Namespace("air"),
                                                             Run(
                                                                 Tellraw('s', JSON.Text("Nah, not flyin' yet", JSON.StyleFormattings.Color(Colors.Yellow), JSON.StyleFormattings.Underlined))
                                                                 )
                                                             )
                                                ));

            ArgumentsFunction introduce = new ArgumentsFunction("introduce", new System.Collections.Generic.Dictionary <string, Type>()
            {
                ["name"]     = typeof(string),
                ["position"] = typeof(float[])
            },
                                                                Tellraw(Selector.Executor, JSON.ArrayBuilder(
                                                                            JSON.Text("My name is ", JSON.StyleFormattings.Bold, JSON.StyleFormattings.Color(Colors.Gold)),
                                                                            JSON.FunctionVariable("introduce", "name", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(", I'm at ", JSON.StyleFormattings.Bold, JSON.StyleFormattings.Color(Colors.Gold)),
                                                                            JSON.FunctionVariable("introduce", "position[0]", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(" "),
                                                                            JSON.FunctionVariable("introduce", "position[1]", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(" "),
                                                                            JSON.FunctionVariable("introduce", "position[2]", JSON.StyleFormattings.Italic, JSON.StyleFormattings.Color(Colors.Yellow)),
                                                                            JSON.Text(" "),
                                                                            JSON.Text("!", JSON.StyleFormattings.Bold, JSON.StyleFormattings.Color(Colors.Gold))
                                                                            ))
                                                                );

            demoPack.Functions.Add(introduce);

            demoPack.Functions.Add(new Function("introducePeople",
                                                introduce.Call("Jeff", new[] { 0.5f, 2f, -4f }),
                                                introduce.Call("Monica", new[] { 0, 0, 0 }),
                                                introduce.Call("Boobo", new[] { 6, 6, 9, -2 })
                                                ));

            // --- Data Pack Code -----------------------------------------

            try
            {
                demoPack.CompileAndInject("CakeLang Demo");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message, ConsoleColor.Red);
            }
        }
示例#8
0
        public override void Step()
        {
            If.Block(c => c
                     .True(_gamepad.IsHeld(NES.Button.Right), () => _charX.Set(z => z.Add(_MoveDist)))
                     .True(_gamepad.IsHeld(NES.Button.Left), () => _charX.Set(z => z.Subtract(_MoveDist)))
                     );
            If.Block(c => c
                     .True(_gamepad.IsHeld(NES.Button.Down), () => _charY.Set(z => z.Add(_MoveDist)))
                     .True(_gamepad.IsHeld(NES.Button.Up), () => _charY.Set(z => z.Subtract(_MoveDist)))
                     );
            If.Block(c => c
                     .True(_gamepad.WasPressed(NES.Button.B), () => {
                _skipOptionIndex.Dec();
                If.True(() => _skipOptionIndex.Equals(255), () => _skipOptionIndex.Set(0));                             //low limit
                GoSub(DrawSkipNum);
            })
                     .True(_gamepad.WasPressed(NES.Button.A), () => {
                _skipOptionIndex.Inc();
                If.True(() => _skipOptionIndex.Equals(_skipOptions.Length), () => _skipOptionIndex.Set(_skipOptions.Length - 1));                               //high limit
                GoSub(DrawSkipNum);
            })
                     );
            Y.Set(0);
            If.True(_gamepad.WasPressed(NES.Button.Select), () => {
                _pattern.Inc();
                If.True(() => _pattern.Equals(3), () => _pattern.Set(0));
            });
            If.True(_gamepad.WasPressed(NES.Button.Start), () => Module <SceneManager>().Queue(Module <Title>()));

            var jx = Temp[1];
            var jy = Temp[2];

            jx.Set(_charX.Subtract(8));
            jy.Set(_charY.Subtract(8));

            NES.PPU.OAM.Object[0].SetPosition(jx, jy);
            NES.PPU.OAM.Object[1].SetPosition(_charX, jy);
            NES.PPU.OAM.Object[2].SetPosition(jx, _charY);
            NES.PPU.OAM.Object[3].SetPosition(_charX, _charY);

            U8 startOffset = 4;

            If.Block(c => c
                     .True(() => _pattern.Equals(0), () => {
                Comment("Single row pattern");
                jx.Set(0x04);
                jy.Set(0x40);

                _processed.Set(0);
                Y.Set(startOffset);

                Loop.Do_old(_ => {
                    var spriteObj = NES.PPU.OAM.Object[Y];
                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_JunkTile);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, jy);
                    Skipterate_Next();

                    jx.Set(z => z.Add(4));
                    _processed.Inc();
                }).While(() => A.Set(_processed).NotEquals(60));
            })
                     .True(() => _pattern.Equals(1), () => {
                Comment("Four rows pattern");
                U8 xStart = 0x30;
                jx.Set(xStart);
                jy.Set(0x30);

                _processed.Set(0);
                Y.Set(startOffset);

                Loop.Do_old(_ => {
                    var spriteObj = NES.PPU.OAM.Object[Y];
                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_JunkTile);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, jy);
                    Skipterate_Next();

                    jx.Set(z => z.Add(8));

                    If.Any(() => _processed.Equals(19), () => _processed.Equals(39)).Then(() => {
                        jy.Set(jy.Add(8));
                        jx.Set(xStart);
                    });
                    _processed.Inc();
                }).While(() => A.Set(_processed).NotEquals(60));
            })
                     .Else(() => {
                Comment("Moving scattered objects pattern");
                Y.Set(startOffset);

                Loop.ForEach(X, _scatterSprites, (face, _) => {
                    var spriteObj = NES.PPU.OAM.Object[Y];
                    jx.Set(face.PosX.Add(8));
                    jy.Set(face.PosY.Add(8));

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile0);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(face.PosX, face.PosY);
                    Skipterate_Next();

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile1);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, face.PosY);
                    Skipterate_Next();

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile2);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(face.PosX, jy);
                    Skipterate_Next();

                    Skipterate_PrepareY(startOffset);
                    spriteObj.Tile.Set(_NPCTile3);
                    spriteObj.Attr.Set(1);
                    spriteObj.SetPosition(jx, jy);
                    Skipterate_Next();

                    face.Move();
                });
            })
                     );
            Skipterate_Next();
        }