Jump to content
IGNORED

Using Different Graphic Based on Direction


Recommended Posts

I have the following setup:

; player graphic
PlayerGraphic
PlayerDirectionUpGraphic
	.byte #%00111100
	.byte #%01111110
	.byte #%11000001
	.byte #%10111111
	.byte #%11111111
	.byte #%11101011
	.byte #%01111110
	.byte #%00111100

PlayerDirectionDownGraphic
	.byte #%00111100
	.byte #%01111110
	.byte #%11000001
	.byte #%10111111
	.byte #%11111111
	.byte #%11101011
	.byte #%01111110
	.byte #%00111100

PlayerDirectionLeftGraphic
	.byte #%00111100
	.byte #%01111110
	.byte #%11000001
	.byte #%10111111
	.byte #%11111111
And a ram variable:

PlayerDirection     .ds 1
With equates as follows:

DIRECTION_UP              equ 1
DIRECTION_DOWN       equ 2
DIRECTION_LEFT          equ 3
DIRECTION_RIGHT       equ 4
What is the best way to handle changing the sprite being displayed based on the "direction" the player is facing?

 

Sent from my LG-M150 using Tapatalk

Link to comment
Share on other sites

First redefine your directions to start at 0 - saves a lot of unnecessary code and even more unnecessary religious discussions with LUA programmers ;)

 

Then create a table of pointers to your graphics:

TBL_GFX_PTR_LO:
    .byte <(PlayerDirectionUpGraphic)
    .byte <(PlayerDirectionDownGraphic)
    .byte <(PlayerDirectionLeftGraphic)
    .byte <(PlayerDirectionRightGraphic) 

we need two bytes for a sprite pointer:

    PlayerGfxPtr ds 2

each frame we initialise said pointer (first HI- then LO-byte):

    lda #>(PlayerDirectionUpGraphic)
    sta PlayerGfxPtr+1
    ldy PlayerDirection
    lda TBL_GFX_PTR_LO,y
    sta PlayerGfxPtr
     

now, in our kernel, we can load from that pointer:

    lda (PlayerGfxPtr),y
    sta GRP0 

(I'm writing this code from memory, be wary)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...