Hi Carl,
>> That looks great, so for a game, you would have to put a character on the
>> screen at a start point, this could be where it is always empty.
Indeed, you'd want to draw thin walls to leave room for the UDG.
> dokey could move the char, and coll could see if the next move is into a
> wall, if it is it will not move there, but if its empty it can move on.
Coll is for collision? Yes. You can test to see if you
> A timer could be added as a limit, and other chars on a loop could patrol
> the maze and if coll finds the value of this it could be game over.
> One question, how many enemies can the program support? I never seem to work
> it out as the way I do it relies on two sprites moving at the same time and
> speed, ie blitz! the bomb and the planes use the same timeout delimiter
Well, as many as the computer has the performance for. Remember a game
is like a movie; so, there's only 1 pause between frames:
begin
MoveAllTheMeanies
doKey DoPlayer
speed @ timeout
gameover @ until
All the meanies move in the same frame using a loop moving one meanie
at a time, but without a pause between moving one meanie and the next
because we only need to see the meanies have moved at the end of the
frame (in the same way that actors in a film move simultaneously; they
don't wait for the previous actor to move before they take a step). In
reality because the computer only moves one meanie at a time there are
slight timing differences between each move, but the computer does it
so quickly the user won't notice - s/he just sees each new frame when
we pause in the main loop ( speed @ timeout ) .
In practice video generation makes it smoother than it might be.
FIGnition executes most of its Forth programs during the top and
bottom margins of the image; so when we move a number of meanies
several (probably all of them in our case) will move during that time
and the screen will only show the update when it regenerates the image
after the top margin. Have a look at the gdemo example:
https://sites.google.com/site/libby8dev/fignition/examples#gdemo
The command for moving all the characters is udgmove:
: udgmove ( lim -- )
0 do
i poz @ dup
vcalc ( old new )
swap 32 swap ic!
i 7 and over ic!
i poz !
loop ;
There's no pausing there! If there was a pause in the game it would go
in the gdem loop later in the program, but in gdem we just want to
know how many udgs we can move around in Forth before it slows down.
In practice we can move about 80 UDGs at about 10fps.
Hope this helps!
-cheers from julz