Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: DJ Omnimaga on March 06, 2010, 09:36:37 pm

Title: Need code help with Sprites
Post by: DJ Omnimaga 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 (http://www.cemetech.net/projects/basicelite/sourcecoder.php), © 2005 Cemetech (http://www.cemetech.net)

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 (http://www.cemetech.net/projects/basicelite/sourcecoder.php), © 2005 Cemetech (http://www.cemetech.net)

It compiled But it was all glitchy :/
Title: Re: Need code help with Sprites
Post by: Eeems on March 06, 2010, 09:39:35 pm
oh, you need to have the ending ']' on the sprite data
Title: Re: Need code help with Sprites
Post by: Quigibo 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 "
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga 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.
Title: Re: Need code help with Sprites
Post by: Builderboy 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?
Title: Re: Need code help with Sprites
Post by: Quigibo 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.
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga 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?
Title: Re: Need code help with Sprites
Post by: Quigibo 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.
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga 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.
Title: Re: Need code help with Sprites
Post by: trevmeister66 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.
Title: Re: Need code help with Sprites
Post by: Quigibo 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.
Title: Re: Need code help with Sprites
Post by: ztrumpet 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
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga 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?
Title: Re: Need code help with Sprites
Post by: ztrumpet 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.  :)
Title: Re: Need code help with Sprites
Post by: meishe91 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
Title: Re: Need code help with Sprites
Post by: Builderboy on March 07, 2010, 01:15:47 am
Well, its the way Asm works, and how the compiler doesn't catch the optimization (which it might in the future ;) ).  All data on the calculator is stored in Binary, which is Base 2.  We work in base 10.  In Base 10, its reeeeeaally easy to multiply or divide by 10, or 100 or 100 ect because all you have to do is move the decimal point around.  Like 143 becomes 1430 if you multiply by 10 and 1540 become 154 if you divide by 10.  This also works in Binary, where multiplying by 2 or dividing by 2 is reeaaaally easy for the calculator to do, because all the calculator has to do is shift the decimal point around, just like in Base 10.

Thats a kinda hackish way to say it without going into more specific asm details :P
Title: Re: Need code help with Sprites
Post by: Quigibo on March 07, 2010, 01:23:26 am
Hey hey!  It certainly does catch the optimization.  But repeated divisions are only optimized in terms of their speed not size.  Regular division is still less code (if you use it a few times).  That's why its not an automatic optimization, you can choose when you need the extra speed with the downside of larger code.

Very nice explanation by the way :)
Title: Re: Need code help with Sprites
Post by: meishe91 on March 07, 2010, 01:43:49 am
Oh ok. So this is speed optimization, not size. I get it :) Thanks.
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga on March 07, 2010, 02:14:11 am
Being a BASIC programmer, I am used to working under extreme speed limitations, so I will probably go for size as much as possible.
Title: Re: Need code help with Sprites
Post by: Quigibo on March 07, 2010, 05:12:31 am
Yeah, the majority of programs and games have to use pauses to keep good timing.  There is almost no need for greater speed unless it is actually demanded.  We'll see how far the hardware can be pushed in the next version since it can take advantage of 15MHz calculators.  I'm getting about 125 sprites per frame at 30 fps.  That's without any game mechanics, but that usually only makes up a small fraction of the cpu time anyway.
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga on March 07, 2010, 05:16:31 am
Nice

Also, we have to make sure to not make our games run too fast either. We have to take the motion blur on the LCD into account, especially TI-Nspire users.

