Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone explain this navigation script?

Status
Not open for further replies.

Kelli3K

Technical User
Nov 2, 2001
1
0
0
AU
Is anyone able to explain what this script does and (more specifically) HOW it does it? Thankyou.


property pSprite
property pSpeed
property pMaxSpeed
property pFriction
property pRotateAmt

on BeginSprite me
pSprite = me.spriteNum
pSpeed = 0
pMaxSpeed = 18
pFriction = 0.6
pRotateAmt = 10
end

on ExitFrame me
if keyPressed(123) then
sprite(pSprite).rotation = sprite(pSprite).rotation - pRotateAmt
else if keyPressed(124) then
sprite(pSprite).rotation = sprite(pSprite).rotation + pRotateAmt
end if
if keyPressed(126) then
if pSpeed < pMaxSpeed then
pSpeed = pSpeed + 1
end if
else
if pSpeed > 0 then
pSpeed = pSpeed - pFriction
end if
if pSpeed < 0 then
pSpeed = 0
end if
end if

if pSpeed > 0 then
angRad = pi() * sprite(pSprite).rotation/180.0
sprite(pSprite).loc = sprite(pSprite).loc + point(pSpeed * cos(angRad), Â
pSpeed * sin(angRad))
end if
end
 
I've added some comments which i hope will help

property pSprite -- declare properties here
property pSpeed
property pMaxSpeed
property pFriction
property pRotateAmt

on BeginSprite me --now set initital values for properties
pSprite = me.spriteNum
pSpeed = 0
pMaxSpeed = 18
pFriction = 0.6
pRotateAmt = 10
end

on ExitFrame me
if keyPressed(123) then --key 123 rotates the sprite anticlockwise
sprite(pSprite).rotation = sprite(pSprite).rotation - pRotateAmt
else if keyPressed(124) then --key 124 rotates the sprite clockwise
sprite(pSprite).rotation = sprite(pSprite).rotation + pRotateAmt
end if
if keyPressed(126) then --key 126 increases the sprites speed upto a max of pMaxSpeed
if pSpeed < pMaxSpeed then
pSpeed = pSpeed + 1
end if
else
if pSpeed > 0 then --if sprite is moving, slow it down (friction)
pSpeed = pSpeed - pFriction
end if
if pSpeed < 0 then --don't allow negative speeds
pSpeed = 0
end if
end if

if pSpeed > 0 then --update sprites position
angRad = pi() * sprite(pSprite).rotation/180.0
sprite(pSprite).loc = sprite(pSprite).loc + point(pSpeed * cos(angRad), Â
pSpeed * sin(angRad))
end if
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top