1. Funny Moves

------=_NextPart_000_0007_01C05335.417606C0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all.

I've been working on a simple program that uses get_key() to "move" a =
bitmap. It does this by going through a loop to check if the right key =
has been pressed and moves it right or left accordingly in increments of =
1. What I'd like to know, is why when I go "left" three times, then hit =
"right" it goes left once more, then right. Why is this? And how can I =
fix it?

-Thanks
-Thomas

------=_NextPart_000_0007_01C05335.417606C0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I've been working on a simple program =
that uses=20
get_key() to "move" a bitmap. It does this by going through a loop to =
check if=20
the right key has been pressed and moves it right or left accordingly in =

increments of 1. What I'd like to know, is why when I go "left" three =
times,=20
then hit "right" it goes left once more, then right. Why is this? And =
how can I=20
fix it?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Thanks</FONT></DIV>

------=_NextPart_000_0007_01C05335.417606C0--

new topic     » topic index » view message » categorize

2. Re: Funny Moves

On Mon, 20 Nov 2000 21:02:55 -0800, Thomas wrote:

>Hi all.
>
>I've been working on a simple program that uses get_key() to "move" a
bitmap. It does this by going through a loop to check if the right key has
been pressed and moves it right or left accordingly in increments of 1.
What I'd like to know, is why when I go "left" three times, then
hit "right" it goes left once more, then right. Why is this? And how can I
fix it?
>
>-Thanks
>-Thomas

Thomas,

I'd rather not venture to guess where your problem lies without first
examining your code.

-- Brian

new topic     » goto parent     » topic index » view message » categorize

3. Re: Funny Moves

>What I'd like to know, is why when I go "left" three times, then hit
> >"right" it goes left once more, then right. Why is this? And how can >I
>fix it?
>


If you're holding "left" down, then release it and hit "right", there might
be a "left" still in the kbd buffer.
You might want to try out Michael Bolin's keyread.e (given that you're
writing a DOS-program that is).


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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Funny Moves

can you post the program so we can look at it and comment?

--Al

new topic     » goto parent     » topic index » view message » categorize

5. Re: Funny Moves

On Mon, 20 Nov 2000 21:02:55 -0800, Paul Kerslake <paulk at UNISERVE.COM>
wrote:

>Hi all.
>
>I've been working on a simple program that uses get_key() to "move" a
bitmap. It does this by going through a loop to check if the right key has
been pressed and moves it right or left accordingly in increments of 1.
What I'd like to know, is why when I go "left" three times, then
hit "right" it goes left once more, then right. Why is this? And how can I
fix it?
>
>-Thanks
>-Thomas
>

  Thomas:
     Look at your loop and see where in your loop
     you are checking the key. You may be checking
     the loop after the leftkey is already executed
     and not before.
  Bernie

new topic     » goto parent     » topic index » view message » categorize

6. Re: Funny Moves

Sorry for the enigmatic letter, I don't like to give away what I'm working
on 'till it's decent. So, here is the piece of code that's causing the
problem: Please and thanks for looking at it.
--Thomas
---/\===

--Start your binary!

integer action
atom LEFT,RIGHT
LEFT=333
RIGHT=331

procedure walkLEFT()
        if action=LEFT then
            display_image({sides,ups}, walkL[2])    --just BMPs*
            pause(.1)
            display_image({sides,ups}, blackout[2])        *
            display_image({sides,ups}, walkR[2])            *
            pause(.1)
            sides+=1
        end if
end procedure

procedure walkRIGHT()
        if action=RIGHT then
            display_image({sides,ups}, walkL[2])
            pause(.1)
            display_image({sides,ups}, blackout[2])
            display_image({sides,ups}, walkR[2])
            pause(.1)
            sides-=2
        end if
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

new topic     » goto parent     » topic index » view message » categorize

7. Re: Funny Moves

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 Parnell
Melbourne, Australia
(Vote [1] The Cheshire Cat for Internet Mascot)


----- Original Message -----

> Sorry for the enigmatic letter, I don't like to give away what I'm working
> on 'till it's decent. So, here is the piece of code that's causing the
> problem: Please and thanks for looking at it.
> --Thomas
> ---/\===
>
> --Start your binary!
>
> integer action
> atom LEFT,RIGHT
> LEFT=333
> RIGHT=331
>
> procedure walkLEFT()
>         if action=LEFT then
>             display_image({sides,ups}, walkL[2])    --just BMPs*
>             pause(.1)
>             display_image({sides,ups}, blackout[2])        *
>             display_image({sides,ups}, walkR[2])            *
>             pause(.1)
>             sides+=1
>         end if
> end procedure
>
> procedure walkRIGHT()
>         if action=RIGHT then
>             display_image({sides,ups}, walkL[2])
>             pause(.1)
>             display_image({sides,ups}, blackout[2])
>             display_image({sides,ups}, walkR[2])
>             pause(.1)
>             sides-=2
>         end if
> 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

new topic     » goto parent     » topic index » view message » categorize

8. Re: Funny Moves

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 message » categorize

9. Re: Funny Moves

K,

Looks to me like you should be updating the variable 'sides'
BEFORE calling 'display(...)'.

What your seeing now when calling 'display(..)'
is probably the remnant of the last 'sides' update
from a previous call rather then what you really want.

Thats if i understand your code fragments correctly...

for example:

  sides+=1
  display(...)

Good luck with it.

--Al

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu