Porting Touch Develop games

I am wondering if it is possible to port a game developed in Touch Develop to MakeCode Arcade? I have the JSON files of a project I made, called ‘Spacey Invaders Reloaded’. Does anyone know of a lexical parser to converts the JSON content into Static TypeScript?

Interesting idea, @cosmoscowboy! MakeCode Arcade is the spiritual successor to Touch Develop, but it’s a very different platform.

If you’re willing to share your JSON, I’d be happy to take a look. I don’t think I have any of my old Touch Develop code anymore.

Any initial thoughts, @peli ?

1 Like

Hi @AlexK,

Thank you for your reply. I have this file which contains functions for calculating Bezier curves. I can strip out the code that was in the format of Touch Develop, and manually write that as TypeScript; that is not a problem. I just though maybe, since Touch Develop code was translated to TypeScript, and that to Javascript, that there is a library somewhere that enables that process.

{
“scripts”: [
{
“header”: {
“cloudId”: “touchdevelop.com”,
“scriptId”: “hnvib”,
“userId”: “cqeba”,
“status”: “published”,
“lastUse”: 1526676178,
“editor”: “touchdevelop”,
“name”: “Bezier curves”,
“comment”: “Formulas for calculating a linear, quadratic and cubic bezier curves were taken from:\n\nhttp://caffeineowl.com/graphics/2d/vectorial/bezierintro.html\n\nhttp://en.wikipedia.org/wiki/Bézier_curve”
},
“source”: “meta version “v2.2,js,ctx,refs,localcloud,unicodemodel,allasync”;\nmeta name “Bezier curves”;\nmeta icon “Share”;\nmeta color “#ffff0038”;\nmeta rootId “xu5kuZwm7kGpcsE4f4u05jDK”;\nmeta isLibrary “yes”;\nmeta allowExport “yes”;\nmeta hasIds “yes”;\nmeta platform “current”;\nmeta parentIds “”;\n// Formulas for calculating a linear, quadratic and cubic bezier curves were taken from:\n// \n// http://caffeineowl.com/graphics/2d/vectorial/bezierintro.html\n// \n// http://en.wikipedia.org/wiki/Bézier_curve\n#OU78BBXCakSog0cs\naction main() {\n #M5PmWnaV1xVsDZc5 $board := media→create_landscape_board(800, 480);\n #LXJmho39gfcIFoHk $world := media→create_picture($board→width, $board→height);\n #N9FE1nZi9BCXCvhJ $board→set_background_picture($world);\n #xZqnFOalBAXGxhTq $heading_quadratic := $board→create_text(100, 20, 30, “Quadratic bézier curve”);\n #V4b15pnMPn2C3GkT $heading_quadratic→set_color(colors→black);\n #Y1AJeCftQeY5Gco3 $heading_quadratic→set_pos($board→width * .15, $board→height * .1);\n #skE87SD4hbacAG23 $heading_cubic := $board→create_text(100, 20, 30, “Cubic bézier curve”);\n #EWM2twfjzMR9OIj7 $heading_cubic→set_color(colors→blue);\n #CUaItpvU7hiPqC7G $heading_cubic→set_pos($heading_quadratic→x, $heading_quadratic→y + 50);\n #EY6KuXTB6A5VOOOO $heading_linear := $board→create_text(100, 20, 30, “Linear bézier curve”);\n #OpQW2IrBAgbwld43 $heading_linear→set_color(colors→orange);\n #EXXlLvjQZUw6pps1 $heading_linear→set_pos($heading_cubic→x, $heading_cubic→y + 50);\n #pSQtFEHjVq4S6wsF $starting_position_, $ending_position_, $control_point_1, $control_point_2 := code→get_points($board);\n #uNjc6BVBfUPjho6k $coordinates2 := records→curve_coordinates→create;\n #XexAgcX1PxdDx8oq $coordinates2→starting_position := $starting_position_;\n #WLEoNZM0WNfxd4xW $coordinates2→ending_position := $ending_position_;\n #vgYW17H3ihGbdIL7 $coordinates2→control_point_1 := $control_point_1;\n #mxOeHZrXgT2XNk4G $coordinates2→control_point_2 := $control_point_2;\n #F8B6UbbV2G2ye3xp code→set_positions_($coordinates2, $board);\n #EsADsDXYphVkY6qA $quadratic_sprite, $cubic_sprite, $linear_sprite := code→create_curve_sprites($board, $starting_position_);\n #bSf6VA3wpyq1CGdb $linear_curve := code→create_linear_curve($coordinates2→starting_position, $coordinates2→ending_position);\n #k68FnATYoq40OuNO $quadratic_curve := code→create_quadratic_curve($coordinates2→starting_position, $coordinates2→ending_position, $coordinates2→control_point_1);\n #xU1R0uQCZ1hEfS15 $cubic_curve := code→create_cubic_curve($coordinates2→starting_position, $coordinates2→ending_position, $coordinates2→control_point_1, $coordinates2→control_point_2);\n #xl3EBmkJAGabZJ9i $total := 1000;\n #iE2MeBI4ypdi9WxO for 0 ≤ i < $total do {\n #yafiaKcxvDdB1YVz $percentage := code→get_percentage($i, $total - 50);\n #qgd3sh7bL0ymaR9Q $linear_curve→t := $percentage;\n #omZI3L5vs5LUBhBo $quadratic_curve→t := code→get_percentage($i, $total);\n #xB09SKk4t12Dsueb $cubic_curve→t := $percentage;\n #sa4zWWq5qUDtqaoF $x := $linear_sprite→x;\n #zvESjCm4Asuy9djX $y := $linear_sprite→y;\n #tUosgwJ5Z36Rh8oo $position := code→get_position($linear_curve);\n #vpceeGa672Sq3J18 $linear_sprite→set_pos($position→x, $position→y);\n #B4xduxs4QSppmEdB $world→draw_line($x, $y, $linear_sprite→x, $linear_sprite→y, $linear_sprite→color, 3);\n #sFll6QZIKJS24zdV $x := $quadratic_sprite→x;\n #KOVb42z1MilCvxxU $y := $quadratic_sprite→y;\n #x22Kyr66jSIQRx0v $position := code→get_position($quadratic_curve);\n #cetl2cKiwvtgfuX2 $quadratic_sprite→set_pos($position→x, $position→y);\n #wASoeMqDMrCmaDeZ $world→draw_line($x, $y, $quadratic_sprite→x, $quadratic_sprite→y, $quadratic_sprite→color, 3);\n #dQBqLXg4Qse8qjJr $linear_curve→t := code→get_percentage($i, $total);\n #YNpfOe4nCc9uVeQk $x := $cubic_sprite→x;\n #US0LGLbfPgiuvXD0 $y := $cubic_sprite→y;\n #GYKMkR3HB3iBa3Vd $position := code→get_position($cubic_curve);\n #xqH0gZldC2eE2bu8 $cubic_sprite→set_pos($position→x, $position→y);\n #vY13h6HS0m0jxcZ4 $world→draw_line($x, $y, $cubic_sprite→x, $cubic_sprite→y, $cubic_sprite→color, 3);\n }\n #ZDPlP7rKKIEiJ355 $board→post_to_wall;\n #hhGJ3W0DgFG4d2KE time→run_after(3, $perform);\n #P7omeDlKOeqE6kW0 where perform() {\n #xJ7YfBkVmOe2fnit $duration := wall→ask_number(“Duration (seconds)?”);\n #xzKEc484zXw4Cn2O time→run_after(1, $perform2);\n #xLt82guSs45RbQOw where perform2() {\n #xI1KmvwmRPZLNw64 data→start_time := time→now;\n #xyJOeKYDgYPEJn7T data→end_time := data→start_time→add_seconds($duration);\n #AsPgpu4u0d73tSdn $board→add_on_every_frame($perform);\n #Yv3AGknK13H5Bc2y where perform() {\n #qkUsK18CvrOV40oV $x := $quadratic_sprite→x;\n #xNDo8SBQVWrg98sF $y := $quadratic_sprite→y;\n #zCBQ46tif6xyvhMt $percentage_ := time→now→subtract(data→start_time) / $duration;\n #x7J1hLrMClc5l6yc $linear_curve→t := $percentage_;\n #WSt2hWCY2mTl8Fgx $quadratic_curve→t := $percentage_;\n #nOrjWFxYIZciLsLy $cubic_curve→t := $percentage_;\n #SQquaehayr7qqP2y $position2 := code→get_position($quadratic_curve);\n #zyZzSeXLyQgvylKx $quadratic_sprite→set_pos($position2→x, $position2→y);\n #uEGuvB2edWYXXoN7 $world→draw_line($x, $y, $quadratic_sprite→x, $quadratic_sprite→y, $quadratic_sprite→color, 3);\n #RVVf6i4x7KWxfVsK $x := $cubic_sprite→x;\n #ouSLE4sSYFtnASD6 $y := $cubic_sprite→y;\n #JCEssJBFtM0R5NSa $position2 := code→get_position($cubic_curve);\n #ItTm8X26z1HADTr1 $cubic_sprite→set_pos($position2→x, $position2→y);\n #xLrNwnMwqT5TfhBL $world→draw_line($x, $y, $cubic_sprite→x, $cubic_sprite→y, $cubic_sprite→color, 3);\n #x3ZNk4yLS2JLuski $x := $linear_sprite→x;\n #xf7y4znK2ZBsw3Mg $y := $linear_sprite→y;\n #lInN15yoOxv5viDg $position2 := code→get_position($linear_curve);\n #iftETmffn52UWyN6 $linear_sprite→set_pos($position2→x, $position2→y);\n #lI4APdinnflXxmGF $world→draw_line($x, $y, $linear_sprite→x, $linear_sprite→y, $linear_sprite→color, 3);\n #Ws4ba5yoCmX0P0Wa if time→now→greater(data→end_time) then {\n #xBpe4RoTHp4Fx8iV data→start_time := time→now;\n #Q7MUzrbgeQNlSl5a data→end_time := data→start_time→add_seconds($duration);\n }\n #q69Zp4iQXu43voZA $board→update_on_wall;\n }\n }\n }\n meta private;\n meta test;\n}\n#TvhtlUTziZG2XzGy\naction get_points(#djMu4Peizo0nHHEv board: Board) returns(#KKQWn4ROgmjBF9it starting_position_: Vector3, #xrKbh12rbYv5A2Ch ending_position_: Vector3, #G0YlcOFnRfVoXc5Y control_point_1: Vector3, #x7PbVW4PjAOubF43 control_point_2: Vector3) {\n #xYaJs7C56D6rtBxj $starting_position_ := math→create_vector3(50, $board→height * .5, 0);\n #xAuacprD3DpFa03X $ending_position_ := math→create_vector3($board→width - 50, $board→height * .5, 0);\n #CU68LO3cE8XHj4gG $control_point_1 := math→create_vector3($board→width * .5, $board→height - 50, 0);\n #oYor5hbNh6Rwu4Zg $control_point_2 := math→create_vector3($board→width * .5, 50, 0);\n meta private;\n meta sync;\n}\n#fgfTCjyl12G8KS1y\naction set_positions_(#y2Zt4WPRpeDsUxuP curve_coordinates: * curve_coordinates, #sY76zkhs3Orbio4x board: Board) {\n #KHCXtfqSUmsV3ZLp // Marks the positions on the board with an eclipse (used for debugging)\n #G8PFTgvI2lzz3g3Y $starting_position_sprite := $board→create_ellipse(40, 40);\n #ddSE2BVcFWLXy0hp $starting_position_sprite→set_pos($curve_coordinates→starting_position→x, $curve_coordinates→starting_position→y);\n #mC2sTYsCTgY1OZiU $starting_position_sprite→set_color(colors→red);\n #AW4hRSSjgIrT2nKE $ending_position_sprite := $board→create_ellipse(40, 40);\n #NcN9OVhXouDGRdq3 $ending_position_sprite→set_pos($curve_coordinates→ending_position→x, $curve_coordinates→ending_position→y);\n #xOM55ElnT2ny5ux6 $ending_position_sprite→set_color(colors→green);\n #VHaBwA42B8FdDhCg if not $curve_coordinates→control_point_1→is_invalid then {\n #xw3TOoSiLD5Qx8Bj $control_point_sprite_1 := $board→create_ellipse(40, 40);\n #xzkacCMrBsAwbngC $control_point_sprite_1→set_pos($curve_coordinates→control_point_1→x, $curve_coordinates→control_point_1→y);\n #xyOx2QbdboOlIVn2 $control_point_sprite_1→set_color(colors→orange);\n }\n #xplcMlT5dC8dpFWo if not $curve_coordinates→control_point_2→is_invalid then {\n #xxb98JTJBn9UE5cH $control_point_sprite_2 := $board→create_ellipse(40, 40);\n #AATj14zOOsrfx2DO $control_point_sprite_2→set_pos($curve_coordinates→control_point_2→x, $curve_coordinates→control_point_2→y);\n #K42QQvsVF4HLhjzn $control_point_sprite_2→set_color(colors→gray);\n }\n meta private;\n meta sync;\n}\n#PL78y1hQLMFKi4e4\naction create_curve_sprites(#zCyxsx6SJ3kFY1or board: Board, #E9poXuwa3S6lBu5Y starting_position_: Vector3) returns(#x7EH9nWhY961tvD2 quadratic_sprite: Sprite, #sGKM1b3666TJMr82 cubic_sprite: Sprite, #pfouu53sThXfOaa4 linear_sprite: Sprite) {\n #sYaqdB2iht3oG4nG $quadratic_sprite := $board→create_rectangle(20, 20);\n #kQB3N9n4BXYzF6rx $quadratic_sprite→set_color(colors→black);\n #XS62MASfSwSSxzGj $quadratic_sprite→set_pos($starting_position_→x, $starting_position_→y);\n #wOHFoaTkMaG270hn $cubic_sprite := $board→create_rectangle(20, 20);\n #kj22exFE2HU74YiN $cubic_sprite→width := $quadratic_sprite→width / 2;\n #xjWTYy3bD4QPg09P $cubic_sprite→height := $quadratic_sprite→height / 2;\n #QK7xptRF2sqyIWZ1 $cubic_sprite→set_color(colors→blue);\n #i4Gl94pZNCuFJbP4 $cubic_sprite→set_pos($starting_position_→x, $starting_position_→y);\n #xrCfuCEelMDeQG43 $linear_sprite := $board→create_ellipse(20, 20);\n #xSuHXKTZ7T3C1MhQ $linear_sprite→set_pos($starting_position_→x, $starting_position_→y);\n #LDcW0UHgUZ2YnmBp $linear_sprite→set_color(colors→orange);\n meta private;\n meta sync;\n}\n#BdGhpbmca\ntable curve_coordinates {\n type = “Object”;\n persistent = false;\n fields {\n #Ghaprprj8SGpRn3U starting_position : Vector3\n #xGKC1ws0WkjjxnNF ending_position : Vector3\n #oLlK07FLkLIaTexv control_point_1 : Vector3\n #MoVW1FkYTxg1eZ7A control_point_2 : Vector3\n }\n}\n#qrZgcIJNUt5oFvpm\naction get_linear_position(#VdEhaVdwLaKZ26Lr curve: * curve) returns(#x559wFU0yAqUNo0t position: Vector3) {\n #xUBDbxo2JJazoY8G // Gets the position (x,y) on a linear bézier curve based on the time elapsed and duration (t = 0 > t < 1)\n #jmVUwsGUyLG3xPEH // T = [0,1] (percentage of curve)\n #boUY6nsYHVSaTBko $curve→t := code→get_t_normalized($curve→t);\n #gU143MDtuLVv4A5d // (1-t)p0 + tp1\n #x7yWh1tr7RFweJeE $x := ((1 - $curve→t) * $curve→curve_coordinates→starting_position→x) + ($curve→t * $curve→curve_coordinates→ending_position→x);\n #roLW00pDYj4j3sgK $y := ((1 - $curve→t) * $curve→curve_coordinates→starting_position→y) + ($curve→t * $curve→curve_coordinates→ending_position→y);\n #qAcGvDorAY1tZK9l $position := math→create_vector3($x, $y, 0);\n meta private;\n meta sync;\n}\n#LpShD2CtzbNAlnPR\naction get_quadratic_position(#QyFst7XekNLW2rwQ curve: * curve) returns(#X4JqmaQ4z0QD4OgY position: Vector3) {\n #CLQ8ix41kVzLotej // Gets the position (x,y) on a quadratic bézier curve based on the time elapsed and duration (t = 0 > t < 1)\n #c8QkBRmpOLb1l76e // T = [0,1] (percentage of curve)\n #xrIFhSxvpi3OnyNF $curve→t := code→get_t_normalized($curve→t);\n #ZgWbfXTmjRZ9Azqs // P = (1-t)2•P1 + 2•(1-t) •t•C + t2•P2\n #xTQdK5SV4B4se1cX $x := math→pow((1 - $curve→t), 2) * $curve→curve_coordinates→starting_position→x + (2 * (1 - $curve→t) * $curve→t * $curve→curve_coordinates→control_point_1→x) + (math→pow($curve→t, 2) * $curve→curve_coordinates→ending_position→x);\n #iDrGm8K2rZiyXrk1 $y := math→pow((1 - $curve→t), 2) * $curve→curve_coordinates→starting_position→y + (2 * (1 - $curve→t) * $curve→t * $curve→curve_coordinates→control_point_1→y) + (math→pow($curve→t, 2) * $curve→curve_coordinates→ending_position→y);\n #SMNk1lEOwBOz4JMn $position := math→create_vector3($x, $y, 0);\n meta private;\n meta sync;\n}\n#nhfu28vQIJRdRJPD\naction get_cubic_position(#tZ9GVMgXEqNePWJb curve: * curve) returns(#ila22l2mwCFg7Wo3 position: Vector3) {\n #hYEL21UryJrRusid // \n #dqMmeTaqegzCEaVY // Gets the position (x,y) on a cubic bézier curve based on the time elapsed and duration (t = 0 > t < 1)\n #xPBQBUIFVY1N9kf8 // T = [0,1] (percentage of curve)\n #v4zY5qb23EPsQAp2 $curve→t := code→get_t_normalized($curve→t);\n #rBGHDQoiOdmzJxH4 // P = (1-t)3•P1 + 3•(1-t)2•t•C1 + 3•(1-t)•t2•C2 + t3•P2\n #qhrZRThuNw4p0Ijk $x := (math→pow(1 - $curve→t, 3) * $curve→curve_coordinates→starting_position→x) + (3 * math→pow(1 - $curve→t, 2) * $curve→t * $curve→curve_coordinates→control_point_1→x) + (3 * (1 - $curve→t) * math→pow($curve→t, 2) * $curve→curve_coordinates→control_point_2→x) + (math→pow($curve→t, 3) * $curve→curve_coordinates→ending_position→x);\n #whtHsUYMcrgzkw2D $y := (math→pow(1 - $curve→t, 3) * $curve→curve_coordinates→starting_position→y) + (3 * math→pow(1 - $curve→t, 2) * $curve→t * $curve→curve_coordinates→control_point_1→y) + (3 * (1 - $curve→t) * math→pow($curve→t, 2) * $curve→curve_coordinates→control_point_2→y) + (math→pow($curve→t, 3) * $curve→curve_coordinates→ending_position→y);\n #xAUIk1mstjV2IhO1 $position := math→create_vector3($x, $y, 0);\n meta private;\n meta sync;\n}\n#xuXpAJPgL2DxDxYZ\naction get_t_normalized(#Z47arMG72YPSGHss t: Number) returns(#yZZfE1vlnyU7ERdS t_normalized: Number) {\n #cFAPQsXIDKZCOD9y $t_normalized := $t;\n #j184mZTSy5Bm272H if $t_normalized > 1 then {\n #j1ZbbEt2eOn28zI1 $t_normalized := 1;\n }\n else { #EAdR1p9xGBgELYzA if $t < 0 then {\n #O64r52Mi9CyMfqpD $t := 0;\n }\n else { } } \n meta private;\n meta sync;\n}\n#vwry4nKnJq6R1cA5\naction get_percentage(#ltQxGTqNXtW2FOJc iteration: Number, #tZ94FbfuJo2SBPw3 total: Number) returns(#xVhdwcW9oJXCRoee percentage: Number) {\n #g1hzvYy14iEKqdTA // percentage = iteration / total\n #x8joQ2tXhrM6pumn $percentage := $iteration / $total;\n meta private;\n meta sync;\n}\n#YaPjwGRW5n1wfB4S\naction starting_position(#AsgYNBdtYgLy0nj8 curve_coordinates: * curve_coordinates) returns(#hm2hX2o46M6p9z20 starting_position: Vector3) {\n #hpfBVpQyhADvwMEH $starting_position := math→create_vector3($curve_coordinates→starting_position→x, $curve_coordinates→starting_position→y, 0);\n meta sync;\n}\n#HySlv4sJTQcbGm2B\naction ending_position(#jLEAP2LxrHBDnMiB curve_coordinates: * curve_coordinates) returns(#t4ZSzOO5NVXPXBe4 ending_position: Vector3) {\n #nGLWnCIgwQxwFB82 $ending_position := math→create_vector3($curve_coordinates→ending_position→x, $curve_coordinates→ending_position→y, 0);\n meta sync;\n}\n#f8BiKmgQ4a1C7hYI\naction control_point_1(#eO4RtGIrcCS7e5Q4 curve_coordinates: * curve_coordinates) returns(#mePeLc37tFTxephe control_point_1: Vector3) {\n #kXqNtXv64161iysj // Can return invalid -> vector3\n #XAF9ojeAwXKqR2jM $control_point_1 := invalid→vector3;\n #xlkdeQ1UkdN8cSBU if not $curve_coordinates→control_point_1→is_invalid then {\n #rDe3u8DeOpnlOWAy $control_point_1 := math→create_vector3($curve_coordinates→control_point_1→x, $curve_coordinates→control_point_1→y, 0);\n }\n meta sync;\n}\n#pODw76O8kXAsc1rU\naction control_point_2(#zNpLSKxz42YrzpBX curve_coordinates: * curve_coordinates) returns(#xt4ZCA2r0mNND6l6 control_point_2: Vector3) {\n #amoDJ1eE3rgJypXb // Can return invalid -> vector3\n #xQD5V8OI7MpsmXPR $control_point_2 := invalid→vector3;\n #FoPQ8tZ5pcK1z55C if not $curve_coordinates→control_point_2→is_invalid then {\n #h2CENz8Lf4CCfNXO $control_point_2 := math→create_vector3($curve_coordinates→control_point_2→x, $curve_coordinates→control_point_2→y, 0);\n }\n meta sync;\n}\n#vdkGV2qZXW7LAG9l\naction set_starting_position(#yQTzM0ByW2XOpNOi curve_coordinates: * curve_coordinates, #xCuwSTdArcU6gac6 starting_position: Vector3) {\n #HvR20r33AbrDvS4v $curve_coordinates→starting_position := $starting_position;\n meta sync;\n}\n#Hl0kN2P4vKwXtaQC\naction set_ending_position(#NfRc04X3uopqVcwI curve_coordinates: * curve_coordinates, #j0tD1qQLoagc8bn6 ending_position: Vector3) {\n #Oim2RIBjCNtk4VH7 $curve_coordinates→ending_position := $ending_position;\n meta sync;\n}\n#xLMBkcPQKv6oyCZT\naction set_control_point_1(#fbG4d3mVPNna056B curve_coordinates: * curve_coordinates, #RlAHLwJssLVg0H6y control_point_1: Vector3) {\n #lE3eClqWUGCRuBm2 $curve_coordinates→control_point_1 := $control_point_1;\n meta sync;\n}\n#xs5VSqG5ylf6hSiS\naction set_control_point_2(#OEY4sB9VB7pEvkbt curve_coordinates: * curve_coordinates, #JZWG1cVOEcpeOuDI control_point_2: Vector3) {\n #pYznP6smote5FfHE $curve_coordinates→control_point_2 := $control_point_2;\n meta sync;\n}\n#fATNKUyERCEta2cQ\ntable curve {\n type = “Object”;\n persistent = false;\n fields {\n #ppUuSyAWkc2LBOkl curve_type : * curve_type\n #SW9cNy5ZPJw3WsDC curve_coordinates : * curve_coordinates\n #BknYaOvkqeHQwBgl t : Number\n }\n}\n#xk986ORLjlpbTDuF\ntable curve_type {\n type = “Object”;\n persistent = false;\n fields {\n #W7vXqR6s7qF98Cs1 linear : Boolean\n #xtx4uiOHC5QwIOey quadratic : Boolean\n #xNRi3OXdgAOGUPOy cubic : Boolean\n }\n}\n#x7pQVfyVNAfv6MAh\naction coordinates(#VXs6zTgQT1UpFP2D curve: * curve) returns(#Whx3Nl4cybDUNgPF curve_coordinates: * curve_coordinates) {\n #MEx33U2Iin4ZlFWS $curve_coordinates := $curve→curve_coordinates;\n meta sync;\n}\n#b9jn7yvQIG6t6DfR\naction get_curve_type(#Hg72Sg3Eku7ZFV5t curve: * curve) returns(#qmxx86ggPXneJ6ct curve_type: * curve_type) {\n #khx0unplE14QdyNy $curve_type := $curve→curve_type;\n meta sync;\n}\n#FEcPoE2AI9MMGSdO\naction create_linear_curve(#xvLrqSHAkIH3lLx2 starting_position: Vector3, #xlOHhc2mUEvb3zjC ending_position: Vector3) returns(#xMOwiR3qnMDef7Xf linear_curve: * curve) {\n #VVIGxsbR2w5KC4gK if $starting_position→is_invalid then {\n #HUOrE4UlhgwFKBGs $starting_position := math→create_vector3(0, 0, 0);\n }\n #t4VxqQ1nbxaCBRhL if $ending_position→is_invalid then {\n #xAmvbjn7GxSkVX7z $ending_position := $starting_position;\n }\n #tNQwD3I244z5Gc7n $linear_curve := records→curve→create;\n #oSLBPyayxoZBfaED $linear_curve→curve_coordinates := records→curve_coordinates→create;\n #nwd2iNGy5jA8kZ0u $linear_curve→curve_type := records→curve_type→create;\n #f2JoeR12muo2QiDD $linear_curve→curve_coordinates→starting_position := $starting_position;\n #cyk4aAX926M7y1ls $linear_curve→curve_coordinates→ending_position := $ending_position;\n #mU4X4pWVbTuqH6Tr $linear_curve→curve_type→linear := true;\n meta sync;\n}\n#ibCTjaingbo8wyvI\naction create_quadratic_curve(#mO6VCyMhRLvoD2VJ starting_position: Vector3, #tBuwHIi2wctLx2hV ending_position: Vector3, #C44j5pXlUfcj0hmG control_point_1: Vector3) returns(#rS1ZMM6IUpFOo9Ph quadratic_curve: * curve) {\n #o4rHorpH6fh0AIpz if $starting_position→is_invalid then {\n #IEMb4LgmLaBJhhqi $starting_position := math→create_vector3(0, 0, 0);\n }\n #Xrx7b0MFUgSzX4HX if $ending_position→is_invalid then {\n #YVnWYRR322v70VOa $ending_position := $starting_position;\n }\n #lyyXnHihOZ4TknSe if $control_point_1→is_invalid then {\n #jpaADE3jQe39TVbY $control_point_1 := $ending_position;\n }\n #wkh4VjTAjaoufeO2 $quadratic_curve := records→curve→create;\n #QhyCPR4Zdh4NOY4N $quadratic_curve→curve_coordinates := records→curve_coordinates→create;\n #gBIN0S28sWXUykZu $quadratic_curve→curve_type := records→curve_type→create;\n #tvMxHHmSTM7PHa94 $quadratic_curve→curve_coordinates→starting_position := $starting_position;\n #X28Nsr3XOITnaBkv $quadratic_curve→curve_coordinates→ending_position := $ending_position;\n #DIdl2N8DcxYkv2Hg $quadratic_curve→curve_coordinates→control_point_1 := $control_point_1;\n #f5hmsWcp4S2eN19O $quadratic_curve→curve_type→quadratic := true;\n meta sync;\n}\n#t0C4DY22JLDdEscy\naction create_cubic_curve(#x6h6TaaPgHKDO7gq starting_position: Vector3, #gDJ4gJkhHizaqFlX ending_position: Vector3, #TmB5M8NjoJ2lBs6k control_point_1: Vector3, #U3IXXo25ooOmMVic control_point_2: Vector3) returns(#s3umkBL0FVZXRf8P cubic_curve: * curve) {\n #HaD455QFTu9Kmmh4 if $starting_position→is_invalid then {\n #o8ZFUsSrt2vtI5ih $starting_position := math→create_vector3(0, 0, 0);\n }\n #nyzhyZnLRkyTfOoW if $ending_position→is_invalid then {\n #Wq8bbWfOUMhV0vfT $ending_position := $starting_position;\n }\n #bJQFriL4pT29cC9S if $control_point_1→is_invalid then {\n #yWYpTwBQD34GR2lw $control_point_1 := $ending_position;\n }\n #xtBN4XnGyabP2V4i if $control_point_2→is_invalid then {\n #qtbvV8FoH4YA42lq $control_point_2 := $control_point_1;\n }\n #k1j5hzCZVUqCnuNG $cubic_curve := records→curve→create;\n #G7GZ7RYUq3kqi07I $cubic_curve→curve_coordinates := records→curve_coordinates→create;\n #vUmEjsFYv6OcGSUo $cubic_curve→curve_type := records→curve_type→create;\n #UG2y2tA81SITL4gf $cubic_curve→curve_coordinates→starting_position := $starting_position;\n #xn0GjvZkxU8kxaVI $cubic_curve→curve_coordinates→ending_position := $ending_position;\n #JemUCWZWu1SOwf3C $cubic_curve→curve_coordinates→control_point_1 := $control_point_1;\n #ECaVZA9btnoWuJBc $cubic_curve→curve_coordinates→control_point_2 := $control_point_2;\n #YrBn1KMZrX4TgA4W $cubic_curve→curve_type→cubic := true;\n meta sync;\n}\n#ZNA0dlqurm6004pA\naction t(#F59T6fonrwFyleDh curve: * curve) returns(#USuMT2kcJHPTy44W t: Number) {\n #BNPB894IxhyW2HQ1 $t := $curve→t;\n meta sync;\n}\n#xQF020RkBGVVyk6v\naction set_t(#ITrUtLENKqcpiKhS curve: * curve, #Mz8zpSMjmtRhfsM4 t: Number) {\n #lx6BQ3uh6U0aVh2D $t_normalized := code→get_t_normalized($t);\n #xErsRc442pI8MIjF $curve→t := $t_normalized;\n meta sync;\n}\n#Iz7r3PDIXM9pk1P8\naction get_position(#MpLGuVN2omjENOH3 curve: * curve) returns(#H4A3XKIRQZ2cIyWt position: Vector3) {\n #IOmUE5YxcjOVquOs $position := math→create_vector3(0, 0, 0);\n #CSD4EfBjFpHZKBUw if $curve→curve_type→cubic then {\n #nAS7fjvrpgpk7Zfy $position := code→get_cubic_position($curve);\n }\n else { #rs9Heg28m8JASiSv if $curve→curve_type→quadratic then {\n #mi8OsJj8gKmHb0IG $position := code→get_quadratic_position($curve);\n }\n else {\n #uo21j9pPEbxAz5I7 $position := code→get_linear_position($curve);\n }\n } \n meta sync;\n}\n#wpNIywjItgaEAdq6\nvar start_time : DateTime {\n transient = true;\n}\n#x0rG3nPQf2YeS85f\nvar end_time : DateTime {\n transient = true;\n}\n#lPEZEiWBOMYwuxLq\naction linear(#xy4JLw82GtHHd58X curve_type: * curve_type) returns(#XB9UN4FlShhEoIe1 linear: Boolean) {\n #WUCE4ARYE4M1gBwI $linear := $curve_type→linear;\n}\n#xUX85M3gzxDg4Wph\naction quadratic(#xKhbBw7tJMeehdtc curve_type: * curve_type) returns(#IHwmsqecNh4S34kx quadratic: Boolean) {\n #xaJ4o1vcTayTqS3I $quadratic := $curve_type→quadratic;\n}\n#hq5NH0n42OoOOXR6\naction cubic(#H5TlrqF6um1uFOcm curve_type: * curve_type) returns(#KlcoCV4ZuYD303RB cubic: Boolean) {\n #IRH6QQFaltKJpWrz $cubic := $curve_type→cubic;\n}\n”
}
]
}

