Re: Funny Moves

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hello Thomas,


>Hi Thomas,
>I think you're learning lots and your coding style has improved remarkably.
>Well done.
>
>I suspect the problem is that you display first then move to the next
>position. The usual way to render moving images is ...
>
>   if image was displayed then
>      hide it at its current position
>   end if
>   move to the new position
>   display the image
>
>I'm not expert here so maybe somebody else can elaborate.

Derek is right. A few other things I noticed about your code...

You use "if action=LEFT.." statement in two places: in the
loop and in the walkLEFT() procedure. Same for the "RIGHT"
action. This is unnesesary but some might condone this
redundancy because it looks like you are being extra careful
about what you are doing. However, only knowing about the
code you have shown, it looks unnesesary. Don't remove the
extra "if"s if you think they are really needed but I don't
think they are.

Also, I notice you have a pause before the erase and after the
display. All you really need is one after the display. Maybe
a double long one. Again, this is a change that shouln't change
the functionality of the program but makes it shorter and more
readable.

Also in your sides calculations I don't know if it is right or
not but I thought left was minus and right was plus. Besides
you are not adding the same as you are subtracting.

Below I have changed your code to accomodate my suggestions and
Derek's. Please try to understand what I have done before you
incororate it into your program. You never know I might have
put an error in there. ;)

> > integer action
> > atom LEFT,RIGHT
> > LEFT=333
> > RIGHT=331
> >
> > procedure walkLEFT()
> >     display_image({sides,ups}, blackout[2])
> >     sides-=1
> >     display_image({sides,ups}, walkL[2])
> >     display_image({sides,ups}, walkR[2])
> >     pause(.2)
> > end procedure
> >
> > procedure walkRIGHT()
> >     display_image({sides,ups}, blackout[2])
> >     sides+=1
> >     display_image({sides,ups}, walkL[2])
> >     display_image({sides,ups}, walkR[2])
> >     pause(.2)
> > end procedure
> >
> > procedure walkies()
> >     action=get_key()
> >     if action=LEFT then
> >         walkLEFT()
> >     elsif action=RIGHT then
> >         walkRIGHT()
> >     end if
> > end procedure
> >
> > while 1 do
> > walkies()
> > end while

_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu