So I'm working on AoCE, and I came to the stage where I have to convert isometric tile coordinates to screen coordinates. This itself is not very difficult, just something like

Code:
var isoToScreen = function(x, y) {
    var posX = (x - y) * tileW;
    var posY = (x + y) * tileH / 2;

    return [posX, posY];
};

would work. However; this formula assumes that the topleft corner (coordinates (0,0)) is at a fixed position, and eventually visible. Sadly, my field doesn't fit in the entire screen, so I have to work with offsets. This didn't turn out well Sad Can someone *maybe* check what's wrong with my code/formulas?


Code:
; Check if we need to draw the puppet:
; X_tile - Y_tile in [X_1-Y_1,X_1-Y_1+9]
; X_tile - Y_tile - (X-1 - Y_1) in [0,9]
; X_tile - Y_tile - (iy+0) in [0,9]

; X_tile + Y_tile in [X_1+Y_1,X_1+Y_1+23]
; X_tile + Y_tile - (X_1+Y_1) in [0,23]
; X_tile + Y_tile - (iy+3) in [0,23]

; Check if X is in the range
    ld a, (ix+puppetX)
    sub a, (ix+puppetY)
    sbc hl, hl
    ld l, a
    ld de, (iy+TopLeftXTile)
    or a, a
    sbc hl, de
    ld (iy+6), l
    ld de, -10
    add hl, de
    jr c, DontDrawPuppet
; Check if Y is in the range
    sbc hl, hl
    ld a, (ix+puppetX)
    add a, (ix+puppetY)
    ld l, a
    jr nc, +_
    inc h
_:  ld de, (iy+TopLeftYTile)
    or a, a
    sbc hl, de
    ld (iy+7), l
    ld de, -24
    add hl, de
    jr c, DontDrawPuppet
DrawPuppet:
    ld a, (iy+6)
    add a, (iy+7)
    add a, a
    add a, a
    add a, a
    add a, 31
    ld hl, variables+OFFSET_Y ; just the offset from the screen, since the field is shifted with 4 pixels each time
    add a, (hl)
    ld l, a
    ld h, 160
    mlt hl
    add hl, hl
    ld e, (iy+6)
    ld d, 16
    mlt de
    add hl, de
    ld a, (variables+OFFSET_X)
    ld d, 0
    ld e, a
    add hl, de
    ld de, (currDrawingBuffer)
    add hl, de

The output is HL=pointer to topleft corner of the right tile.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement