Author Topic: Some (big) issues with ghosts  (Read 3644 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael.3545

  • LV3 Member (Next: 100)
  • ***
  • Posts: 69
  • Rating: +13/-7
    • View Profile
Some (big) issues with ghosts
« on: October 26, 2010, 06:49:08 pm »
Hello Omnimagicians, I seem to be having a bit of an issue.  I am working on a pacman clone.  The ghosts used to behave like this:


I finally added a method of controlling the ghost's movements, and instead of moving as expected, I got this:


This is the code I added:
Code: [Select]
:   .G-BRAIN
:..............
:
:   .On tile
:   !If {A}^7 or ({B}^7)
:    L4+2?P
:    0?{L4}r
:    0?{P}
:    If J
:     J*?1?{L4}
:    Else
:     K*?1?{L4+1}
:    End
:
:.stop indent
:
:.1  UP
:!If pxl-Test({A},{B}-1)r
:If {L4+1}??1
: 0?{{P}*2+L4+3}
: ?1?{{P}*2+L4+4}
: {P}+1?{P}
:End
:End
:
:.2  RIGHT
:!If pxl-Test({A}+7,{B})r
:If {L4}?1
: 1?{{P}*2+L4+3}
: 0?{{P}*2+L4+4)
: {P}+1?{P}
:End
:End
:
:.3  DOWN
:!If pxl-Test({A},{B}+7)r
:If {L4+1}?1
: 0?{{P}*2+L4+3}
: 1?{{P}*2+L4+4}
: {P}+1?{P}
:End
:End
:
:.4  LEFT
:!If pxl-Test({A}-1,{B})r
:If {L4}??1
: ?1?{{P}*2+L4+3}
: 0?{{P}*2+L4+4}
: {P}+1?{P}
:End
:End
:
:.resume indent
:
:    {rand^{L4+2}*2+L4+3}?P
:    {P}?iPart(U}
:    {P+1}?iPart(V}
:    sub(GGD)
:   End
:
:..............

I am using L4 as super temporary storage.  It is used in one routine during my loop, and I write completely new data to it each time I use it, so volatility isn't an issue.  I tested all of the things I wasn't sure about (such as using pxl-test() on an off-screen locaiton) and all of that sort of stuff works as expected.

Here is what my variables do:
  • A,B: Pointers to where the ghosts x and y positions are saved.  (1 byte each)
  • J,K: Temporary variables, they store the ghost's x and y velocity.*
  • U,V: Pointers to where the ghost's x an y velocity are stored.  (1 nibble each)*
  • P:  A temporary variable I use to avoid repeating math I've already done.


Here is the structure of L4:
  • {L4},{L4+1}: the x and y velocity opposite to which a ghost is currently moving at.*
  • {L4+3}: The number of x and y velocities stored in the next 6 bytes of ram
  • {L4+4},{L4+5}: A possible x,y velocity*
  • {L4+6},{L4+7}: same as above
  • {L4+8},{L4+9}: same as above


*These values are either 1, 0, or -1.

Thanks for your help!  It is depressing that I couldn't figure it out myself.  :'(

Offline Michael.3545

  • LV3 Member (Next: 100)
  • ***
  • Posts: 69
  • Rating: +13/-7
    • View Profile
Re: Some (big) issues with ghosts
« Reply #1 on: November 01, 2010, 01:54:07 pm »
*bump*

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Some (big) issues with ghosts
« Reply #2 on: November 01, 2010, 03:24:44 pm »
Are the black pieces (the walls) black on the backbuffer as well? Because I see in your code you are using pxl-test()r

Also, I'm not sure how well negative numbers and nibbles mix. I had this problem in cuberunner, and ended up just using whole bytes for the direction of the velocity vector. Normally a -1 is parsed as a 65535, and a -1 in a sign{} is parsed as a 255. (talking about addition/multiplication here), but a -1 as a nibble is parsed as....15? I'm not really sure.

Third, this looks problematic:
Code: [Select]
:    {rand^{L4+2}*2+L4+3}→P
:    {P}→iPart(U}
:    {P+1}→iPart(V}

If I can understand what you're doing, L4 holds numbers you want to use, not pointers. So I think you might want
Code: [Select]
:    rand^{L4+2}*2+L4+3→P
:    {P}→iPart(U}
:    {P+1}→iPart(V}
instead.
« Last Edit: November 01, 2010, 03:26:56 pm by squidgetx »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Some (big) issues with ghosts
« Reply #3 on: November 01, 2010, 06:39:37 pm »
Well it took like three hours of stepping through the instructions one-by-one in wabbitemu's debugger, but I think I isolated and solved all the problems. :)

Offline Michael.3545

  • LV3 Member (Next: 100)
  • ***
  • Posts: 69
  • Rating: +13/-7
    • View Profile
Re: Some (big) issues with ghosts
« Reply #4 on: November 01, 2010, 11:25:57 pm »
Judging by what runer changed, I guess it was an issue with the nibbles values, as squidget suggestet.

Well it took like three hours of stepping through the instructions one-by-one in wabbitemu's debugger, but I think I isolated and solved all the problems. :)

This is way beyond what I expected from anyone.  Runer112, you have earned my undying thanks and definitely mention in the final program.  Your new source is indeed working exactly as it should, much to my elation.  I have sent it to my calc, and will be looking to see what you did over the next few days.  If I can't work it out myself, I will post back here.  Thanks!

 :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Some (big) issues with ghosts
« Reply #5 on: November 01, 2010, 11:58:07 pm »
Wow nice Runer112. Hopefully it works well :D