property pSpeed -- the speed of sprite movement property pAngle -- movement angle property pDirection -- direction of movement property pX, pY -- x and y sprite position property pDX, pDY -- for movement vector property pGravity -- gravity strength property pSp -- the sprite to move property pMove -- controls overall sprite movement property pStartLoc -- the starting location of the sprite --------------------------------------------------------------------------- -- Drop onto a sprite to give it simple projectile movement based on a -- firing angle, direction, speed, and gravity factor. -- -- Ken Loge - http://diginoodles.com --------------------------------------------------------------------------- on getPropertyDescriptionList me list = [:] addProp list, #pSpeed, [#comment: "Speed of Movement: (In pixels per update)", #format: #float, #default: 10.0] addProp list, #pAngle, [#comment: "Firing Angle (0 = horizontal, 90 = vertically up):", #format: #float, #default: 45.0] addProp list, #pDirection, [#comment: "Fire left or right?", #format: #symbol, #default: #right, #range: [#left, #right]] addProp list, #pGravity, [#comment: "Gravity strength (in pixels per update):", #format: #float, #default: 0.5] return list end on beginSprite me initialize(me) end -- initialize variables on initialize me pStartLoc = sprite(me.spriteNum).loc pSp = sprite(me.spriteNum) pX = float(pSp.locH) pY = float(pSp.locV) -- calculate movement vector pDX = sin(pAngle / 180.0 * pi()) * pSpeed pDY = -cos(pAngle / 180.0 * pi()) * pSpeed -- flip X direction to move left if pDirection = #left then pDX = -pDX pMove = FALSE end on mouseUp me pMove = TRUE end on exitFrame me if pMove = TRUE then pX = pX + pDX pY = pY + pDY pDY = pDY + pGravity -- stop moving the sprite if it moves past -- its original vertical position if pY >= pStartLoc.locV then pSp.locV = pStartLoc.locV pMove = FALSE initialize(me) end if -- update sprite position pSp.loc = point(integer(pX), integer(pY)) end if end