**Part22b. Tutorial Stack 14: New Player Move Handeling and Ping Pong Warps**

I changed the way the player ship is controlled by the mouse. I didn't like the mouse pointer being right on top of the shop most of the time.

So now it works with any change of the Mouse X direction over 20 pixels.

Code: Select all

```
if abs(item 1 the mouseLoc - lastMouseX) > 20 then
if item 1 of the mouseLoc < lastMouseX then
put -1 into pXM
put 180 into playerDirAngle
put "left" into flyDir
end if
if item 1 of the mouseLoc > lastMouseX then
put 1 into pXM
put 0 into playerDirAngle
put "right"into flyDir
end if
if item 1 of the mouse is not lastMouseX then put item 1 of the mouseLoc into lastMouseX
end if
```

*MouseLocTargetV*. Could play with the distance that causes the mouse to change direction but lower values make it a bit jerky, it's really amazing how short 20 pixels is in distance on modern monitors.

Added this bit of code to WarpJump, now our ship goes in one side and appears to bouch out the other in the opposite direction.

Code: Select all

```
if flyDir is "right" then
put "left" into flyDir
put item 1 of the mouseLoc+30 into lastMouseX
else
put "right" into flyDir
put item 1 of the mouseLoc-30 into lastMouseX
end if
```

*lastMouseX*an artificial position fools

**PlayerMove**into thinking that the current/same mouse position is a shift for intention to move in a direction.

Added some functions to the stack. Not needed just yet. But they took me a bit of time to find or not find online and then figure out.

**MidPoint**

Code: Select all

```
--// find midpoint between two locations
function MidPoint x1,x2,y1,y2
put floor((x1+x2)/2) into x3
put floor((y1+y2)/2) into y3
return x3,y3
end MidPoint
```

**EndPoint**

Code: Select all

```
--// find the arbitrary endpoint along a line segment given two points
]function EndPoint x1,x2,y1,y2,magnitude
put floor((x1+x2)/2)+deltaVal(x1,x2)*magnitude into x3
put floor((y1+y2)/2)+deltaVal(y1,y2)*magnitude into y3
return x3,y3
end EndPoint
```

**rotatePoints**

Code: Select all

```
--// rotate the points of an object
function rotatePoints x, y, cx, cy, tAngle
--// x, //X coords to rotate - replaced on return
--// y, //Y coords to rotate - replaced on return
--// cx, //X coordinate of center of rotation
--// cy, //Y coordinate of center of rotation
-- // angle) //Angle of rotation (radians, counterclockwise)
put cos(tAngle) into tcos
put sin(tAngle) into tsin
put ((x-cx)*tcos - (y-cy)*tsin) + cx into Xout
put ((x-cx)*tsin + (y-cy)*tcos) + cy into Yout
return xOut & comma & yOut
end rotatePoints
```

*Radians*!

Here's the first part of the geomantric ritual

Code: Select all

```
put "SomeGraphicsName" into myG
if myG is not empty then
put the points of graphic myG into tPoints
put the width of graphic myG into W
put the loc of graphic myG into mLoc
put item 1 of mLoc into cx
put item 2 of mLoc into cy
repeat with i= 1 to 360
put (i*144)*(pi/180) into radians
put empty into newPoints
repeat for each line L in tpoints
if L is not empty then
put item 1 of L into X
put item 2 of L into Y
put rotatePoints(x,y,cx,cy,i) into L
end if
put L & cr after newPoints
end repeat
set the points of graphic myG to newPoints
end repeat
end if
```

This may come into play later, but I fear it'll slow the game down.

Okay I'm in the mood to add more sound effects to the game so I'll upload the stack before making a mess of it.