In order to ensure that the player no longer moves the Stop variable (as stated earlier) is set to 0 ensuring that the run action no longer plays. When the collision is made the code also ensures that the hit animation will play giving the effect of an actually impact.
The code is as follows
private action CheckGears ()
This action is called in Gameloop
for each sprite in ◳ Gears
where true
do
if sprite → x + sprite → width < 0 then
This ensures that when a gear(sprite) leaves the screen it will return. This also dictates whether the Gear will be Large or Small
◳ Gears → remove(sprite)
sprite → delete
LorS is whether the gears will be Large or Small. if LorS = 1 the gear will be Large if LorS is 2 the gear will be Small
◳ LorS := math → random(2) + 1
if ◳ LorS = 1 then
▷ SpawnLGear
else
▷ SpawnSGear
end if
else do nothing end if
if ◳ sprite → overlaps with(sprite) then
This determines what occurs when the gears hit the sprite (character)
This stops the score from increasing
◳ scoreadd := 0
◳ sprite → create animation → stop
This links to Background Scroll and stops the background from scrolling
◳ Direction := 0
This plays the animation "hit"
◳ sprite → create animation → play frames("Hit")
This stops the sprite moving
◳ sprite → set speed x(0)
✿ Ow Cute2 → play
This prevents the sprite from continuing to run left or right
◳ Stop := 0
▷ gameOver
else
▷ Run
end if
end for each
end action
Again, appropriate thought to where to code this important part of the program
ReplyDelete