reflect()
Purpose
Find the reflection of a vector
Description
Find the reflection of a vector when it hits a surface
Syntax
result = reflect( incident, normal )
Arguments
result The resulting reflection vector { x, y, z, w }
incident incident vector { x, y, z, w }
normal normal vector orthoganal to the surface { x, y, z, w }
Example
radians( true )
image = loadImage( "Untied Games/Enemy small top C", false )
ship = createSprite( )
setSpriteImage( ship, image )
lastpos = { gwidth() / 2, gheight() / 2 }
setSpriteLocation( ship, lastpos )
setSpriteScale( ship, { 3, 3 } )
size = getSpriteSize( ship )
speed = { 400, 300 }
loop
clear()
c = controls( 0 )
curpos = getSpriteLocation( ship )
refx = 0
refy = 0
if curpos.x < size.x / 2 then
refx = 1
endIf
if curpos.y < size.y / 2 then
refy = 1
endIf
if curpos.x > gwidth() - size.x / 2 then
refx = -1
endIf
if curpos.y > gheight() - size.y / 2 then
refy = -1
endIf
speed = reflect( speed, { refx, refy } )
setSpriteSpeed( ship, speed )
if curpos != lastpos then
setSpriteRotation( ship, -pi / 2 + atan2( curpos.y - lastpos.y, curpos.x - lastpos.x ) )
lastpos = curpos
endIf
updateSprites()
drawSprites()
update()
repeat
Associated Commands