I made a Maze Game in Livecode but I have a problem because there are enemies in my Maze who can move and if you touch them you will respawn at the start.
Everything works fine but I don't know where I have to include the moving code of the enemie...
I know I have to include it in the Card Code but in which "command box" of it?
I tried to include the code it in "on openCard" but the program doesn't react after I start it the game (maybe overloaded).
Here is the code of the enemie moving:
Code: Select all
repeat forever
put random(4) into Direction
if Direction = 1 then
set the top of graphic "enemie1" to the top of graphic "enemie1" - 3
if top of graphic "enemie1" < 0 then
set the top of graphic "enemie1" to 0
end if
end if
if Direction = 2 then
set the bottom of graphic "enemie1" to the bottom of graphic "enemie1" + 3
if the bottom of graphic "enemie1" > the bottom of card "mycard" then
set the bottom of graphic "enemie1" to the bottom of card "mycard"
end if
end if
if Direction = 3 then
set the left of graphic "enemie1" to the left of graphic "box" - 3
if the left of graphic "enemie1" < 0 then
set the left of graphic "enemie1" to 0
end if
end if
if Direction = 4 then
set the right of graphic "enemie1" to the right of graphic "enemie1" + 3
if right of graphic "enemie1" > the right of card "mycard" then
set the right of graphic "enemie1" to the right of card "mycard"
end if
end if
wait 250 milliseconds
end repeat
Code: Select all
local Coins, Coin1, Coin2, Coin3, Coin4, Coin5, Coin6, Coin7, Coin8, Coin9, Coin10, Coin11, Coin12
local Direction
on openCard
play "BGMusic.aif" looping
put 0 into Coins
put 0 into Coin1
put 0 into Coin2
put 0 into Coin3
put 0 into Coin4
put 0 into Coin5
put 0 into Coin6
put 0 into Coin7
put 0 into Coin8
put 0 into Coin9
put 0 into Coin10
put 0 into Coin11
put 0 into Coin12
put 0 into Direction
repeat forever
put random(4) into Direction
if Direction = 1 then
set the top of graphic "enemie1" to the top of graphic "enemie1" - 3
if top of graphic "enemie1" < 0 then
set the top of graphic "enemie1" to 0
end if
end if
if Direction = 2 then
set the bottom of graphic "enemie1" to the bottom of graphic "enemie1" + 3
if the bottom of graphic "enemie1" > the bottom of card "mycard" then
set the bottom of graphic "enemie1" to the bottom of card "mycard"
end if
end if
if Direction = 3 then
set the left of graphic "enemie1" to the left of graphic "box" - 3
if the left of graphic "enemie1" < 0 then
set the left of graphic "enemie1" to 0
end if
end if
if Direction = 4 then
set the right of graphic "enemie1" to the right of graphic "enemie1" + 3
if right of graphic "enemie1" > the right of card "mycard" then
set the right of graphic "enemie1" to the right of card "mycard"
end if
end if
wait 250 milliseconds
end repeat
end openCard
on arrowkey x
--Controls
if x is "up" then
set the top of graphic "box" to the top of graphic "box" - 3
if top of graphic "box" < 0 then
set the top of graphic "box" to 0
end if
if intersect( graphic "box" , group "maze" , "opaque pixels") then
set the bottom of graphic "box" to the bottom of graphic "box" + 3.1
end if
end if
if x is "down" then
set the bottom of graphic "box" to the bottom of graphic "box" + 3
if the bottom of graphic "box" > the bottom of card "mycard" then
set the bottom of graphic "box" to the bottom of card "mycard"
end if
if intersect( graphic "box" , group "maze" , "opaque pixels") then
set the bottom of graphic "box" to the bottom of graphic "box" - 3.1
end if
end if
if x is "left" then
set the left of graphic "box" to the left of graphic "box" - 3
if the left of graphic "box" < 0 then
set the left of graphic "box" to 0
end if
if intersect( graphic "box" , group "maze" , "opaque pixels") then
set the left of graphic "box" to the left of graphic "box" + 3.1
end if
end if
if x is "right" then
set the right of graphic "box" to the right of graphic "box" + 3
if right of graphic "box" > the right of card "mycard" then
set the right of graphic "box" to the right of card "mycard"
end if
if intersect( graphic "box" , group "maze" , "opaque pixels") then
set the right of graphic "box" to the right of graphic "box" - 3.1
end if
end if
--
--Enemies
if intersect( graphic "box" , graphic "enemie1", "opaque pixels") then
set the loc of graphic "box" to 120,70
end if
if intersect( graphic "box" , graphic "enemie2", "opaque pixels") then
set the loc of graphic "box" to 120,70
end if
if intersect( graphic "box" , graphic "enemie3", "opaque pixels") then
set the loc of graphic "box" to 120,70
end if
if intersect( graphic "box" , graphic "enemie4", "opaque pixels") then
set the loc of graphic "box" to 120,70
end if
if intersect( graphic "box" , graphic "enemie5", "opaque pixels") then
set the loc of graphic "box" to 120,70
end if
if intersect( graphic "box" , graphic "enemie6", "opaque pixels") then
set the loc of graphic "box" to 120,70
end if
--
--Coins
if intersect( graphic "box" , graphic "Coin1", "opaque pixels") then
if Coin1 = 0 then
add 1 to Coins
end if
put 1 into Coin1
hide graphic "Coin1"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin2", "opaque pixels") then
if Coin2 = 0 then
add 1 to Coins
end if
put 1 into Coin2
hide graphic "Coin2"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin3", "opaque pixels") then
if Coin3 = 0 then
add 1 to Coins
end if
put 1 into Coin3
hide graphic "Coin3"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin4", "opaque pixels") then
if Coin4 = 0 then
add 1 to Coins
end if
put 1 into Coin4
hide graphic "Coin4"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin5", "opaque pixels") then
if Coin5 = 0 then
add 1 to Coins
end if
put 1 into Coin5
hide graphic "Coin5"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin6", "opaque pixels") then
if Coin6 = 0 then
add 1 to Coins
end if
put 1 into Coin6
hide graphic "Coin6"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin7", "opaque pixels") then
if Coin7 = 0 then
add 1 to Coins
end if
put 1 into Coin7
hide graphic "Coin7"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin8", "opaque pixels") then
if Coin8 = 0 then
add 1 to Coins
end if
put 1 into Coin8
hide graphic "Coin8"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin9", "opaque pixels") then
if Coin9 = 0 then
add 1 to Coins
end if
put 1 into Coin9
hide graphic "Coin9"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin10", "opaque pixels") then
if Coin10 = 0 then
add 1 to Coins
end if
put 1 into Coin10
hide graphic "Coin10"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin11", "opaque pixels") then
if Coin11 = 0 then
add 1 to Coins
end if
put 1 into Coin11
hide graphic "Coin11"
put Coins into field "Coinsv"
end if
if intersect( graphic "box" , graphic "Coin12", "opaque pixels") then
if Coin12 = 0 then
add 1 to Coins
end if
put 1 into Coin12
hide graphic "Coin12"
put Coins into field "Coinsv"
end if
--
--Goal
if intersect( graphic "box" , graphic "Goal" , "opaque pixels") then
set the loc of graphic "box" to 120,70
show graphic "Coin1"
show graphic "Coin2"
show graphic "Coin3"
show graphic "Coin4"
show graphic "Coin5"
show graphic "Coin6"
show graphic "Coin7"
show graphic "Coin8"
show graphic "Coin9"
show graphic "Coin10"
show graphic "Coin11"
show graphic "Coin12"
put 0 into Coins
put 0 into Coin1
put 0 into Coin2
put 0 into Coin3
put 0 into Coin4
put 0 into Coin5
put 0 into Coin6
put 0 into Coin7
put 0 into Coin8
put 0 into Coin9
put 0 into Coin10
put 0 into Coin11
put 0 into Coin12
put Coins into field "Coinsv"
go card 3
end if
--
end arrowKey
on closeCard
play stop
put 0 into Coin1
put 0 into Coin2
put 0 into Coin3
put 0 into Coin4
put 0 into Coin5
put 0 into Coin6
put 0 into Coin7
put 0 into Coin8
put 0 into Coin9
put 0 into Coin10
put 0 into Coin11
put 0 into Coin12
end closeCard
With best regards, Moorky.