My first pixelater program, the one that went by multiples of 2, I had to slow down the 8x8 part with a For(Z,0,9000:End (at that time I didn't knew the Pause command), to keep the speed similar to the two other parts. With no pausing, the 8x8 rendered so fast I couldn't see the 4x4 at all
Title: Re: Need code help with Sprites
Post by: ztrumpet on March 07, 2010, 11:37:01 am
Wow, 15mhz is going to be fast!

Awesome explanation Builderboy!  Great job on it! :D
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 10:32:14 pm
I'm having some trouble of my own in this bit of code involving sprites... In the (marked as, at least) bolded section, I try to get the sprite to default to the first 8 bits in the pic. It said getKey worked this way in the readme, but it's not working the way I expect it to... Or is "and" glitchy?

It messes up the sprite, which is somewhat disconcerting to me.

Code: [Select]
ClrHome
ClrDraw
DiagnosticOff
'DOWN
[3C245A42A5A55A663C245A42A5A55E603C245A42A5A55A663C245A42A5A57A06→Pic1
'RIGHT
[3824445858582838382444586C6894EC3824445858582838382444585C4894EC→Pic2
'LEFT
[1C24221A1A1A141C1C24221A361629371C24221A1A1A141C1C24221A3A122937→Pic3
'UP
[3C244242A5A55A663C244242A5A55E603C244242A5A55A663C244242A5A57A06→Pic4
1→A
1→B
0→X
Pt-On(A,B,Pic1

While getKey(15)=0
[b]If getKey=1 and getKey(1)≠1:Pt-On(A,B,Pic1)End
If getKey=2 and getKey(2)≠1:Pt-On(A,B,Pic2)End
If getKey=3 and getKey(3)≠1:Pt-On(A,B,Pic3)End
If getKey=4 and getKey(4)≠1:Pt-On(A,B,Pic4)End[/b]
Pause 100
DispGraph
X+1→X
If X=20:0→XEnd
If getKey(1)=1
B+1→B
ClrDraw
Pt-On(A,B,X/5*8+Pic1
End
If getKey(2)=1
A-1→A
ClrDraw
Pt-On(A,B,X/5*8+Pic3
End
If getKey(3)=1
A+1→A
ClrDraw
Pt-On(A,B,X/5*8+Pic2
End
If getKey(4)=1
B-1→B
ClrDraw
Pt-On(A,B,X/5*8+Pic4
End
End

I'm new here, and also a n00b programmer. So yeah.
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 16, 2010, 10:46:48 pm
Umm I don't really get most of your code, but getkey=1 and getkey(1)/=1 would be contradictory, since getkey sees what key is pressed and getkey(x) sees if key x is pressed, so you're saying, "If the current key being pressed is down, (one) and down is not being pressed, do this"
You get the blue box with the code tag. [ code]Your code here[ /code]
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 10:49:46 pm
Hmm... It says in the readme that just getKey is "Expression becomes the last key pressed. It is zero if no keys are pressed.".
I'm trying to say "If (direction button) has been pushed last, and (directional button) is not being pushed at the moment, display (direction-appropriate sprite)".

Since this obviously doesn't work, how else could I do something with the same effect?
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 16, 2010, 11:00:30 pm
Sorry, you're right, lol, it i the last key pressed, but I *think* it would still be a contradiction...  plus, i think like in basic, once you test for straight getkey, it resets the last key to 0, so you should store the getkey to something first.  somebody correct if i'm wrong.  And so you're trying to change the sprite only when they release the key basically, not just when pressed?
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 11:02:20 pm
Right, right, why didn't I think of that before?... Set a variable during the if statement, and use that.

############################

How do you ask if ANY key is being pressed, instead of a specific key? Is there a way?

(edit: merged close double-post)
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 16, 2010, 11:12:23 pm
1. try to edit instead instead of double-posting if the posts are fairly close together. (like yours)
2. thats what getkey w/o the (x) part does, really.
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga on March 16, 2010, 11:21:08 pm
(merged double-posts)

Unfortunately, I never messed with getkey yet, I only did special graphical effects and animation routines and modified some examples code, so I cannot help. Hopefully, someone who used it a lot might be able to help, though.
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 11:21:46 pm
Sorry, I was afraid people might not have noticed it.
Now the sprites flicker... I have this now:

If getKey=0
If D=1:Pt-On(A,B,Pic1)End
If D=2:Pt-On(A,B,Pic2)End
If D=3:Pt-On(A,B,Pic3)End
If D=4:Pt-On(A,B,Pic4)End
End

Anything wrong with this?
Title: Re: Need code help with Sprites
Post by: trevmeister66 on March 16, 2010, 11:25:44 pm
is D your previous getKey? and it flickers because (a) you don't erase the pic after updating the screen and (b) when you do press a key, it's not going to draw anything that loop because getKey won't = 0, so itll skip drawing the sprite. Does that make sense?
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 11:30:17 pm
Not quite... This is all in context, so here's the whole of it:

Code: [Select]
ClrHome
ClrDraw
DiagnosticOff
'DOWN
[3C245A42A5A55A663C245A42A5A55E603C245A42A5A55A663C245A42A5A57A06→Pic1
'RIGHT
[3824445858582838382444586C6894EC3824445858582838382444585C4894EC→Pic2
'LEFT
[1C24221A1A1A141C1C24221A361629371C24221A1A1A141C1C24221A3A122937→Pic3
'UP
[3C244242A5A55A663C244242A5A55E603C244242A5A55A663C244242A5A57A06→Pic4
1→A
1→B
0→X
Pt-On(A,B,Pic1

While getKey(15)=0
If getKey=0
If D=1:Pt-On(A,B,Pic1)End
If D=2:Pt-On(A,B,Pic2)End
If D=3:Pt-On(A,B,Pic3)End
If D=4:Pt-On(A,B,Pic4)End
End
Pause 100
DispGraph
X+1→X
If X=20:0→XEnd
If getKey(1)=1
B+1→B
1→D
ClrDraw
Pt-On(A,B,X/5*8+Pic1
End
If getKey(2)=1
A-1→A
2→D
ClrDraw
Pt-On(A,B,X/5*8+Pic3
End
If getKey(3)=1
A+1→A
3→D
ClrDraw
Pt-On(A,B,X/5*8+Pic2
End
If getKey(4)=1
B-1→B
4→D
ClrDraw
Pt-On(A,B,X/5*8+Pic4
End
End
Title: Re: Need code help with Sprites
Post by: trevmeister66 on March 16, 2010, 11:33:29 pm
Hmm well you don't need to do ClrDraw, you can just do "Pt-Off(X,Y,Pic#" before you update it's X or Y location, and then draw the new sprite.
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 11:37:41 pm
The problem is, it might have been a completely different sprite, and then it would only erase a portion of the sprite. Of course, I might be wrong. Does it slow the program down?
Also, that doesn't help me for making the sprites not flicker.
Title: Re: Need code help with Sprites
Post by: calc84maniac on March 16, 2010, 11:38:36 pm
Hmm well you don't need to do ClrDraw, you can just do "Pt-Off(X,Y,Pic#" before you update it's X or Y location, and then draw the new sprite.
Pt-Off doesn't work that way. What it actually does is similar to the "overwrite" option in xLib. You could do Pt-Off with a blank sprite to erase though, I think
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 11:45:06 pm
Would I need to append a 0000000000000000 to a hex code, or is that the default?
Also, I'd really like some help with the flicker problem...
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 16, 2010, 11:47:02 pm
Umm, I might be able to help with the rest of the code if i actually knew what it did other than display sprites when you press keys.  I can't really get intentions from code. :P
Title: Re: Need code help with Sprites
Post by: Eeems on March 16, 2010, 11:47:53 pm
You need a beeline or a ':' between the ) and the End, and you don't need the )

also for any If statements, any time you use and/or/xor you need a bracket after.
So this: If x=10 and x=11 would change to this: if x=10 and (x=11
that's just some quirks of the axe parser right now.

Edit: wow, didn't see those new posts x.x
Title: Re: Need code help with Sprites
Post by: ikemike on March 16, 2010, 11:51:57 pm
Okay. It displays a sprite and moves it around the screen when you press the corresponding arrow key. The sprite that's shown is part of that direction's walking animation. A  X is constantly changing values from 0 to 20, and that value changes which sprite in the walking animation is shown. The problem is the revert-to-non-walking-sprite. This causes the walking animation to constantly flicker back to the default non-walking sprite, when it should be displaying a sprite of a limb extended.

The fact I can make a sprite animate and walk around, though, is awesome, because I haven't been able to do this is pure basic in my two years of (amateurish) programming. I learn how to do this in 2 days with Axe parser. Cool stuff.
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 16, 2010, 11:58:56 pm
So the first sprite is the walking down animation, the second walking right animation etc. is that correct? if so what are you using for standing still?
Title: Re: Need code help with Sprites
Post by: ikemike on March 17, 2010, 12:01:10 am
The standing still sprite is the first and third hexadecimal code in each Pic#. I can add walking-specific sprites later.
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 17, 2010, 12:16:23 am
Oh, ok, i see. How about trying this?
Code: [Select]
DiagnosticOff
'DOWN
[3C245A42A5A55A663C245A42A5A55E603C245A42A5A55A663C245A42A5A57A06→Pic1
'LEFT
[1C24221A1A1A141C1C24221A361629371C24221A1A1A141C1C24221A3A122937→Pic2
'RIGHT
[3824445858582838382444586C6894EC3824445858582838382444585C4894EC→Pic3
'UP
[3C244242A5A55A663C244242A5A55E603C244242A5A55A663C244242A5A57A06→Pic4

1->C
0->X
0->Y
While 1
C+1->C
If X^5=0
C/5->A
getkey->K
X+(K=3)-(K=2)->X
Y+(K=1)-(K=4)->Y
If K=0
0->A
Else
K->D
End
sub(DP)
If K=15:Goto FN:End
End
End

Lbl DS
ClrDraw
If D=1:Pt-Off(X,Y,A*8+Pic1:End
If D=2:Pt-Off(X,Y,A*8+Pic2:End
If D=3:Pt-Off(X,Y,A*8+Pic3:End
If D=4:Pt-Off(X,Y,A*8+Pic4:End
DispGraph
Return

Lbl FN
I think that should do what you want... if it doesn't just tell me what happened, scince i just typed this up w/o testing it :P  Ask if you want to know anything about that, of if really just want me to try to edit yours...

EDIT: Forgot to initialize the variables! oops :P
EDIT2: Hopefully you didn't try that code either, you wouldn't have been able to quit...
Title: Re: Need code help with Sprites
Post by: Eeems on March 17, 2010, 11:12:35 am
try changing the If K=15:Goto FN:End to ReturnIf K=15 and get rid of the Lbl FN at the end as well as the Return. You could also change the While 1 to Repeat K=15 or Repeat getkey(15), and then adding a Return at the end of the loop.
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 17, 2010, 01:38:57 pm
thats a good idea, except, what return?
Code: [Select]
DiagnosticOff
'DOWN
[3C245A42A5A55A663C245A42A5A55E603C245A42A5A55A663C245A42A5A57A06→Pic1
'LEFT
[1C24221A1A1A141C1C24221A361629371C24221A1A1A141C1C24221A3A122937→Pic2
'RIGHT
[3824445858582838382444586C6894EC3824445858582838382444585C4894EC→Pic3
'UP
[3C244242A5A55A663C244242A5A55E603C244242A5A55A663C244242A5A57A06→Pic4

1->C
0->X
0->Y
While 1
C+1->C
If X^5=0
C/5->A
getkey->K
X+(K=3)-(K=2)->X
Y+(K=1)-(K=4)->Y
If K=0
0->A
Else
K->D
End
sub(DP)
ReturnIf K=15
End
End

Lbl DS
ClrDraw
If D=1:Pt-Off(X,Y,A*8+Pic1:End
If D=2:Pt-Off(X,Y,A*8+Pic2:End
If D=3:Pt-Off(X,Y,A*8+Pic3:End
If D=4:Pt-Off(X,Y,A*8+Pic4:End
DispGraph
Return
btw, ikemike, i swapped the numbers of the left and right directional sprite so they directly correlate to the arrow keys
Title: Re: Need code help with Sprites
Post by: ikemike on March 17, 2010, 04:16:34 pm
I tried the code, but it gives me a fatal error... Then I have to take the batteries out and it resets the RAM.
Title: Re: Need code help with Sprites
Post by: Eeems on March 17, 2010, 08:30:02 pm
When does the fatal error happen? And what exactly happened?
Title: Re: Need code help with Sprites
Post by: ikemike on March 17, 2010, 09:16:47 pm
Basically, the nothing happens. I start it up, and am greeted with a blank screen. Whereupon I press the arrow keys and nothing appears. Pressing clear doesn't exit, so I take out a battery and put it back in. This causes a RAM clear, so I'm sure it was a fatal error and not just a stuck loop or something.

By the way, what's the pattern of getKey expressions? It's different than the standard one used in Ti-BASIC, and i haven't quite figured it out.
Title: Re: Need code help with Sprites
Post by: Quigibo on March 17, 2010, 09:24:52 pm
Just going to help optimize a bit and fix some code
Code: [Select]
ClrHome
ClrDraw
DiagnosticOff
.DOWN
[3C245A42A5A55A663C245A42A5A55E603C245A42A5A55A663C245A42A5A57A06→Pic1
.RIGHT
[3824445858582838382444586C6894EC3824445858582838382444585C4894EC→Pic2
.LEFT
[1C24221A1A1A141C1C24221A361629371C24221A1A1A141C1C24221A3A122937→Pic3
.UP
[3C244242A5A55A663C244242A5A55E603C244242A5A55A663C244242A5A57A06→Pic4
0→X
1→A→B                   ;More efficient way to initialize similar variables

Repeat getKey(15)             ;"Repeat" is the same as "while zero"

Pt-On(A,B,D*64+Pic1)       ;Each sprite group is 64 bytes apart
                                     ;Draw the rest sprite every frame, even if it gets written over.
If X+1→X=20             ;You can put the storage statements in if conditions.
  0→X
End
Pause 100

If getKey(1)              ;You don't need the equals one here
  B+1→B
  0→D                     ;D should start at zero
  sub(DW)
End
If getKey(2)
  A-1→A
  1→D
  sub(DW)
End
If getKey(3)
  A+1→A
  2→D
  sub(DW)
End
If getKey(4)
  B-1→B
  3→D
  sub(DW)
End

DispGraph
End
ClrHome                         ;Clear the screen on exit
Return

Lbl DW
ClrDraw                                   ;Clear the screen.  It will erase the rest sprite.
Pt-On(A,B,D*64+(X/5*8)+Pic4)   ;Draw the sprite with the right sprite set.
Return


Haven't tested anything.  But it should work I think.  There are a lot more optimizations you can do, but they are relatively minor and I don't want to confuse you since you're new to this.
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 17, 2010, 11:56:42 pm
O I'm so stupid :P it wiould never run the main loop.  sorry if i cleared stuffs you were working on :(
Code: [Select]
DiagnosticOff
'DOWN
[3C245A42A5A55A663C245A42A5A55E603C245A42A5A55A663C245A42A5A57A06→Pic1
'LEFT
[1C24221A1A1A141C1C24221A361629371C24221A1A1A141C1C24221A3A122937→Pic2
'RIGHT
[3824445858582838382444586C6894EC3824445858582838382444585C4894EC→Pic3
'UP
[3C244242A5A55A663C244242A5A55E603C244242A5A55A663C244242A5A57A06→Pic4

1->C
0->X
0->Y
While 1
C+1->C
If X^5=0 \\ this should actually be "If C^5=0"
C/5->A
getkey->K
X+(K=3)-(K=2)->X
Y+(K=1)-(K=4)->Y
If K=0
0->A
Else
K->D
End
sub(DP)
ReturnIf K=15
End
End

Lbl DS
ClrDraw
If D=1:Pt-Off(X,Y,A*8+Pic1:End
If D=2:Pt-Off(X,Y,A*8+Pic2:End
If D=3:Pt-Off(X,Y,A*8+Pic3:End
If D=4:Pt-Off(X,Y,A*8+Pic4:End
DispGraph
Return
now that should work.  well, i'm assuming so, if return will quit... (i'm just assuming so since thats what Eeems implied :P)  O random quirk, pressing a key other than the arrows will give you nothing till an arrow key is pressed. didnt feel like fixing that rigth then :P
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga on March 18, 2010, 12:08:15 am

By the way, what's the pattern of getKey expressions? It's different than the standard one used in Ti-BASIC, and i haven't quite figured it out.
Not too sure, I think the key codes were posted somewhere but I totally forgot. Quigibo should probably include the list if they are not included with Axe latest releases.
Title: Re: Need code help with Sprites
Post by: cooliojazz on March 18, 2010, 12:21:39 am
53 52 51 50 49
54 55 56    4
             2    3
48 40 32    1
47 39 31 23 15
46 38 30 22 14
45 37 29 21 13
44 36 28 20 12
43 35 27 19 11
42 34 26 18 10
    33 25 17 9

Those are the keys of the calculator...  the pattern, basically, is just dereasing numbers asyou move down the rows and to the right, with the arrow keys and the top two rows being different
Title: Re: Need code help with Sprites
Post by: Eeems on March 18, 2010, 12:52:29 am
Return is the equivalent of the 'ret' instruction in ASM. It will quit a macro/routine back to the main code and it will also quit the program if it is no longer in a macro/routine.
Title: Re: Need code help with Sprites
Post by: DJ Omnimaga on March 18, 2010, 01:59:33 am
cool thanks Squirreliojazz... er... Cooliojazz :D
Title: Re: Need code help with Sprites
Post by: ikemike on March 18, 2010, 04:20:15 pm
Thanks, Cooliojazz. Those getKey values will help a lot.

Also, the code doesn't work. It displays the sprite, and it can move around, but it doesn't animate and leaves a trail when moving up or down. It's also really slow.