YA Crank Question

Hi all, I'm trying to build an arcade game where the player sprite is moved around the screen in a circle using the crank, collecting items and avoiding sprites.

I have very little programming knowledge and some kind folks on here shared some code that got the player moving with the crank, which I'll share here:

In 'Player' script:

on draw do

// Draw a crank dot
if event.ra!=0 then
a = event.aa
a /= 180
a *= 3.14159
emit "sin"
emit "cos"
x = sin
x *= 54
x += 90
x += 2

	y = cos
	y *= 54
	y += 58
	y += 2
fill "black" at x,y,1,1


on crank do
x /= 8
x = floor x
y /= 8
y = floor y
goto x,y

In 'Game' script:

on sin do
aNorm = a
while aNorm>=3.141592 do
aNorm -= 6.283184

n = 0
modifier = 1
sin = 0
while n<6 do
	// modifier * aNorm^(2n+1)
	// -------------------
	// (2n+1)!
	pow = n
	pow *= 2
	pow += 1
	// numerator
	num = modifier
	p = pow
	while p>0 do
		num *= aNorm
	// denominator
	f = pow
	den = 1
	while f>0 do
		den *= f
	if den==0 then
		den = 1
	// log "{modifier} * {num}"
	// log "------------------"
	// log "{den}"
	// Add to result
	num /= den
	sin += num
	// Set up next loop
	modifier *= -1
	n += 1


on cos do
oldA = a
oldSin = sin
a += 1.57079
call "sin"
cos = sin
cos *= -1 // Trig is y up, pulp is y down
a = oldA
sin = oldSin

This works quite nicely to get the player moving around in a circle with the crank. The trouble is the player now no longer collects items or collides with sprites. I'm guessing that drawing the crank dot and having the player follow it means the Player isn't existing in the room the same way it normally would.

Is there anything I can add or change to this to make the player be able to interact with objects as normal? Or is there a better way to move the player around with the crank?

Thank you very much for any help.

1 Like

The collect event on items and the interact event on sprites only get automatically called when the player moves into them using dpad input.

Your crank-based movement is scripted using goto x,y, so collect and/or interact aren't being triggered.

One way to fix it might be to manually call those events on the target tile after the goto like this:

goto x,y
tell x,y to
  call "interact"
  call "collect"

(Note this won't quite be interacting "as normal" as the normal behaviour is that you can't move onto a sprite as it is solid)

1 Like

Thank you very much! It hadn't occurred to me that interact won't work if the player moves to the tile without the d-pad. Telling the tile to call interact and collect now results in x,y swapping to a white tile when the player moves on but there are limited tiles the player can move to so I can just tell them to swap back to what they were previously.

Thanks for the help!

The tile swapping to a white tile is most likely because it is an item being collected. If you don't add your own collect event to an item tile's script, the default behaviour is for it to increment a variable based on its name and swap to white as it is "collected".