Join us on Discord!
You can help CodeWalrus stay online by donating here.

Sprites v3, a new ASM lib to enhance TI-84 Plus CE BASIC games [tutorial]

Started by Dream of Omnimaga, May 16, 2016, 12:42:15 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

unregistered

Perhaps I found why there was a bug !
In this program, when you start to define sprites, you ommit sprite #0 !
Please don't forget that we must start from 0, because meanwhile this allows the routine to (re)set sprites :)

Asm(prgmSETTINGS
0:Asm(prgmCLSCREEN
{20,25,255,148,224,227,0,12,4,34,231,129
Asm(prgmPALETTE
1→dim(ʟWALRS
{129,224,227,231,129,224→L₁
For(Z,7,39
randInt(0,1→L₁(Z
End
"001,75,410011101011121111111110111111001110
Asm(prgmSPRITE
"002,75,450000004555000444455544440004000000
Asm(prgmSPRITE
"003,75,400606006006006066466060060060060600
Asm(prgmSPRITE
"004,C5,7000099990000099988889999988877778888877700007777700000000000
Asm(prgmSPRITE
"005,88,40330330012212210112112103333333332323333323233333333333330330330
Asm(prgmSPRITE
"006,55,70000000000000000000000000
Asm(prgmSPRITE
"007,88,3A33A33AA1221221A1121121A333333333232333332323333333333333A33A33A
Asm(prgmSPRITE
"668,Y5,4BBB666BBB6666BBBBBB6BBB66666BBBBBB44466644464446664446444666664446665556665556555666555655565556555555AAAAAAAAA6AAA666AAA6AAA66666AAA6662226662226666222222622266666222666
Asm(prgmSPRITE
"669,Y5,46666BBB666BBB6BBBBBB6BBB6666666BBB44464446664446444666644466666664446666555666555655555565555556666555AAA6AAA666AAA6666AAA6AAA666AAA66662226666222666622222262226662226222
Asm(prgmSPRITE
"616,75,4BBB6BBB46664665666555A666A662226222
Asm(prgmSPRITE
{0,0,320,80,0,0,77,320,8,16,0,78,320,1,0,0,85,320,8,25,0,86,320,1,16,0,93,320,8,29,0,94,320,1,25,0,101,320,8,14,0,102,320,1,29,0,109,320,61,231,0,110,320,1,14,0,170,320,71,5,2,41,316,4,129
Asm(prgmCLSCREEN
{6,146,111,7,2,17,8,138,17,9,290,17
Asm(prgmSPRITE
For(A,0,288,24
{10+A,168,1,4,16,18+A,170,4,1,231,26+A,169,4,4,14
Asm(prgmCLSCREEN
End
{89,52,14,0,1,2
Asm(prgmPRINT
"A GAME OF WALRUSES
Asm(prgmPRINT
{12,179,0,5
Asm(prgmPRINT
"PC a\nd Atari 2600 game by JWinslow23
Asm(prgmPRINT
{20,199
Asm(prgmPRINT
"TI-84 Plus CE remake by DJ Omnimaga
Asm(prgmPRINT
{48,219
Asm(prgmPRINT
"(C)2016, https://codewalr.us
Asm(prgmPRINT
{114,146,0,231
Asm(prgmPRINT
"Highscore:
Asm(prgmPRINT
{202,146
Asm(prgmPRINT
ʟWALRS(1
Asm(prgmPRINT
0getKey
Repeat Z
getKey→Z
End
If Z=45:Then
Asm(prgmBACKHOME
ClrHome
DelVar L₁Return
End
While 1
1→A
0→B
0→I
288→C
288→D
1→E
100→R
120→O
0→P
288→F
0→G
1→M
{0,0,320,220,20,0,220,320,20,0
Asm(prgmCLSCREEN
{146,222,255,0
Asm(prgmPRINT
0
Asm(prgmPRINT
While B<190 and Z≠45 and (O≠C or (B+20<R or B+10>R
While B<190 and O≤300 and (O≠C or (B+20<R or B+10>R
{5,F,G,5,D,I,3,12A,96,3,12A+80,96,3,12A+160,96,3,12A+240,96,4,C,B,M,O,R
Asm(prgmSPRITE
C→D
B→I
O→F
R→G
A+1→A
If A>13:1→A
getKey→Z
If Z=21:⁻40→E
E+10+10(E=⁻10→E
C-24(Z=24)+24(Z=26→C
If C<0:0→C
If C>288:288→C
If E>30:30→E
B+E→B
If B<0:0→B
O+24→O
R+20(M=2)((R<B)-(R>B→R
If Z=45:200→B
End
If (B+20≥R and B+10≤R) and O=C and not(M:Then
P+10→P:300→O
End
If O>288:Then
0→O
P+1→P
{146,222
Asm(prgmPRINT
P
Asm(prgmPRINT
20randInt(0,9→R
not(randInt(0,3))+(150<randInt(P,200→M
End
End
If Z≠45:Then
If B>189:189→B
For(Z,1,2
For(M,1,4
{33,12,1,6,27,L₁(M+1),33,5,1,5,27,L₁(M),33,4,1,1,27,L₁(M),33,4,A,52,6,L₁(M+1),33,4,A+13,52,6,L₁(M+1),33,B+L₁(M+4Z+2),C+L₁(M+4Z+18),39,1,L₁(M+2
"Asm(prgmTEXTLIB
End
End
{17,L₁(M),16,12
"Asm(prgmTEXTLIB

{126,40,0,129
Asm(prgmPRINT
"Game Over
Asm(prgmPRINT
If P>ʟWALRS(1:Then
{112,60
Asm(prgmPRINT
"NEW HIGHSCORE
Asm(prgmPRINT
P→ʟWALRS(1
End
0getKey
Repeat getKey
End
Else
Asm(prgmBACKHOME
ClrHome
DelVar L₁Return
End
End

Dream of Omnimaga

Yeah, as replied in the other topic it seems that definiting sprite 0 properly did not fix it.

That said, I did not know that defining Sprite 0 erased all other sprites, because I was sure that the 000 thing was just as reference. It's good to know, because I thought the only way to reset sprites was to use the following code:

"NSB":Asm(prgmBACKHOME
Asm(prgmSETTINGS



On a side note, I did a screenshot of the text linebreak in action :D

  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

unregistered

Sprites v3.31 available ! ( https://tiplanet.org/forum/archives_voir.php?id=539203 )

! NEW !.. "getKey":Asm(prgmPALETTE

Allows you to know if 1 or more "arrow" keys  are pressed, then store result into theta variable

(down)=1 , (left)=2 , (right) =4 , (up) = 8

Also allows you to know if 1 or more of the keys (2nd) =1 , (mode) = 4 , (del) = 8 are pressed,
then store result into Ans.

It's possible to read several keys together !

EG : when (up) and (left) are pressed, theta will contains value 8+2 = 10 :)


Dream of Omnimaga

Very nice addition. I will give it a try in my game to see if the game runs fast enough with that new feature. Otherwise I will probably use it in future games that don't require much speed. Thanks a lot :)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Dream of Omnimaga

So I tried Sprites v3.31 and it doesn't look like "getKey":Asm(prgmPALETTE does anything at all. I tried it in GalagACE but keys wouldn't respond at all. Not that I plan to use it in that game since it would slow it down but I thought I would let you know.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

unregistered

 9_9 Oh, please forget v3.31 : this sort of getkey added to PALETTE was rather slow  :-[ (in fact, you had to put the token of getKey, perhaps it was not ok for you because of that ;) )
I just downgraded to v3.3  :P
To be fast, we could add this "getkeyS" function but as another new ASM program (yes , one more!)

Dream of Omnimaga

That could work, but what about merging some existing programs? For example BACKHOME with SETTINGS? That would still leave us at 6.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Dream of Omnimaga

By the way, would adding Sprite/rectangle clipping support cause too many slowdowns?

Also I think in some scenarios where graphics are simple, it's better to use sprites than rectangles, because a rectangle uses 5 list arguments, while a sprite uses 3, so if you display 20 objects, then this means you need to use a list of 100 elements, versus 60, causing extra slowdowns. So from now on if I need to display small rectangles of fixed size, I'll just use a sprite lol.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Dream of Omnimaga

So I had an idea @grosged , regarding the issue with scaled sprite data storage: Why not store the zoom value with the sprite data and zoom to that value when the sprite is called? This would allow you to keep the sprite command at three arguments, but still greatly reduce the size of scaled sprite data. For example, right now a 35x35 sprite zoomed at 700% takes 60025 bytes of safe RAM, while with my idea it would take 1225. My initial idea was to have the user specify the zoom during sprite display, but I felt it would make the lists too long with 4 arguments. With my new idea the user would still not be able to choose a different zoom after the sprite was stored and sprite display would be slower, but it would take much less space while still sticking to three arguments for sprite calling. Of course the sprite data would be 1 byte larger due to the zoom being stored side by side, but it's better than for example 49 times larger .

With Pokéwalrus, for example, I would be able to store all my 150 sprites into the safe RAM at once, while right now I can only store about 16 at a time.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

unregistered

You know , I feel my project sprites like finished, now (after many many improvements/versions)
Moreover, I always tried to keep speed before anything else : writing another version including zoom during display would unfortunately get it slow.

Dream of Omnimaga

Ah I see. That's true it would get slow actually. Perhaps too much to allow scrolling tilemaps.

On a side note I should try storing map data inside 8xi images and use pxl-test. I would have a few tiles at a time but I wonder if it would be faster than using lists. I would be able to use maps larger than 31*32 pixels too and they would take no RAM. It probably depends if Sprite uses the graph screen, though.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Dream of Omnimaga

A little advice for exporting sprites: Do not use color #22 (L) unless you are 100% sure that it's never placed right to the left of a pixel that use colors from 1 to 6. This is because TokenIDE converts L1 through L6 into the List tokens of the same names and omits the backslash in your code (and TokenIDE doesn't save backslashes, even in the txt file *pokes @merthsoft or someone else to fix on Github*) to prevent that. Not using color L next to 1 through 6 will speed up sprite conversion considerably.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

RomanChrome

Hi,
I really like this program, and it's honestly really helpful for creating things. I've written a program for Windows which allows you to quickly create sprites for for this. It can be downloaded here: http://bit.ly/TISpriteEditorPage.
On another topic, I do wish that there was a way in this program to do something like pxl-check and see if a pixel is on or not, but I can see that might be hard to add.

Dream of Omnimaga

Heya @RomanChrome and welcome here. I agree with you about this library. When I still programmed stuff, it was very handy for advanced graphics in my basic games and due to chained command support it allowed my games or demos to run at very decent speed. Pxl-check would be an interesting addition for sure (I think it's possible)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U


Powered by EzPortal