# 「動き」ジャンル <% category = 'motion' color = 225 %> # ( )歩動かす <% n = "#{category}_move" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('%1歩動かす', ['STEP', ['Number'], Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> arg = Blockly.Ruby.valueToCode(@, 'STEP', Blockly.Ruby.ORDER_NONE) || '0' Blockly.Ruby.characterMethodCall_('move', "#{arg}") # 時計回りに( )度回す # 半時計回りに( )度回す <% [ ['right', '', ''], ['left', '半', '-'], ].each do |suffix, label_prefix, sign| n = "#{category}_rotate_#{suffix}" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('<%= label_prefix %>時計回りに%1度回す', ['ANGLE', ['Number'], Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> arg = Blockly.Ruby.valueToCode(@, 'ANGLE', Blockly.Ruby.ORDER_NONE) || '0' Blockly.Ruby.characterMethodCall_('rotate', "<%= sign %>#{arg}") <% end %> # ( )度に向ける <% n = "#{category}_set_angle" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('%1度に向ける', ['ANGLE', ['Number'], Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> angle = Blockly.Ruby.valueToCode(@, 'ANGLE', Blockly.Ruby.ORDER_NONE) || '0' Blockly.Ruby.characterSetVariable_('angle', angle) # マウスポインターへ向ける <% n = "#{category}_point_towards_mouse" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField('マウスポインターへ向ける') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> "#{Blockly.Ruby.rn()}point_towards(:mouse)\n" # [▼]へ向ける <% n = "#{category}_point_towards_character" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField(new Smalruby.FieldCharacter(), 'CHAR') .appendField('へ向ける') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> char = @getFieldValue('CHAR') Blockly.Ruby.characterMethodCall_('point_towards', char) # x座標を( )、y座標を( )にする <% n = "#{category}_set_x_y" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField('X座標を') @appendValueInput('X').setCheck('Number') @appendDummyInput().appendField('、Y座標を') @appendValueInput('Y').setCheck('Number') @appendDummyInput().appendField('にする') @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> x = Blockly.Ruby.valueToCode(@, 'X', Blockly.Ruby.ORDER_NONE) || '0' y = Blockly.Ruby.valueToCode(@, 'Y', Blockly.Ruby.ORDER_NONE) || '0' Blockly.Ruby.characterSetVariable_('x', x) + Blockly.Ruby.characterSetVariable_('y', y) # マウスポインターへ行く <% n = "#{category}_go_to_mouse" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField('マウスポインターへ行く') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> "#{Blockly.Ruby.rn()}go_to(:mouse)\n" # [▼]へ行く # <% n = "#{category}_go_to_character" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField(new Smalruby.FieldCharacter(), 'CHAR') .appendField('へ行く') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> char = @getFieldValue('CHAR') "#{Blockly.Ruby.rn()}go_to(#{var0})\n" # ( )秒でx座標を( )、y座標を( )に変える <% n = "#{category}_glide_to_x_y" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('%1秒でx座標を%2、y座標を%3に変える', ['SEC', ['Number'], Blockly.ALIGN_RIGHT], ['X', ['Number'], Blockly.ALIGN_RIGHT], ['Y', ['Number'], Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> sec = Blockly.Ruby.valueToCode(@, 'SEC', Blockly.Ruby.ORDER_NONE) || '0' x = Blockly.Ruby.valueToCode(@, 'X', Blockly.Ruby.ORDER_NONE) || '0' y = Blockly.Ruby.valueToCode(@, 'Y', Blockly.Ruby.ORDER_NONE) || '0' "#{Blockly.Ruby.rn()}glide_to(second: #{sec}, x: #{x}, y: #{y})\n" # x座標を( )ずつ変える # x座標を( )にする # y座標を( )ずつ変える # y座標を( )にする <% [ ['change_x_by', 'X', 'ずつ変える', '+='], ['set_x', 'X', 'にする', '='], ['change_y_by', 'Y', 'ずつ変える', '+='], ['set_y', 'Y', 'にする', '='], ].each do |suffix, name, label_suffix, operator| n = "#{category}_#{suffix}" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('<%= name.downcase %>座標を%1<%= label_suffix %>', ['<%= name %>', ['Number'], Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> <%= name.downcase %> = Blockly.Ruby.valueToCode(@, '<%= name %>', Blockly.Ruby.ORDER_NONE) || '0' Blockly.Ruby.characterSetVariable_('<%= name.downcase %>', <%= name.downcase %>, '<%= operator %>') <% end %> # もし端に着いたら、跳ね返る <% n = "#{category}_turn_if_reach_wall" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField('もし端に着いたら、跳ね返る') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> Blockly.Ruby.characterMethodCall_('turn_if_reach_wall') # 条件:端に着いた <% n = "#{category}_reach_wall" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField('端に着いた') @setOutput(true, 'Boolean') @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> Blockly.Ruby.characterMethodCallInput_('reach_wall?') # 跳ね返る <% n = "#{category}_turn" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField('跳ね返る') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> Blockly.Ruby.characterMethodCall_('turn') # 回転方法を[▼]にする <% n = "#{category}_set_rotation_style" %> Blockly.Blocks['<%= n %>'] = init: ()-> dropdown = [ ['左右のみ', 'left_right'], ['回転しない', 'none'], ['自由に回転', 'free'], ] @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField('回転方法を') .appendField(new Blockly.FieldDropdown(dropdown), 'STYLE') .appendField('にする') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> style = @getFieldValue('STYLE') Blockly.Ruby.characterSetVariable_('rotation_style', ":#{style}") # 変数:x座標 # 変数:y座標 # 変数:向き <% [ ['x', 'x座標'], ['y', 'y座標'], ['angle', '向き'], ].each do |method, label| n = "#{category}_self_#{method}" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput().appendField('<%= label %>') @setOutput(true, 'Number') @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> Blockly.Ruby.characterMethodCallInput_('<%= method %>') <% end %>