@@ -118,7 +118,7 @@ CompilerValue *MotionBlocks::compilePointTowards(Compiler *compiler)
118118 Target *anotherTarget = compiler->engine ()->targetAt (index);
119119
120120 if (anotherTarget && !anotherTarget->isStage ())
121- compiler->addTargetFunctionCall (" motion_point_towards_target_by_index " , Compiler::StaticType::Void, { Compiler::StaticType::Number }, { compiler->addConstValue (index ) });
121+ compiler->addTargetFunctionCall (" motion_point_towards_sprite " , Compiler::StaticType::Void, { Compiler::StaticType::Pointer }, { compiler->addConstValue (anotherTarget ) });
122122 }
123123 } else {
124124 CompilerValue *towards = compiler->addInput (input);
@@ -158,7 +158,7 @@ CompilerValue *MotionBlocks::compileGoTo(Compiler *compiler)
158158 Target *anotherTarget = compiler->engine ()->targetAt (index);
159159
160160 if (anotherTarget && !anotherTarget->isStage ())
161- compiler->addTargetFunctionCall (" motion_go_to_target_by_index " , Compiler::StaticType::Void, { Compiler::StaticType::Number }, { compiler->addConstValue (index ) });
161+ compiler->addTargetFunctionCall (" motion_go_to_sprite " , Compiler::StaticType::Void, { Compiler::StaticType::Pointer }, { compiler->addConstValue (anotherTarget ) });
162162 }
163163 } else {
164164 CompilerValue *to = compiler->addInput (input);
@@ -220,8 +220,8 @@ CompilerValue *MotionBlocks::compileGlideTo(Compiler *compiler)
220220
221221 if (anotherTarget && !anotherTarget->isStage ()) {
222222 if (!target->isStage ()) {
223- endX = compiler->addFunctionCallWithCtx (" motion_get_sprite_x_by_index " , Compiler::StaticType::Number, { Compiler::StaticType::Number }, { compiler->addConstValue (index ) });
224- endY = compiler->addFunctionCallWithCtx (" motion_get_sprite_y_by_index " , Compiler::StaticType::Number, { Compiler::StaticType::Number }, { compiler->addConstValue (index ) });
223+ endX = compiler->addFunctionCallWithCtx (" motion_get_sprite_x " , Compiler::StaticType::Number, { Compiler::StaticType::Pointer }, { compiler->addConstValue (anotherTarget ) });
224+ endY = compiler->addFunctionCallWithCtx (" motion_get_sprite_y " , Compiler::StaticType::Number, { Compiler::StaticType::Pointer }, { compiler->addConstValue (anotherTarget ) });
225225 }
226226 } else
227227 return nullptr ;
@@ -405,9 +405,8 @@ extern "C" void motion_point_towards_random_direction(ExecutionContext *ctx)
405405 sprite->setDirection (rng->randint (-180 , 179 ));
406406}
407407
408- extern " C" void motion_point_towards_target_by_index (Sprite *sprite, double index )
408+ extern " C" void motion_point_towards_sprite (Sprite *sprite, Sprite *anotherSprite )
409409{
410- Sprite *anotherSprite = static_cast <Sprite *>(sprite->engine ()->targetAt (index));
411410 motion_point_towards_pos (sprite, anotherSprite->x (), anotherSprite->y ());
412411}
413412
@@ -456,9 +455,8 @@ extern "C" void motion_go_to_random_pos(ExecutionContext *ctx)
456455 sprite->setPosition (rng->randintDouble (-stageWidth / 2.0 , stageWidth / 2.0 ), rng->randintDouble (-stageHeight / 2.0 , stageHeight / 2.0 ));
457456}
458457
459- extern " C" void motion_go_to_target_by_index (Sprite *sprite, double index )
458+ extern " C" void motion_go_to_sprite (Sprite *sprite, Sprite *anotherSprite )
460459{
461- Sprite *anotherSprite = static_cast <Sprite *>(sprite->engine ()->targetAt (index));
462460 sprite->setPosition (anotherSprite->x (), anotherSprite->y ());
463461}
464462
@@ -539,17 +537,13 @@ extern "C" double motion_get_random_y(ExecutionContext *ctx)
539537 return ctx->rng ()->randintDouble (-stageHeight / 2.0 , stageHeight / 2.0 );
540538}
541539
542- extern " C" double motion_get_sprite_x_by_index (ExecutionContext *ctx, double index )
540+ extern " C" double motion_get_sprite_x (ExecutionContext *ctx, Sprite *sprite )
543541{
544- assert (!ctx->engine ()->targetAt (index)->isStage ());
545- Sprite *sprite = static_cast <Sprite *>(ctx->engine ()->targetAt (index));
546542 return sprite->x ();
547543}
548544
549- extern " C" double motion_get_sprite_y_by_index (ExecutionContext *ctx, double index )
545+ extern " C" double motion_get_sprite_y (ExecutionContext *ctx, Sprite *sprite )
550546{
551- assert (!ctx->engine ()->targetAt (index)->isStage ());
552- Sprite *sprite = static_cast <Sprite *>(ctx->engine ()->targetAt (index));
553547 return sprite->y ();
554548}
555549
0 commit comments