Author Topic: Same routine, different outputs.  (Read 12483 times)

0 Members and 1 Guest are viewing this topic.

Offline bilyp

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +9/-1
  • Axing the z80
    • View Profile
Same routine, different outputs.
« on: November 16, 2011, 12:29:40 am »
So I have a matrix (12x8) for a tilemapper that I wrote...
Code: [Select]
:[000000000000]→GDB1
:[000000000002]
:[000000000001]
:[000000000001]
:[220000000001]
:[112000000021]
:[331220002213]
:[333112221133]
and a routine that displays it:
Code: [Select]
:For(A,0,7)
:For(B,0,11)
:Pt-On(B*8,A*8,nib{A*12+B+(GDB1*2)}*8+Pic1)
:End
:End
and then a routine to detect if you are in a block, and store the block ID to C, where B = X+2, A = Y + 16. (the character is 16x8)
Code: [Select]
:If nib{B*12+A+(GDB1*2)}→C
but even though the core of the routines
Code: [Select]
:nib{VAR1*12+VAR2+(GDB1*2)}
are the same, only the first one shows correct blocks. The second one sometimes detects non existent blocks, and doesn't detect some existing blocks.

Is there something wrong in my syntax? Please help, I could not find the reason. :(
(attached is the source of the file with the buggy routines)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Same routine, different outputs.
« Reply #1 on: November 16, 2011, 09:25:36 am »
How big are your blocks? If they're not 1x1, it doesn't make sense to use B=X+2 and A=Y+16 to locate your block in the matrix. Assuming they're 8x8, you should divide X and Y by eight.




Offline bilyp

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +9/-1
  • Axing the z80
    • View Profile
Re: Same routine, different outputs.
« Reply #2 on: November 16, 2011, 10:14:15 am »
Like I said, the player is 16 tall, and 8 wide. The X and Y values correspond to the top left corner of the character, and i want the middle of the bottom part of the character to see if its in a block, and the block below that to see if it is standing on a block. And even though they are 8*8 tiles, I still think that it needs to be pushed down, please correct me if I'm wrong.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Same routine, different outputs.
« Reply #3 on: November 16, 2011, 08:45:25 pm »
Look closely at your first for loop.  A and B are in the ranges from 0 to 7 and 0 to 11 respectively.  You are trying to do the same with Y and X in the ranges 0 to 63 and 0 to 95.  So basically to remedy this, just divide each coordinate by 8 and that should give you the correct block.  In fact, you should turn this into a subroutine because you will likely reuse it a lot:

Code: [Select]
:.Syntax TILE(X,Y)
:Lbl TILE
:Return nib{r2/2/2/2*12+(r1/2/2/2)+(GDB1*2)}

Now in your for loop, you can call TILE(B*8,A*8 ) and elsewhere call TILE(X+2,Y+16).

EDIT: Added a speed optimization since it saves you from needing the division subroutine.
« Last Edit: November 16, 2011, 08:49:16 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline bilyp

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +9/-1
  • Axing the z80
    • View Profile
Re: Same routine, different outputs.
« Reply #4 on: November 17, 2011, 09:56:57 am »
Thanks! I just tested and it worked! You were right I was going to need that routine in many places.  ;D