There's nothing to it, mate. Start simple. Here's a simple one that should make a dot 'walk' left and right on the screen, turninng at each end. Don't have max here so may have a couple of bugs.
The heart of the machine is a select statement that executes the right code for the current state. In this example if the state is STATE_GO_RIGHT, we send our dot one pixel to the right and look to see if it got to the right edge of the screen. When it does, it flips the state to STATE_GO_LEFT which will start it walking to the left. The current state is just stored as an integer - declaring consts with names makes the code easier to read.
const STATE_GO_RIGHT=0
const STATE_GO_LEFT=1
current_state=STATE_GO_RIGHT
x=0
graphics 800,600,32,60
repeat
cls
select current_state
case STATE_GO_RIGHT
x=x+1
if x=800 current_state=STATE_GO_LEFT
case STATE_GO_LEFT
x=x-1
if x=0 current_state=STATE_GO_RIGHT
end select
plot x,100
flip
until keyhit(KEY_ESCAPE) I know this behaviour wont seem very 'intelligent' but anything more complicated really just builds on this simple principle.
|