Game play and repeat loops
Ken Ray
kray at sonsothunder.com
Sun Oct 19 11:32:12 EDT 2003
Mike, using a repeat loop is pretty ineffecient and hard to control; I'd
recommend using "send" messages and then trap for the arrow keys going
down with the "on arrowKey" handler.
Something like this (I'm assuming an image is being moved, and escape
stops the game):
global gCurrentDirection
on StartGame
put "left" into gCurrentDirection
send "MoveObject" to me
end StartGame
on MoveObject
switch gCurrentDirection
case "up"
set the top of img 1 to (the top of img 1-1)
break
case "down"
set the bottom of img 1 to (the bottom of img 1+1)
break
case "left"
set the left of img 1 to (the left of img 1-1)
break
case "right"
set the right of img 1 to (the right of img 1+1)
break
end switch
send "MoveObject" to me in 20 milliseconds
end MoveObject
on arrowKey pDirection
put pDirection into gCurrentDirection
end arrowKey
on escapeKey
cancel (item 1 of the pendingMessages) -- assumes no other messages
are going on
end escapeKey
Hope this helps,
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com
> [mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of
> Mike Brown
> Sent: Sunday, October 19, 2003 8:43 AM
> To: use-revolution at lists.runrev.com
> Subject: Game play and repeat loops
>
>
> Hi Everyone,
>
> I am scripting a simple animated game. An object moves
> across the stack driven by commands within a repeat loop. I
> want to change variables within the repeat loop when the user
> selects one of the arrow keys (up, down, left, right).
> Basically, as the object moves across the screen, it's
> direction can be changed by selecting the arrow key.
>
> Is the use of a repeat loop for this incorrect or is there a
> way to insert condition changes into the loop?
>
> Thanks,
> Mike
>
>
> Mike Brown
> Cyber-NY Interactive
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-> revolution
>
More information about the use-livecode
mailing list