2 Likes

What fun code! I love it.

It’s also fun to see Touch Develop code again. It’s been a very long time for me. I’ve forgotten how different the language is; it’s much more like Pascal.

I’d be interested to see if any of the code for the Touch Develop parser still exists. I don’t think this can be done with a simple line-by-line transpiler, since the Touch Develop environment is so different from the MakeCode Arcade environment.

I’m going to ponder on this and stare at your code a bit more to see how I’d approach this. In the meantime, perhaps we’ll hear from members of the Touch Develop team with their thoughts and perspective.

2 Likes

Thanks Alex,

I used the Bezier curves to move the enemies in a space invaders game. I would like to make this again, but also to make extensions so that others might be able to use the animations. TypeScript is new for me, as is Javascript, but with experience in C#, the transition shouldn’t be too hard. Any help in parsing this is appreciated, even if it is only formatting the Touch Develop code into something readable.

Well, at the very least, I can help you with that last request!

Touch Develop code
{
“scripts”: [
{
“header”: {
“cloudId”: “touchdevelop.com”,
“scriptId”: “hnvib”,
“userId”: “cqeba”,
“status”: “published”,
“lastUse”: 1526676178,
“editor”: “touchdevelop”,
“name”: “Bezier curves”,
“comment”: “Formulas for calculating a linear, quadratic and cubic bezier curves were taken from:

http://caffeineowl.com/graphics/2d/vectorial/bezierintro.html

http://en.wikipedia.org/wiki/Bézier_curve”
},
“source”: “meta version “v2.2,js,ctx,refs,localcloud,unicodemodel,allasync”;
meta name “Bezier curves”;
meta icon “Share”;
meta color “#ffff0038”;
meta rootId “xu5kuZwm7kGpcsE4f4u05jDK”;
meta isLibrary “yes”;
meta allowExport “yes”;
meta hasIds “yes”;
meta platform “current”;
meta parentIds “”;
// Formulas for calculating a linear, quadratic and cubic bezier curves were taken from:
// 
// http://caffeineowl.com/graphics/2d/vectorial/bezierintro.html
// 
// http://en.wikipedia.org/wiki/Bézier_curve
#OU78BBXCakSog0cs
action main() {
 #M5PmWnaV1xVsDZc5 $board := media→create_landscape_board(800, 480);
 #LXJmho39gfcIFoHk $world := media→create_picture($board→width, $board→height);
 #N9FE1nZi9BCXCvhJ $board→set_background_picture($world);
 #xZqnFOalBAXGxhTq $heading_quadratic := $board→create_text(100, 20, 30, “Quadratic bézier curve”);
 #V4b15pnMPn2C3GkT $heading_quadratic→set_color(colors→black);
 #Y1AJeCftQeY5Gco3 $heading_quadratic→set_pos($board→width * .15, $board→height * .1);
 #skE87SD4hbacAG23 $heading_cubic := $board→create_text(100, 20, 30, “Cubic bézier curve”);
 #EWM2twfjzMR9OIj7 $heading_cubic→set_color(colors→blue);
 #CUaItpvU7hiPqC7G $heading_cubic→set_pos($heading_quadratic→x, $heading_quadratic→y + 50);
 #EY6KuXTB6A5VOOOO $heading_linear := $board→create_text(100, 20, 30, “Linear bézier curve”);
 #OpQW2IrBAgbwld43 $heading_linear→set_color(colors→orange);
 #EXXlLvjQZUw6pps1 $heading_linear→set_pos($heading_cubic→x, $heading_cubic→y + 50);
 #pSQtFEHjVq4S6wsF $starting_position_, $ending_position_, $control_point_1, $control_point_2 := code→get_points($board);
 #uNjc6BVBfUPjho6k $coordinates2 := records→curve_coordinates→create;
 #XexAgcX1PxdDx8oq $coordinates2→starting_position := $starting_position_;
 #WLEoNZM0WNfxd4xW $coordinates2→ending_position := $ending_position_;
 #vgYW17H3ihGbdIL7 $coordinates2→control_point_1 := $control_point_1;
 #mxOeHZrXgT2XNk4G $coordinates2→control_point_2 := $control_point_2;
 #F8B6UbbV2G2ye3xp code→set_positions_($coordinates2, $board);
 #EsADsDXYphVkY6qA $quadratic_sprite, $cubic_sprite, $linear_sprite := code→create_curve_sprites($board, $starting_position_);
 #bSf6VA3wpyq1CGdb $linear_curve := code→create_linear_curve($coordinates2→starting_position, $coordinates2→ending_position);
 #k68FnATYoq40OuNO $quadratic_curve := code→create_quadratic_curve($coordinates2→starting_position, $coordinates2→ending_position, $coordinates2→control_point_1);
 #xU1R0uQCZ1hEfS15 $cubic_curve := code→create_cubic_curve($coordinates2→starting_position, $coordinates2→ending_position, $coordinates2→control_point_1, $coordinates2→control_point_2);
 #xl3EBmkJAGabZJ9i $total := 1000;
 #iE2MeBI4ypdi9WxO for 0 ≤ i < $total do {
 #yafiaKcxvDdB1YVz $percentage := code→get_percentage($i, $total - 50);
 #qgd3sh7bL0ymaR9Q $linear_curve→t := $percentage;
 #omZI3L5vs5LUBhBo $quadratic_curve→t := code→get_percentage($i, $total);
 #xB09SKk4t12Dsueb $cubic_curve→t := $percentage;
 #sa4zWWq5qUDtqaoF $x := $linear_sprite→x;
 #zvESjCm4Asuy9djX $y := $linear_sprite→y;
 #tUosgwJ5Z36Rh8oo $position := code→get_position($linear_curve);
 #vpceeGa672Sq3J18 $linear_sprite→set_pos($position→x, $position→y);
 #B4xduxs4QSppmEdB $world→draw_line($x, $y, $linear_sprite→x, $linear_sprite→y, $linear_sprite→color, 3);
 #sFll6QZIKJS24zdV $x := $quadratic_sprite→x;
 #KOVb42z1MilCvxxU $y := $quadratic_sprite→y;
 #x22Kyr66jSIQRx0v $position := code→get_position($quadratic_curve);
 #cetl2cKiwvtgfuX2 $quadratic_sprite→set_pos($position→x, $position→y);
 #wASoeMqDMrCmaDeZ $world→draw_line($x, $y, $quadratic_sprite→x, $quadratic_sprite→y, $quadratic_sprite→color, 3);
 #dQBqLXg4Qse8qjJr $linear_curve→t := code→get_percentage($i, $total);
 #YNpfOe4nCc9uVeQk $x := $cubic_sprite→x;
 #US0LGLbfPgiuvXD0 $y := $cubic_sprite→y;
 #GYKMkR3HB3iBa3Vd $position := code→get_position($cubic_curve);
 #xqH0gZldC2eE2bu8 $cubic_sprite→set_pos($position→x, $position→y);
 #vY13h6HS0m0jxcZ4 $world→draw_line($x, $y, $cubic_sprite→x, $cubic_sprite→y, $cubic_sprite→color, 3);
 }
 #ZDPlP7rKKIEiJ355 $board→post_to_wall;
 #hhGJ3W0DgFG4d2KE time→run_after(3, $perform);
 #P7omeDlKOeqE6kW0 where perform() {
 #xJ7YfBkVmOe2fnit $duration := wall→ask_number(“Duration (seconds)?”);
 #xzKEc484zXw4Cn2O time→run_after(1, $perform2);
 #xLt82guSs45RbQOw where perform2() {
 #xI1KmvwmRPZLNw64 data→start_time := time→now;
 #xyJOeKYDgYPEJn7T data→end_time := data→start_time→add_seconds($duration);
 #AsPgpu4u0d73tSdn $board→add_on_every_frame($perform);
 #Yv3AGknK13H5Bc2y where perform() {
 #qkUsK18CvrOV40oV $x := $quadratic_sprite→x;
 #xNDo8SBQVWrg98sF $y := $quadratic_sprite→y;
 #zCBQ46tif6xyvhMt $percentage_ := time→now→subtract(data→start_time) / $duration;
 #x7J1hLrMClc5l6yc $linear_curve→t := $percentage_;
 #WSt2hWCY2mTl8Fgx $quadratic_curve→t := $percentage_;
 #nOrjWFxYIZciLsLy $cubic_curve→t := $percentage_;
 #SQquaehayr7qqP2y $position2 := code→get_position($quadratic_curve);
 #zyZzSeXLyQgvylKx $quadratic_sprite→set_pos($position2→x, $position2→y);
 #uEGuvB2edWYXXoN7 $world→draw_line($x, $y, $quadratic_sprite→x, $quadratic_sprite→y, $quadratic_sprite→color, 3);
 #RVVf6i4x7KWxfVsK $x := $cubic_sprite→x;
 #ouSLE4sSYFtnASD6 $y := $cubic_sprite→y;
 #JCEssJBFtM0R5NSa $position2 := code→get_position($cubic_curve);
 #ItTm8X26z1HADTr1 $cubic_sprite→set_pos($position2→x, $position2→y);
 #xLrNwnMwqT5TfhBL $world→draw_line($x, $y, $cubic_sprite→x, $cubic_sprite→y, $cubic_sprite→color, 3);
 #x3ZNk4yLS2JLuski $x := $linear_sprite→x;
 #xf7y4znK2ZBsw3Mg $y := $linear_sprite→y;
 #lInN15yoOxv5viDg $position2 := code→get_position($linear_curve);
 #iftETmffn52UWyN6 $linear_sprite→set_pos($position2→x, $position2→y);
 #lI4APdinnflXxmGF $world→draw_line($x, $y, $linear_sprite→x, $linear_sprite→y, $linear_sprite→color, 3);
 #Ws4ba5yoCmX0P0Wa if time→now→greater(data→end_time) then {
 #xBpe4RoTHp4Fx8iV data→start_time := time→now;
 #Q7MUzrbgeQNlSl5a data→end_time := data→start_time→add_seconds($duration);
 }
 #q69Zp4iQXu43voZA $board→update_on_wall;
 }
 }
 }
 meta private;
 meta test;
}
#TvhtlUTziZG2XzGy
action get_points(#djMu4Peizo0nHHEv board: Board) returns(#KKQWn4ROgmjBF9it starting_position_: Vector3, #xrKbh12rbYv5A2Ch ending_position_: Vector3, #G0YlcOFnRfVoXc5Y control_point_1: Vector3, #x7PbVW4PjAOubF43 control_point_2: Vector3) {
 #xYaJs7C56D6rtBxj $starting_position_ := math→create_vector3(50, $board→height * .5, 0);
 #xAuacprD3DpFa03X $ending_position_ := math→create_vector3($board→width - 50, $board→height * .5, 0);
 #CU68LO3cE8XHj4gG $control_point_1 := math→create_vector3($board→width * .5, $board→height - 50, 0);
 #oYor5hbNh6Rwu4Zg $control_point_2 := math→create_vector3($board→width * .5, 50, 0);
 meta private;
 meta sync;
}
#fgfTCjyl12G8KS1y
action set_positions_(#y2Zt4WPRpeDsUxuP curve_coordinates: * curve_coordinates, #sY76zkhs3Orbio4x board: Board) {
 #KHCXtfqSUmsV3ZLp // Marks the positions on the board with an eclipse (used for debugging)
 #G8PFTgvI2lzz3g3Y $starting_position_sprite := $board→create_ellipse(40, 40);
 #ddSE2BVcFWLXy0hp $starting_position_sprite→set_pos($curve_coordinates→starting_position→x, $curve_coordinates→starting_position→y);
 #mC2sTYsCTgY1OZiU $starting_position_sprite→set_color(colors→red);
 #AW4hRSSjgIrT2nKE $ending_position_sprite := $board→create_ellipse(40, 40);
 #NcN9OVhXouDGRdq3 $ending_position_sprite→set_pos($curve_coordinates→ending_position→x, $curve_coordinates→ending_position→y);
 #xOM55ElnT2ny5ux6 $ending_position_sprite→set_color(colors→green);
 #VHaBwA42B8FdDhCg if not $curve_coordinates→control_point_1→is_invalid then {
 #xw3TOoSiLD5Qx8Bj $control_point_sprite_1 := $board→create_ellipse(40, 40);
 #xzkacCMrBsAwbngC $control_point_sprite_1→set_pos($curve_coordinates→control_point_1→x, $curve_coordinates→control_point_1→y);
 #xyOx2QbdboOlIVn2 $control_point_sprite_1→set_color(colors→orange);
 }
 #xplcMlT5dC8dpFWo if not $curve_coordinates→control_point_2→is_invalid then {
 #xxb98JTJBn9UE5cH $control_point_sprite_2 := $board→create_ellipse(40, 40);
 #AATj14zOOsrfx2DO $control_point_sprite_2→set_pos($curve_coordinates→control_point_2→x, $curve_coordinates→control_point_2→y);
 #K42QQvsVF4HLhjzn $control_point_sprite_2→set_color(colors→gray);
 }
 meta private;
 meta sync;
}
#PL78y1hQLMFKi4e4
action create_curve_sprites(#zCyxsx6SJ3kFY1or board: Board, #E9poXuwa3S6lBu5Y starting_position_: Vector3) returns(#x7EH9nWhY961tvD2 quadratic_sprite: Sprite, #sGKM1b3666TJMr82 cubic_sprite: Sprite, #pfouu53sThXfOaa4 linear_sprite: Sprite) {
 #sYaqdB2iht3oG4nG $quadratic_sprite := $board→create_rectangle(20, 20);
 #kQB3N9n4BXYzF6rx $quadratic_sprite→set_color(colors→black);
 #XS62MASfSwSSxzGj $quadratic_sprite→set_pos($starting_position_→x, $starting_position_→y);
 #wOHFoaTkMaG270hn $cubic_sprite := $board→create_rectangle(20, 20);
 #kj22exFE2HU74YiN $cubic_sprite→width := $quadratic_sprite→width / 2;
 #xjWTYy3bD4QPg09P $cubic_sprite→height := $quadratic_sprite→height / 2;
 #QK7xptRF2sqyIWZ1 $cubic_sprite→set_color(colors→blue);
 #i4Gl94pZNCuFJbP4 $cubic_sprite→set_pos($starting_position_→x, $starting_position_→y);
 #xrCfuCEelMDeQG43 $linear_sprite := $board→create_ellipse(20, 20);
 #xSuHXKTZ7T3C1MhQ $linear_sprite→set_pos($starting_position_→x, $starting_position_→y);
 #LDcW0UHgUZ2YnmBp $linear_sprite→set_color(colors→orange);
 meta private;
 meta sync;
}
#BdGhpbmca
table curve_coordinates {
 type = “Object”;
 persistent = false;
 fields {
 #Ghaprprj8SGpRn3U starting_position : Vector3
 #xGKC1ws0WkjjxnNF ending_position : Vector3
 #oLlK07FLkLIaTexv control_point_1 : Vector3
 #MoVW1FkYTxg1eZ7A control_point_2 : Vector3
 }
}
#qrZgcIJNUt5oFvpm
action get_linear_position(#VdEhaVdwLaKZ26Lr curve: * curve) returns(#x559wFU0yAqUNo0t position: Vector3) {
 #xUBDbxo2JJazoY8G // Gets the position (x,y) on a linear bézier curve based on the time elapsed and duration (t = 0 > t < 1)
 #jmVUwsGUyLG3xPEH // T = [0,1] (percentage of curve)
 #boUY6nsYHVSaTBko $curve→t := code→get_t_normalized($curve→t);
 #gU143MDtuLVv4A5d // (1-t)p0 + tp1
 #x7yWh1tr7RFweJeE $x := ((1 - $curve→t) * $curve→curve_coordinates→starting_position→x) + ($curve→t * $curve→curve_coordinates→ending_position→x);
 #roLW00pDYj4j3sgK $y := ((1 - $curve→t) * $curve→curve_coordinates→starting_position→y) + ($curve→t * $curve→curve_coordinates→ending_position→y);
 #qAcGvDorAY1tZK9l $position := math→create_vector3($x, $y, 0);
 meta private;
 meta sync;
}
#LpShD2CtzbNAlnPR
action get_quadratic_position(#QyFst7XekNLW2rwQ curve: * curve) returns(#X4JqmaQ4z0QD4OgY position: Vector3) {
 #CLQ8ix41kVzLotej // Gets the position (x,y) on a quadratic bézier curve based on the time elapsed and duration (t = 0 > t < 1)
 #c8QkBRmpOLb1l76e // T = [0,1] (percentage of curve)
 #xrIFhSxvpi3OnyNF $curve→t := code→get_t_normalized($curve→t);
 #ZgWbfXTmjRZ9Azqs // P = (1-t)2•P1 + 2•(1-t) •t•C + t2•P2
 #xTQdK5SV4B4se1cX $x := math→pow((1 - $curve→t), 2) * $curve→curve_coordinates→starting_position→x + (2 * (1 - $curve→t) * $curve→t * $curve→curve_coordinates→control_point_1→x) + (math→pow($curve→t, 2) * $curve→curve_coordinates→ending_position→x);
 #iDrGm8K2rZiyXrk1 $y := math→pow((1 - $curve→t), 2) * $curve→curve_coordinates→starting_position→y + (2 * (1 - $curve→t) * $curve→t * $curve→curve_coordinates→control_point_1→y) + (math→pow($curve→t, 2) * $curve→curve_coordinates→ending_position→y);
 #SMNk1lEOwBOz4JMn $position := math→create_vector3($x, $y, 0);
 meta private;
 meta sync;
}
#nhfu28vQIJRdRJPD
action get_cubic_position(#tZ9GVMgXEqNePWJb curve: * curve) returns(#ila22l2mwCFg7Wo3 position: Vector3) {
 #hYEL21UryJrRusid // 
 #dqMmeTaqegzCEaVY // Gets the position (x,y) on a cubic bézier curve based on the time elapsed and duration (t = 0 > t < 1)
 #xPBQBUIFVY1N9kf8 // T = [0,1] (percentage of curve)
 #v4zY5qb23EPsQAp2 $curve→t := code→get_t_normalized($curve→t);
 #rBGHDQoiOdmzJxH4 // P = (1-t)3•P1 + 3•(1-t)2•t•C1 + 3•(1-t)•t2•C2 + t3•P2
 #qhrZRThuNw4p0Ijk $x := (math→pow(1 - $curve→t, 3) * $curve→curve_coordinates→starting_position→x) + (3 * math→pow(1 - $curve→t, 2) * $curve→t * $curve→curve_coordinates→control_point_1→x) + (3 * (1 - $curve→t) * math→pow($curve→t, 2) * $curve→curve_coordinates→control_point_2→x) + (math→pow($curve→t, 3) * $curve→curve_coordinates→ending_position→x);
 #whtHsUYMcrgzkw2D $y := (math→pow(1 - $curve→t, 3) * $curve→curve_coordinates→starting_position→y) + (3 * math→pow(1 - $curve→t, 2) * $curve→t * $curve→curve_coordinates→control_point_1→y) + (3 * (1 - $curve→t) * math→pow($curve→t, 2) * $curve→curve_coordinates→control_point_2→y) + (math→pow($curve→t, 3) * $curve→curve_coordinates→ending_position→y);
 #xAUIk1mstjV2IhO1 $position := math→create_vector3($x, $y, 0);
 meta private;
 meta sync;
}
#xuXpAJPgL2DxDxYZ
action get_t_normalized(#Z47arMG72YPSGHss t: Number) returns(#yZZfE1vlnyU7ERdS t_normalized: Number) {
 #cFAPQsXIDKZCOD9y $t_normalized := $t;
 #j184mZTSy5Bm272H if $t_normalized > 1 then {
 #j1ZbbEt2eOn28zI1 $t_normalized := 1;
 }
 else { #EAdR1p9xGBgELYzA if $t < 0 then {
 #O64r52Mi9CyMfqpD $t := 0;
 }
 else { } } 
 meta private;
 meta sync;
}
#vwry4nKnJq6R1cA5
action get_percentage(#ltQxGTqNXtW2FOJc iteration: Number, #tZ94FbfuJo2SBPw3 total: Number) returns(#xVhdwcW9oJXCRoee percentage: Number) {
 #g1hzvYy14iEKqdTA // percentage = iteration / total
 #x8joQ2tXhrM6pumn $percentage := $iteration / $total;
 meta private;
 meta sync;
}
#YaPjwGRW5n1wfB4S
action starting_position(#AsgYNBdtYgLy0nj8 curve_coordinates: * curve_coordinates) returns(#hm2hX2o46M6p9z20 starting_position: Vector3) {
 #hpfBVpQyhADvwMEH $starting_position := math→create_vector3($curve_coordinates→starting_position→x, $curve_coordinates→starting_position→y, 0);
 meta sync;
}
#HySlv4sJTQcbGm2B
action ending_position(#jLEAP2LxrHBDnMiB curve_coordinates: * curve_coordinates) returns(#t4ZSzOO5NVXPXBe4 ending_position: Vector3) {
 #nGLWnCIgwQxwFB82 $ending_position := math→create_vector3($curve_coordinates→ending_position→x, $curve_coordinates→ending_position→y, 0);
 meta sync;
}
#f8BiKmgQ4a1C7hYI
action control_point_1(#eO4RtGIrcCS7e5Q4 curve_coordinates: * curve_coordinates) returns(#mePeLc37tFTxephe control_point_1: Vector3) {
 #kXqNtXv64161iysj // Can return invalid -> vector3
 #XAF9ojeAwXKqR2jM $control_point_1 := invalid→vector3;
 #xlkdeQ1UkdN8cSBU if not $curve_coordinates→control_point_1→is_invalid then {
 #rDe3u8DeOpnlOWAy $control_point_1 := math→create_vector3($curve_coordinates→control_point_1→x, $curve_coordinates→control_point_1→y, 0);
 }
 meta sync;
}
#pODw76O8kXAsc1rU
action control_point_2(#zNpLSKxz42YrzpBX curve_coordinates: * curve_coordinates) returns(#xt4ZCA2r0mNND6l6 control_point_2: Vector3) {
 #amoDJ1eE3rgJypXb // Can return invalid -> vector3
 #xQD5V8OI7MpsmXPR $control_point_2 := invalid→vector3;
 #FoPQ8tZ5pcK1z55C if not $curve_coordinates→control_point_2→is_invalid then {
 #h2CENz8Lf4CCfNXO $control_point_2 := math→create_vector3($curve_coordinates→control_point_2→x, $curve_coordinates→control_point_2→y, 0);
 }
 meta sync;
}
#vdkGV2qZXW7LAG9l
action set_starting_position(#yQTzM0ByW2XOpNOi curve_coordinates: * curve_coordinates, #xCuwSTdArcU6gac6 starting_position: Vector3) {
 #HvR20r33AbrDvS4v $curve_coordinates→starting_position := $starting_position;
 meta sync;
}
#Hl0kN2P4vKwXtaQC
action set_ending_position(#NfRc04X3uopqVcwI curve_coordinates: * curve_coordinates, #j0tD1qQLoagc8bn6 ending_position: Vector3) {
 #Oim2RIBjCNtk4VH7 $curve_coordinates→ending_position := $ending_position;
 meta sync;
}
#xLMBkcPQKv6oyCZT
action set_control_point_1(#fbG4d3mVPNna056B curve_coordinates: * curve_coordinates, #RlAHLwJssLVg0H6y control_point_1: Vector3) {
 #lE3eClqWUGCRuBm2 $curve_coordinates→control_point_1 := $control_point_1;
 meta sync;
}
#xs5VSqG5ylf6hSiS
action set_control_point_2(#OEY4sB9VB7pEvkbt curve_coordinates: * curve_coordinates, #JZWG1cVOEcpeOuDI control_point_2: Vector3) {
 #pYznP6smote5FfHE $curve_coordinates→control_point_2 := $control_point_2;
 meta sync;
}
#fATNKUyERCEta2cQ
table curve {
 type = “Object”;
 persistent = false;
 fields {
 #ppUuSyAWkc2LBOkl curve_type : * curve_type
 #SW9cNy5ZPJw3WsDC curve_coordinates : * curve_coordinates
 #BknYaOvkqeHQwBgl t : Number
 }
}
#xk986ORLjlpbTDuF
table curve_type {
 type = “Object”;
 persistent = false;
 fields {
 #W7vXqR6s7qF98Cs1 linear : Boolean
 #xtx4uiOHC5QwIOey quadratic : Boolean
 #xNRi3OXdgAOGUPOy cubic : Boolean
 }
}
#x7pQVfyVNAfv6MAh
action coordinates(#VXs6zTgQT1UpFP2D curve: * curve) returns(#Whx3Nl4cybDUNgPF curve_coordinates: * curve_coordinates) {
 #MEx33U2Iin4ZlFWS $curve_coordinates := $curve→curve_coordinates;
 meta sync;
}
#b9jn7yvQIG6t6DfR
action get_curve_type(#Hg72Sg3Eku7ZFV5t curve: * curve) returns(#qmxx86ggPXneJ6ct curve_type: * curve_type) {
 #khx0unplE14QdyNy $curve_type := $curve→curve_type;
 meta sync;
}
#FEcPoE2AI9MMGSdO
action create_linear_curve(#xvLrqSHAkIH3lLx2 starting_position: Vector3, #xlOHhc2mUEvb3zjC ending_position: Vector3) returns(#xMOwiR3qnMDef7Xf linear_curve: * curve) {
 #VVIGxsbR2w5KC4gK if $starting_position→is_invalid then {
 #HUOrE4UlhgwFKBGs $starting_position := math→create_vector3(0, 0, 0);
 }
 #t4VxqQ1nbxaCBRhL if $ending_position→is_invalid then {
 #xAmvbjn7GxSkVX7z $ending_position := $starting_position;
 }
 #tNQwD3I244z5Gc7n $linear_curve := records→curve→create;
 #oSLBPyayxoZBfaED $linear_curve→curve_coordinates := records→curve_coordinates→create;
 #nwd2iNGy5jA8kZ0u $linear_curve→curve_type := records→curve_type→create;
 #f2JoeR12muo2QiDD $linear_curve→curve_coordinates→starting_position := $starting_position;
 #cyk4aAX926M7y1ls $linear_curve→curve_coordinates→ending_position := $ending_position;
 #mU4X4pWVbTuqH6Tr $linear_curve→curve_type→linear := true;
 meta sync;
}
#ibCTjaingbo8wyvI
action create_quadratic_curve(#mO6VCyMhRLvoD2VJ starting_position: Vector3, #tBuwHIi2wctLx2hV ending_position: Vector3, #C44j5pXlUfcj0hmG control_point_1: Vector3) returns(#rS1ZMM6IUpFOo9Ph quadratic_curve: * curve) {
 #o4rHorpH6fh0AIpz if $starting_position→is_invalid then {
 #IEMb4LgmLaBJhhqi $starting_position := math→create_vector3(0, 0, 0);
 }
 #Xrx7b0MFUgSzX4HX if $ending_position→is_invalid then {
 #YVnWYRR322v70VOa $ending_position := $starting_position;
 }
 #lyyXnHihOZ4TknSe if $control_point_1→is_invalid then {
 #jpaADE3jQe39TVbY $control_point_1 := $ending_position;
 }
 #wkh4VjTAjaoufeO2 $quadratic_curve := records→curve→create;
 #QhyCPR4Zdh4NOY4N $quadratic_curve→curve_coordinates := records→curve_coordinates→create;
 #gBIN0S28sWXUykZu $quadratic_curve→curve_type := records→curve_type→create;
 #tvMxHHmSTM7PHa94 $quadratic_curve→curve_coordinates→starting_position := $starting_position;
 #X28Nsr3XOITnaBkv $quadratic_curve→curve_coordinates→ending_position := $ending_position;
 #DIdl2N8DcxYkv2Hg $quadratic_curve→curve_coordinates→control_point_1 := $control_point_1;
 #f5hmsWcp4S2eN19O $quadratic_curve→curve_type→quadratic := true;
 meta sync;
}
#t0C4DY22JLDdEscy
action create_cubic_curve(#x6h6TaaPgHKDO7gq starting_position: Vector3, #gDJ4gJkhHizaqFlX ending_position: Vector3, #TmB5M8NjoJ2lBs6k control_point_1: Vector3, #U3IXXo25ooOmMVic control_point_2: Vector3) returns(#s3umkBL0FVZXRf8P cubic_curve: * curve) {
 #HaD455QFTu9Kmmh4 if $starting_position→is_invalid then {
 #o8ZFUsSrt2vtI5ih $starting_position := math→create_vector3(0, 0, 0);
 }
 #nyzhyZnLRkyTfOoW if $ending_position→is_invalid then {
 #Wq8bbWfOUMhV0vfT $ending_position := $starting_position;
 }
 #bJQFriL4pT29cC9S if $control_point_1→is_invalid then {
 #yWYpTwBQD34GR2lw $control_point_1 := $ending_position;
 }
 #xtBN4XnGyabP2V4i if $control_point_2→is_invalid then {
 #qtbvV8FoH4YA42lq $control_point_2 := $control_point_1;
 }
 #k1j5hzCZVUqCnuNG $cubic_curve := records→curve→create;
 #G7GZ7RYUq3kqi07I $cubic_curve→curve_coordinates := records→curve_coordinates→create;
 #vUmEjsFYv6OcGSUo $cubic_curve→curve_type := records→curve_type→create;
 #UG2y2tA81SITL4gf $cubic_curve→curve_coordinates→starting_position := $starting_position;
 #xn0GjvZkxU8kxaVI $cubic_curve→curve_coordinates→ending_position := $ending_position;
 #JemUCWZWu1SOwf3C $cubic_curve→curve_coordinates→control_point_1 := $control_point_1;
 #ECaVZA9btnoWuJBc $cubic_curve→curve_coordinates→control_point_2 := $control_point_2;
 #YrBn1KMZrX4TgA4W $cubic_curve→curve_type→cubic := true;
 meta sync;
}
#ZNA0dlqurm6004pA
action t(#F59T6fonrwFyleDh curve: * curve) returns(#USuMT2kcJHPTy44W t: Number) {
 #BNPB894IxhyW2HQ1 $t := $curve→t;
 meta sync;
}
#xQF020RkBGVVyk6v
action set_t(#ITrUtLENKqcpiKhS curve: * curve, #Mz8zpSMjmtRhfsM4 t: Number) {
 #lx6BQ3uh6U0aVh2D $t_normalized := code→get_t_normalized($t);
 #xErsRc442pI8MIjF $curve→t := $t_normalized;
 meta sync;
}
#Iz7r3PDIXM9pk1P8
action get_position(#MpLGuVN2omjENOH3 curve: * curve) returns(#H4A3XKIRQZ2cIyWt position: Vector3) {
 #IOmUE5YxcjOVquOs $position := math→create_vector3(0, 0, 0);
 #CSD4EfBjFpHZKBUw if $curve→curve_type→cubic then {
 #nAS7fjvrpgpk7Zfy $position := code→get_cubic_position($curve);
 }
 else { #rs9Heg28m8JASiSv if $curve→curve_type→quadratic then {
 #mi8OsJj8gKmHb0IG $position := code→get_quadratic_position($curve);
 }
 else {
 #uo21j9pPEbxAz5I7 $position := code→get_linear_position($curve);
 }
 } 
 meta sync;
}
#wpNIywjItgaEAdq6
var start_time : DateTime {
 transient = true;
}
#x0rG3nPQf2YeS85f
var end_time : DateTime {
 transient = true;
}
#lPEZEiWBOMYwuxLq
action linear(#xy4JLw82GtHHd58X curve_type: * curve_type) returns(#XB9UN4FlShhEoIe1 linear: Boolean) {
 #WUCE4ARYE4M1gBwI $linear := $curve_type→linear;
}
#xUX85M3gzxDg4Wph
action quadratic(#xKhbBw7tJMeehdtc curve_type: * curve_type) returns(#IHwmsqecNh4S34kx quadratic: Boolean) {
 #xaJ4o1vcTayTqS3I $quadratic := $curve_type→quadratic;
}
#hq5NH0n42OoOOXR6
action cubic(#H5TlrqF6um1uFOcm curve_type: * curve_type) returns(#KlcoCV4ZuYD303RB cubic: Boolean) {
 #IRH6QQFaltKJpWrz $cubic := $curve_type→cubic;
}
”
}
]
}```
1 Like

That is fantastic Alex! That makes the code much more readable, and I am really impressed with quick response.

Is there any chance I could send you the rest of the code? I have another 5 files.
I don’t mind that others see the code, since this platform is all about sharing code and being open-source. If I can send the other files, would it be better to send them via email?

I’m a C# coder at heart, too. JavaScript and, even more so, TypeScript are easy languages to pick up with that background. The thing that sometimes gets me is the peculiar syntax that JavaScript has for declaring variables. I keep wanting to write them the C# way and IntelliSense keeps yelling at me. :smile:

I’ll give you time to port your code. I find it’s a great way to learn a language. Please feel free to ask for help if you need any.

There are several nice documents in the MakeCode documentation about creating extensions. Once you’ve ported your code, I’ll be happy to help you with creating extensions.


Regarding your other files, we could work on them together via GitHub if you’d like. You can find me there as alex-kulcsar. Might be the best way to collaborate on this code if we treat it like a project. Since you’re porting your code to MakeCode Arcade, that might be the best way to start.

  • Create a GitHub project within MakeCode Arcade.
  • Add the Touch Develop code to your new project via the GitHub web site.
  • Invite me as a collaborator.
1 Like

I agree with you on the quirkiness of the syntax; but I also see that as an advantage in offering flexibility.

Working on the code together in GitHub sounds like a good idea; I will get back to you on that. To be honest, I am somewhat of an amateur to GitHub, since I have been cradled using tools such as Visual Studio and Bitbucket. I will keep in touch.

1 Like

Just in case you need it, here’s MakeCode Arcade’s documentation. MakeCode Arcade makes it pretty easy to work with GitHub, too.

I have indeed logged into my GitHub account and linked that to MakeCode. I am quite impressed with what MakeCode already offers in terms of integration. I will be taking baby steps with MakeCode, to first familiarize myself with the block code, and then moving on to creating extensions.

I am also curious as to how you formatted the Touch Develop code. Was that done using something from the old platform, of did you just simply use something that parses the string value?

@AlexK
Baby steps project dealing with linear movement:

I don’t understand why the code does not work with blocks, maybe I need to add markdown for certain functions.

1 Like

Yup; baby steps are a good thing! If you’re comfortable with the TypeScript environment, then, at least for this project, you probably want to stay there…especially if you’re planning on writing an extension. You can worry about the Blocks parts later. (Short answer: The TS code needs to be both structured and then annotated in a specific way in order for blocks to appear in the toolbox.)

You’ll definitely want to get into the Blocks environment, though, to gain an understanding of the interface before you try to develop an extension. I’d suggest using the Blocks tutorials in the Tutorials or the Game Design Concepts sections of the home page. They’re great introductions to the MakeCode Arcade interface, and they provide you with a bit of a glimpse into the philosophy behind the MakeCode Arcade project.

Regarding your Touch Develop JSON: I cheated. :slightly_smiling_face: All I did was load your code into a text editor and then replace \n with an actual newline. I’m not a Microsoft employee, past or present, and so I don’t have access to the Touch Develop source code. I’m simply a user and massive fan of both platforms…and a very occasional contributor to the MakeCode Arcade platform.

@AlexK
I was able to get part of the code working in blocks. I know that the annotations are not entirely correct. I took a shortcut and used examples from the game extension (sprites.ts & sprite.ts). I will take a look at the documentation:

https://makecode.com/playground

For now it is so much information, I need to let it all sink in.

1 Like

We had some code to convert touchdevelop programs… but it’s long gone now sorry.

2 Likes

That is a pity; as that would have saved my a lot time recreating old games. Was ‘that code’ for converting block code, or written code? I’m sure someone has the tool lying around somewhere.