@@ -118,7 +118,7 @@ CompilerValue *MotionBlocks::compilePointTowards(Compiler *compiler)
118
118
Target *anotherTarget = compiler->engine ()->targetAt (index );
119
119
120
120
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 ) });
122
122
}
123
123
} else {
124
124
CompilerValue *towards = compiler->addInput (input);
@@ -158,7 +158,7 @@ CompilerValue *MotionBlocks::compileGoTo(Compiler *compiler)
158
158
Target *anotherTarget = compiler->engine ()->targetAt (index );
159
159
160
160
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 ) });
162
162
}
163
163
} else {
164
164
CompilerValue *to = compiler->addInput (input);
@@ -220,8 +220,8 @@ CompilerValue *MotionBlocks::compileGlideTo(Compiler *compiler)
220
220
221
221
if (anotherTarget && !anotherTarget->isStage ()) {
222
222
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 ) });
225
225
}
226
226
} else
227
227
return nullptr ;
@@ -405,9 +405,8 @@ extern "C" void motion_point_towards_random_direction(ExecutionContext *ctx)
405
405
sprite->setDirection (rng->randint (-180 , 179 ));
406
406
}
407
407
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 )
409
409
{
410
- Sprite *anotherSprite = static_cast <Sprite *>(sprite->engine ()->targetAt (index ));
411
410
motion_point_towards_pos (sprite, anotherSprite->x (), anotherSprite->y ());
412
411
}
413
412
@@ -456,9 +455,8 @@ extern "C" void motion_go_to_random_pos(ExecutionContext *ctx)
456
455
sprite->setPosition (rng->randintDouble (-stageWidth / 2.0 , stageWidth / 2.0 ), rng->randintDouble (-stageHeight / 2.0 , stageHeight / 2.0 ));
457
456
}
458
457
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 )
460
459
{
461
- Sprite *anotherSprite = static_cast <Sprite *>(sprite->engine ()->targetAt (index ));
462
460
sprite->setPosition (anotherSprite->x (), anotherSprite->y ());
463
461
}
464
462
@@ -539,17 +537,13 @@ extern "C" double motion_get_random_y(ExecutionContext *ctx)
539
537
return ctx->rng ()->randintDouble (-stageHeight / 2.0 , stageHeight / 2.0 );
540
538
}
541
539
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 )
543
541
{
544
- assert (!ctx->engine ()->targetAt (index )->isStage ());
545
- Sprite *sprite = static_cast <Sprite *>(ctx->engine ()->targetAt (index ));
546
542
return sprite->x ();
547
543
}
548
544
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 )
550
546
{
551
- assert (!ctx->engine ()->targetAt (index )->isStage ());
552
- Sprite *sprite = static_cast <Sprite *>(ctx->engine ()->targetAt (index ));
553
547
return sprite->y ();
554
548
}
555
549
0 commit comments