Jump to content
Karl G

Easy way to set player graphic to number

Recommended Posts

Normally if you wanted to set one of the player graphics to display a number, you would do something like an "on ... goto" statement, defining a new digit for each of the digits. To save time and code, you can instead make use of the built-in graphics for the score digits with just a few lines of code.  First, in your program's definitions, you will want to define a couple of constants that contain the two bytes of the ROM address where the score digits are defined:

 

    const score_table_high = >scoretable
    const score_table_low = <scoretable

 

The code to change the player graphic to a number follows. This example uses player 0, but you can change the 0s to 1s if you wish to use player 1. Also, I use the variable DisplayNumber here, which you will want to change to whatever variable holds the number to be displayed:

 

    temp1 = DisplayNumber
    player0height = 7
    player0pointerhi = score_table_high
    temp1 = temp1 * 8
    player0pointerlo = temp1 + score_table_low

 

That's all that's needed. You will set the color, position, and NUSIZx value as normal. Note that you will probably want to use a double-width NUSIZx value for the number to look the same proportionally as the score digits (larger, but the same dimensions).

  • Like 1

Share this post


Link to post
Share on other sites

Three and a half questions:

 

1. Does this work with all kernels? (Would the numbers be upside down when using some kernels?)

 

2. Since bB uses the lower temp variables for various jobs will there be any problems using temp1?

 

3. Is it OK if I adapt your post and put it on the bB page?

Edited by Random Terrain

Share this post


Link to post
Share on other sites

What is the half question?  :)

 

1) I've only tested this with the standard kernel so far. I am pretty sure it won't work with the DPC+ kernel. it will probably work with the Multisprite kernel, but I need to check variable names, and test it.

 

2) it didn't cause any problems when I used it, but feel free to change it to something like temp4 if you post it.

 

3) Sure. 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Just tried it with DPC+ and you're right. Doesn't work. Is there anything that could be changed to make it work?

Share this post


Link to post
Share on other sites

I honestly don't know the internals of the DPC+ kernel that well. I'll take a look at how the score itself is done to see if there's an easy way to do that. 

  • Like 1

Share this post


Link to post
Share on other sites

I stuck this in an existing example program. Double click the fire button to change the number:

 

ex_numbers_standard_kernel_with_coordinates_2019y_12m_22d_0019t.bin

 

 

(To change the size of a selected object, hold down the fire button and press left or right to cycle through the different sizes.)

Edited by Random Terrain
  • Like 1

Share this post


Link to post
Share on other sites

It looks like the multisprite always puts out the player0 first/bottom-most data line. The bB interpreter always inserts an extra zeroed line for graphics for it, but not the virtual sprites. The player0 pointer is updated on each kernel line to maintain this. I'm thinking batari didn't have enough kernel time where he needed the player graphic update to happen, so he used this technique as a trade-off.

 

I don't think you'll get your technique to work here, without adding a bunch of otherwise unused zeroes to the top of each score digit. If you decide to do this, you'll need to adjust the starting position of the score graphics to allow for the padding.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks. I think this could still be a useful trick for users of the multisprite kernel to use with the virtual sprites, at least. It's probably not worth hacking the score graphic data just to make it work with P0, however,  but it's good to know why that one did not work.

  • Like 1

Share this post


Link to post
Share on other sites

I need to test it when I am in front of my computer again, but I think this might also mean that the documented trick to make sprites Melt Away by decreasing the height variable might also not work with P0 and the multisptite kernel. If this is true, then that would also be worth documenting.

  • Like 2

Share this post


Link to post
Share on other sites

Just in case somebody asks in the future, is there any way to shoehorn a two digit number into a sprite using this technique? For Tone Toy 2008, the numbers had to be drawn and placed in sprite data. If it could be done without making a custom strip of numbers, that would be very handy.

Share this post


Link to post
Share on other sites

If you made a custom score font, and made use of hex digits, you could do 0 through 15 that way, but not above that.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Karl G said:

I need to test it when I am in front of my computer again, but I think this might also mean that the documented trick to make sprites Melt Away by decreasing the height variable might also not work with P0 and the multisptite kernel. If this is true, then that would also be worth documenting.

I just tried it out. It works fine, since the sprite data is upside down. The last P0 data to be displayed is actually the first byte in the table. i.e the zero value. To make it stay in place and "melt" you need to also add to player0y as you decrease player0height, otherwise it rolls up like a roller blind.

 

 

 

  • Like 2

Share this post


Link to post
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.

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...