@@ -112,7 +112,7 @@ CompilerValue *MotionBlocks::compilePointTowards(Compiler *compiler)
112
112
if (value == " _mouse_" )
113
113
compiler->addTargetFunctionCall (" motion_point_towards_mouse" );
114
114
else if (value == " _random_" )
115
- compiler->addFunctionCallWithCtx (" motion_point_towards_random_pos " );
115
+ compiler->addFunctionCallWithCtx (" motion_point_towards_random_direction " );
116
116
else {
117
117
int index = compiler->engine ()->findTarget (value);
118
118
Target *anotherTarget = compiler->engine ()->targetAt (index );
@@ -398,14 +398,11 @@ extern "C" void motion_point_towards_mouse(Sprite *sprite)
398
398
motion_point_towards_pos (sprite, engine->mouseX (), engine->mouseY ());
399
399
}
400
400
401
- extern " C" void motion_point_towards_random_pos (ExecutionContext *ctx)
401
+ extern " C" void motion_point_towards_random_direction (ExecutionContext *ctx)
402
402
{
403
403
Sprite *sprite = static_cast <Sprite *>(ctx->thread ()->target ());
404
- IEngine *engine = ctx->engine ();
405
- const int stageWidth = engine->stageWidth ();
406
- const int stageHeight = engine->stageHeight ();
407
404
IRandomGenerator *rng = ctx->rng ();
408
- motion_point_towards_pos ( sprite, rng-> randintDouble (-stageWidth / 2.0 , stageWidth / 2.0 ), rng->randintDouble (-stageHeight / 2.0 , stageHeight / 2.0 ));
405
+ sprite-> setDirection ( rng->randint (- 180 , 179 ));
409
406
}
410
407
411
408
extern " C" void motion_point_towards_target_by_index (Sprite *sprite, double index)
@@ -424,7 +421,7 @@ extern "C" void motion_pointtowards(ExecutionContext *ctx, const StringPtr *towa
424
421
if (string_compare_case_sensitive (towards, &MOUSE_STR) == 0 )
425
422
motion_point_towards_mouse (sprite);
426
423
else if (string_compare_case_sensitive (towards, &RANDOM_STR) == 0 )
427
- motion_point_towards_random_pos (ctx);
424
+ motion_point_towards_random_direction (ctx);
428
425
else {
429
426
// TODO: Use UTF-16 in engine
430
427
std::string u8name = utf8::utf16to8 (std::u16string (towards->data ));
0 commit comments