Jump to content
IGNORED

Easy way to set player graphic to number


Karl G

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 3
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

Curious. I was playing around with this to swap player1 for a number.

 

Is it possible to perform this in reverse? And have it to where you swap a sprite into the score?

 

As an example, say the game starts. Instead of a score it scrolls "PRESS FIRE!" and when you do it changes the data back to numbers.

Link to comment
Share on other sites

I'll have to take a look, but I think the pointer to the graphics for the score is hardcoded somewhere, and is set each frame from non-persistant variables, so it's not just a simple matter of changing a pointer to point at new data. I'll look at this sometime later to confirm. 

Link to comment
Share on other sites

I checked, and it was as I suspected. The scoretable is hardcoded in a couple of places, and there's no permanent pointer to the scoretable graphics.  It could be hacked to use a persistent pointer and allow the graphics to be used to change on the fly, but it would require sacrificing two variables for that purpose.

 

If it were done, it might not work the way you were picturing. You would define graphics to replace the normal score digits, and set the score to load the appropriate graphics.  You can fit two skinny letters in each digit, so for your "PRESS FIRE!" example, you would make the graphics for digit 0 be "PR" and digit 1 be "ES", and so on all the way through digit 5 just being the "!".  You could then set the pointer to use the new graphics, and set the score=012345 to get the message you want, then change the pointer and the score back after you no longer need that.

 

If you or anyone else has a specific need for that kind of hacked solution, I can whip something up.  Keep in mind that it will take a lot of ROM if you have a lot of messages due to needing to create every letter combo as its own unique graphic as opposed to using something like the text minikernel for this functionality.

 

Link to comment
Share on other sites

That is very interesting. I don't really have a particular use for that. I was just curious if it was a simple swap. That would be an interesting effect if you had the free space for it. But then it might be better to just use the text minikernel at that point.

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