Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Munchor on January 01, 2011, 02:51:25 pm

Title: Moving a Sprite
Post by: Munchor on January 01, 2011, 02:51:25 pm
Hey there, here is a GIF and the code of how to move a smilie, just change the code to whatever you want to get a moving mouse, a moving dog, or whatever you want.

Code: [Select]
.SMILIE
.The Sprite, change the Hex to whatever you want
[004466000000817E]->Pic1
.Do everything below until CLEAR is pressed
Repeat getKey(15)
StorePic
.Display Sprite
Pt-On(X,Y,Pic1
DispGraph
Pt-Change(X,Y,Pic1
RecallPic
ClrDraw
.Right Key
If getKey(3) and (X<92)
X+1->X
End
.Left Key
If getKey(2) and (X>2)
X-1->X
End
.Down Key
If getKey(1) and (Y<60)
Y+1->Y
End
.Up Key
If getKey(4) and (Y>2)
Y-1->Y
End
. End of the game loop
End



Title: Re: Moving a Sprite
Post by: Snake X on January 01, 2011, 02:51:55 pm
icwutudidther....  :P
Title: Re: Moving a Sprite
Post by: Munchor on January 01, 2011, 02:55:14 pm
Forgot to add comments:

Code: [Select]
.SMILIE
.The Sprite, change the Hex to whatever you want
[004466000000817E]->Pic1
.Do everything below until CLEAR is pressed
Repeat getKey(15)
StorePic
.Display Sprite
Pt-On(X,Y,Pic1
DispGraph
Pt-Change(X,Y,Pic1
RecallPic
ClrDraw
.Right Key
If getKey(3) and (X<92)
X+1->X
End
.Left Key
If getKey(2) and (X>2)
X-1->X
End
.Down Key
If getKey(1) and (Y<60)
Y+1->Y
End
.Up Key
If getKey(4) and (Y>2)
Y-1->Y
End
. End of the game loop
End

Also, optimized unneeded stuff.
Title: Re: Moving a Sprite
Post by: yunhua98 on January 01, 2011, 03:02:03 pm
I just wanted to optimize that...  ;)
Code: [Select]
:.SMILE
:[004466000000817E]->Pic1
:DiagnosticOff
:0->X->Y
:Repeat getkey(15)
:Pt-Off(X,Y,[0000000000000000]
:X+getkey(3)-getkey(2)->X
:Y+getkey(1)-getkey(4)->Y
:Pt-On(X,Y,Pic1
:DispGraph
:End

oh, wait, you want boundaries...

Code: [Select]
:.SMILE
:[004466000000817E]->Pic1
:DiagnosticOff
:0->X->Y
:Repeat getkey(15)
:Pt-Off(X,Y,[0000000000000000]
:X+(getkey(3) and (X<88))-(getkey(2) and (X>0))->X
:Y+(getkey(1) and (Y<56))-(getkey(4) and (Y>0))->Y
:Pt-On(X,Y,Pic1
:DispGraph
:End
Title: Re: Moving a Sprite
Post by: Munchor on January 01, 2011, 03:25:16 pm
Optimizations like Runer112 does!
/me runs

I know everything I do can be optimized, and people always optimize my stuff xD But thanks ;D
Title: Re: Moving a Sprite
Post by: Runer112 on January 01, 2011, 06:47:51 pm
As small as I could get it, 345 bytes of executable code. ;)

Code: [Select]
:.SMILE
:[004466000000817E]->Pic1
:DiagnosticOff
:0->X->Y
:Repeat getkey(15)
:ClrDraw
:getKey(3)-getKey(2)+X
:!If +1
:+1
:End
:-1
:Pt-On(min(,88)→X,getKey(1)-getKey(4)+Y+(=⁻1)min(,56)→Y,Pic1)
:DispGraph
:End
Title: Re: Moving a Sprite
Post by: squidgetx on January 02, 2011, 10:33:47 am
O.o

It took me about 2 straight minutes staring at the screen before I finally understood what that did.
Title: Re: Moving a Sprite
Post by: Munchor on January 02, 2011, 10:39:40 am
I always go :crazy: and :w00t: when I see Runer's optimizations...
Title: Re: Moving a Sprite
Post by: AngelFish on January 02, 2011, 12:51:17 pm
As small as I could get it, 345 bytes of executable code. ;)
<snip>

As cool as that optimization is, Runer, it ignores a major part of Scout's code. Notice the "Storepic." That's there to store the screen so that it can be replaced later, when the sprite is erased. Likewise, the "Recallpic" replaces it.
Title: Re: Moving a Sprite
Post by: squidgetx on January 03, 2011, 01:00:25 pm
I think I just made it a wee bit smaller :D (now it's 362 bytes :o with .4.6)
never mind lol

Code: [Select]
:.SMILE
:[004466000000817E]->Pic1
:DiagnosticOff
:0->X->Y
:Repeat getkey(15)
:ClrDraw
:getKey(3)-getKey(2)+X
:!If +1
:1
:End
:-1
:Pt-On(min(,88)→X,getKey(1)-getKey(4)+Y+(=⁻1)min(,56)→Y,Pic1)
:DispGraph
:End
You could use the DispgGraphClrDraw at the end as well to save speed (idk about size) but I don't have .4.7 :P

Also @qwerty, I think that since this code serves the same purpose (moving around a sprite) its ok :P
Title: Re: Moving a Sprite
Post by: Runer112 on January 03, 2011, 01:08:26 pm
I opted out of that optimization because I assumed that if somebody wanted to use this code in their program, they would probably have more than just that one sprite in the buffer and wouldn't want to clear it every time they updated the screen.
Title: Re: Moving a Sprite
Post by: squidgetx on January 03, 2011, 01:10:47 pm
Actually the main one that I was talking about was changing !If +1:+1:End to !If +1:1:End (or are you talking to qwerty?)
Title: Re: Moving a Sprite
Post by: Runer112 on January 03, 2011, 01:11:46 pm
+1 is smaller and faster than 1 :P
Title: Re: Moving a Sprite
Post by: squidgetx on January 03, 2011, 01:13:35 pm
oh really?

...

fail >.<
Title: Re: Moving a Sprite
Post by: DJ Omnimaga on January 04, 2011, 03:21:12 am
+1 is smaller and faster than 1 :P
O.O what?
Title: Re: Moving a Sprite
Post by: squidgetx on January 04, 2011, 05:27:56 am
Yes I think it's because adding one to hl is faster than loading one into hl.

Did someone accidentally sticky this? I unstickied it :P (actually could have been me, I never know quite what I'm pressing while on a itouch lol)
Title: Re: Moving a Sprite
Post by: DJ Omnimaga on January 04, 2011, 03:16:24 pm
Maybe someone accidentally clicked the button X.x