@@ -112,7 +112,7 @@ CompilerValue *MotionBlocks::compilePointTowards(Compiler *compiler)
112112 if (value == " _mouse_" )
113113 compiler->addTargetFunctionCall (" motion_point_towards_mouse" );
114114 else if (value == " _random_" )
115- compiler->addFunctionCallWithCtx (" motion_point_towards_random_pos " );
115+ compiler->addFunctionCallWithCtx (" motion_point_towards_random_direction " );
116116 else {
117117 int index = compiler->engine ()->findTarget (value);
118118 Target *anotherTarget = compiler->engine ()->targetAt (index);
@@ -398,14 +398,11 @@ extern "C" void motion_point_towards_mouse(Sprite *sprite)
398398 motion_point_towards_pos (sprite, engine->mouseX (), engine->mouseY ());
399399}
400400
401- extern " C" void motion_point_towards_random_pos (ExecutionContext *ctx)
401+ extern " C" void motion_point_towards_random_direction (ExecutionContext *ctx)
402402{
403403 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 ();
407404 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 ));
409406}
410407
411408extern " 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
424421 if (string_compare_case_sensitive (towards, &MOUSE_STR) == 0 )
425422 motion_point_towards_mouse (sprite);
426423 else if (string_compare_case_sensitive (towards, &RANDOM_STR) == 0 )
427- motion_point_towards_random_pos (ctx);
424+ motion_point_towards_random_direction (ctx);
428425 else {
429426 // TODO: Use UTF-16 in engine
430427 std::string u8name = utf8::utf16to8 (std::u16string (towards->data ));
0 commit comments