Author Topic: Need code help with Sprites  (Read 22285 times)

0 Members and 2 Guests are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Need code help with Sprites
« on: March 06, 2010, 09:36:37 pm »
Quote from: BASIC Code
:[FFFFFFFFFFFFFFFF→Pic8
:[FEFEFEFEFEFEFE00→Pic7
:[FCFCFCFCFCFC0000→Pic6
:[F8F8F8F8F8000000→Pic5
:[F0F0F0F000000000→Pic4
:[E0E0E00000000000→Pic3
:StoreGDB
:StorePic
:For(A,0,94
:For(B,0,62
:If pxl-Test(A,B
:Pxl-On(A+1,B
:Pxl-On(A,B+1
:Pxl-On(A+1,B+1
:Else
:Pxl-Off(A+1,B
:Pxl-Off(A,B+1
:Pxl-Off(A+1,B+1
:End
:B+1→B
:End
:A+1→A
:End
:DispGraph
:For(C,3,8
:RecallPic
:For(A,0,93
:For(B,0,61
:If pxl-Test(A,B
:Pt-On(A,B,C*8+Pic0
:Else
:Pt-On(A,B,C*8+Pic0
:Pt-Change(A,B,C*8+Pic0
:End
:B+C-1→B
:End
:A+C-1→A
:End
:DispGraph
:End
Generated by SourceCoder, © 2005 Cemetech

I am unsure what I am doing wrong. This is supposed to go through pic 3-8, but when compiling I get an ERR:UNDEFINED at 74% 2nd pass. I was trying what Quigibo told me to do with the sprites to be able to display them dynamically. Any help?

Btw I also tried the following:

Quote from: BASIC Code
:[FFFFFFFFFFFFFFFF→Pic8
:[FEFEFEFEFEFEFE00→Pic7
:[FCFCFCFCFCFC0000→Pic6
:[F8F8F8F8F8000000→Pic5
:[F0F0F0F000000000→Pic4
:[E0E0E00000000000→Pic3
:StoreGDB
:StorePic
:For(A,0,94
:For(B,0,62
:If pxl-Test(A,B
:Pxl-On(A+1,B
:Pxl-On(A,B+1
:Pxl-On(A+1,B+1
:Else
:Pxl-Off(A+1,B
:Pxl-Off(A,B+1
:Pxl-Off(A+1,B+1
:End
:B+1→B
:End
:A+1→A
:End
:DispGraph
:For(C,0,5
:RecallPic
:For(A,0,93
:For(B,0,61
:If pxl-Test(A,B
:Pt-On(A,B,C*8+Pic3
:Else
:Pt-On(A,B,C*8+Pic3
:Pt-Change(A,B,C*8+Pic3
:End
:B+C+2→B
:End
:A+C+2→A
:End
:DispGraph
:End
Generated by SourceCoder, © 2005 Cemetech

It compiled But it was all glitchy :/

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6266
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Need code help with Sprites
« Reply #1 on: March 06, 2010, 09:39:35 pm »
oh, you need to have the ending ']' on the sprite data
/e

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Need code help with Sprites
« Reply #2 on: March 06, 2010, 09:41:21 pm »
You didn't define Pic0 so of course its undefined.  In your case, the first sprite is Pic8 it should be C*8+Pic8.  But actually, you start C at 3 so it should really be C-3*8+Pic8.  That would make C=3 correspond to pic8, C=4 is pic7, etc...  You might have to rearrange the sprites if you need it in the other order.

Edit: and no, you don't need the "]" after sprite data, just like strings don't need the "
« Last Edit: March 06, 2010, 09:45:41 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need code help with Sprites
« Reply #3 on: March 06, 2010, 09:46:11 pm »
@Quigibo: Mhmm I am confused by what you mean x.x

I am unsure if I understand the concept. I was sure C*8+Pic0 worked as Picturetodisplay(0+C). For example, in Celtic, if you want to display an entire picture and have pics stored in 3 through 8, you'll do real(3,C,0,1. The C would be the pic that needs to be recalled. So basically 0+C. How does your concept works? I know about the *8 part, but I don,t understand otherwise...

@Eeems: no, because it worked fine in my older programs without it.
« Last Edit: March 06, 2010, 09:46:55 pm by DJ Omnimaga »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Need code help with Sprites
« Reply #4 on: March 06, 2010, 09:51:13 pm »
Yeah i think it might make a bit more sense to put all of the pic data into a single location, then access it like this:

[FFFFFFFFFFFFFFFF  (not really a space here but i am showing it to distinguish between two separate sprites)
FEFEFEFEFEFEFE00
FCFCFCFCFCFC0000
F8F8F8F8F8000000
F0F0F0F000000000
E0E0E00000000000]->Pic0

Then you can access the first sprite by using 0+Pic0 (or just Pic0 :P), and then the second by using 8+Pic0 ect...

So you would change For(C,3,8) to For(C,0,5) i think?

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Need code help with Sprites
« Reply #5 on: March 06, 2010, 10:05:19 pm »
When you input pictures, strings, and other data, it get added to the end of the program.  Here is the memory map for you:

<Program><Data1><Data2><Data3>...<LastData>

The first data block you entered was "Pic8".  Don't forget, that's just an arbitrary name, you can call it Str8Z if you want and it will behave the same way.  What it does is add that data you just wrote to the end of the assembly program.  The pointer to that block of data is now in the name Pic8.  You will see if you do "Disp Pic8>Dec" that Pic8 is really just a pointer to the end of the program so far.

But then, the you added more data and stored the pointer to that data in Pic7.  Those new bytes get added to the end of the program directly after the first sprite since that is the new end of the program.  In fact, you don't even need to give it a name, you can leave the -> part out since you don't need to refer to it by a unique name.  You can get that pointer simply by doing 8+Str8 since it occurs 8 bytes after the first pointer.

I am going to call the first sprite Str8Z so it appears arbitrary:

Quote from: BASIC Code
:[FFFFFFFFFFFFFFFF]→Str8Z
:[FEFEFEFEFEFEFE00]
:[FCFCFCFCFCFC0000]
:[F8F8F8F8F8000000]
:[F0F0F0F000000000]
:[E0E0E00000000000]

At this point, the first picture is Str8Z.  You can call Pt-On(X,Y,Str8Z)
The next sprite is 8 bytes after the first one right?  So you can do Pt-On(X,Y,8+Str8Z)
The next is 8 bytes after that so you can do Pt-On(X,Y,16+Str8Z)
Then Pt-On(X,Y,24+Str8Z)

In general, the nth sprite (starting at n=0) in that particular data block is N*8+Str8Z.
So in general, you can do Pt-On(X,Y,N*8+Str8Z) to get the nth sprite.

EDIT: and by the way, Builderboy's method is identical.
« Last Edit: March 06, 2010, 10:09:00 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need code help with Sprites
« Reply #6 on: March 06, 2010, 10:11:35 pm »
Ooooh I see what you mean now. I was confused at first. Didn't knew you could do this. Thanks for the info. It should also make my task easier for when I have a lot of sprites.

I am going to experiment now

I assume this is a bit what that pointer stuff is about, right?

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Need code help with Sprites
« Reply #7 on: March 06, 2010, 10:17:46 pm »
What is a sprite?  Its just a pointer.  As is a string, even the variables themselves are pointers!  But you don't have direct access to those which is why L1 says "saveSScreen+54" because each 2 byte number is stored there (26*2 = 52) plus a 2 byte random seed = 54 bytes.

So actually, this is kinda cool.  Another way you can access variables:
:5->A
is the same as:
:5->{L1-54}
:0->{L1-53}    ;This is because the number is 2 bytes and also little endian
But the first one is more optimized of course.
« Last Edit: March 06, 2010, 10:18:37 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need code help with Sprites
« Reply #8 on: March 06, 2010, 10:24:57 pm »
aaah ok I see. It might be hard for me to understand all of these, but I am starting to get it now. Thanks a lot for your help.


Btw my program now works. I am not sure if it's faster or slower. If it's slower, the slow down is sure hard to notice, though. However, 811 bytes is much better than the 1546 bytes my other compiled program took. Still a bit large compared to the source (653 bytes for old program and 313 for new one) but a big improvement.

Offline trevmeister66

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1009
  • Rating: +14/-5
    • View Profile
Re: Need code help with Sprites
« Reply #9 on: March 06, 2010, 10:31:57 pm »
aaah ok I see. It might be hard for me to understand all of these, but I am starting to get it now. Thanks a lot for your help.


Btw my program now works. I am not sure if it's faster or slower. If it's slower, the slow down is sure hard to notice, though. However, 811 bytes is much better than the 1546 bytes my other compiled program took. Still a bit large compared to the source (653 bytes for old program and 313 for new one) but a big improvement.
Nice DJ. An improvement is an improvement, no matter how small or big.
Projects:    nameless RPG: 1.0%  |  Reverse Snake v1.5: 100%  |  Secret Project: 5%  |  DUNGEON: 70%

My MW2 Blog <-- Please visit :)

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Need code help with Sprites
« Reply #10 on: March 06, 2010, 11:00:51 pm »
99% of the time, if the executable is smaller, the code is also faster.  How much faster will vary, but there are very few exceptions to this rule.  A notable one is successive divisions by 2 instead of a single regular division.  So in general, you can use this rule to see if the program is faster or slower without even running it.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Need code help with Sprites
« Reply #11 on: March 06, 2010, 11:54:21 pm »
Pointers are really neat!  Thanks for implementing them, and I finally understand why you'd want to use [Data not stored to anything].  You can access it easily with pointers!

Cool! ;D

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Need code help with Sprites
« Reply #12 on: March 07, 2010, 12:01:17 am »
Nice to know.

However, do you imply that two divisions in a row by 2 instead of a single one will be smaller or am I interpreting this exception wrong?

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Need code help with Sprites
« Reply #13 on: March 07, 2010, 12:13:13 am »
Nice to know.

However, do you imply that two divisions in a row by 2 instead of a single one will be smaller or am I interpreting this exception wrong?
A/8 is slower than A/2/2/2.  :)
« Last Edit: March 07, 2010, 12:13:26 am by ztrumpet »

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Need code help with Sprites
« Reply #14 on: March 07, 2010, 01:10:04 am »
I know nothing about the AxeParser language, yet, but why would more divisions be faster? It just doesn't make sense to me :P
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)