Re: Syntax problem, how is then missing in this statement
Posted: Sat Aug 09, 2014 1:56 am
..........
Questions and answers about the LiveCode platform.
https://forums.livecode.com/
Code: Select all
set the top of line x of characterSprites to the top of line x of characterSprites - playerSpeedCode: Select all
local myWalls
local characterSprites
local numberOfWalls
local intersectsTop
local intersectsBottom
local intersectsLeft
local intersectsRight
local playerSpeed
on preOpenCard
setUpVariables
end preOpenCard
command setUpVariables
--set the player looking to the right at startup
show image "pUp"
show image "pDown"
show image "pLeft"
show image "pRight"
put "pUp" into line 1 of characterSprites
put "pDown" into line 2 of characterSprites
put "pLeft" into line 3 of characterSprites
put "pRight" into line 4 of characterSprites
put 5 into playerSpeed
put 10 into numberOfWalls
repeat with x = 1 to numberOfWalls
put "rectangle" & x into line x of myWalls
end repeat
end setUpVariables
on arrowKey k
if k = "up" then
handleWallCollisions
if intersectsTop = "false" then
repeat with x = 1 to 4
set the top of img line x of characterSprites to the top of img line x of characterSprites - playerSpeed
end repeat
end if
else if k = "down" then
handleWallCollisions
if intersectsBottom = "false" then
repeat with x = 1 to 4
set the bottom of img line x of characterSprites to the bottom of img line x of characterSprites + playerSpeed
end repeat
end if
else if k = "left" then
handleWallCollisions
if intersectsLeft = "false" then
repeat with x = 1 to 4
set the left of img line x of characterSprites to the left of img line x of characterSprites - playerSpeed
end repeat
end if
else if k = "right" then
handleWallCollisions
if intersectsRight = "false" then
repeat with x = 1 to 4
set the right of img line x of characterSprites to the right of img line x of characterSprites + playerSpeed
end repeat
end if
end if
--reset the collision detection
put false into intersectsBottom
put false into intersectsTop
put false into intersectsLeft
put false into intersectsRight
end arrowKey
--notes where the player has intersected to negate the motion of the player into the wall it will be important to start with all intersections set to false
command handleWallCollisions
--for every sprite image
repeat with x = 1 to 4
--for every wall
repeat with y = 1 to numberOfWalls
if intersect (img line x of characterSprites,graphic line y of myWalls, 255) then
repeat with b = 1 to 4
if the bottom of img line b of characterSprites > the top of graphic line y of myWalls then
put "true" into intersectsBottom
end if
if the top of img line b of characterSprites < the bottom of graphic line y of myWalls then
put "true" into intersectsTop
end if
if the left of img line b of characterSprites < the right of graphic line y of myWalls then
put "true" into intersectsLeft
end if
if the right of img line b of characterSprites > the left of graphic line y of myWalls then
put "true" into intersectsRight
end if
end repeat
end if
end repeat
end repeat
end handleWallCollisions