Author Topic: Moving a Sprite  (Read 7739 times)

0 Members and 2 Guests are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Moving a Sprite
« 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



« Last Edit: January 01, 2011, 02:55:36 pm by ScoutDavid »

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
Re: Moving a Sprite
« Reply #1 on: January 01, 2011, 02:51:55 pm »
icwutudidther....  :P
« Last Edit: January 01, 2011, 02:52:07 pm by Snake X »
Loved this place, still the best producers of power metal, and sparked my dreams of coding.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Moving a Sprite
« Reply #2 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.

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Moving a Sprite
« Reply #3 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
« Last Edit: January 01, 2011, 03:15:07 pm by yunhua98 »

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Moving a Sprite
« Reply #4 on: January 01, 2011, 03:25:16 pm »
Optimizations like Runer112 does!
* ScoutDavid runs

I know everything I do can be optimized, and people always optimize my stuff xD But thanks ;D

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Moving a Sprite
« Reply #5 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

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Moving a Sprite
« Reply #6 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.
« Last Edit: January 02, 2011, 10:35:33 am by squidgetx »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Moving a Sprite
« Reply #7 on: January 02, 2011, 10:39:40 am »
I always go :crazy: and :w00t: when I see Runer's optimizations...
« Last Edit: January 02, 2011, 10:39:58 am by ScoutDavid »

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Moving a Sprite
« Reply #8 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.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Moving a Sprite
« Reply #9 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
« Last Edit: January 03, 2011, 01:13:55 pm by squidgetx »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Moving a Sprite
« Reply #10 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.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Moving a Sprite
« Reply #11 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?)
« Last Edit: January 03, 2011, 01:12:02 pm by squidgetx »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Moving a Sprite
« Reply #12 on: January 03, 2011, 01:11:46 pm »
+1 is smaller and faster than 1 :P

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Moving a Sprite
« Reply #13 on: January 03, 2011, 01:13:35 pm »
oh really?

...

fail >.<
« Last Edit: January 03, 2011, 01:16:24 pm by squidgetx »

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: Moving a Sprite
« Reply #14 on: January 04, 2011, 03:21:12 am »
+1 is smaller and faster than 1 :P
O.O what?
« Last Edit: January 04, 2011, 03:21:38 am by DJ Omnimaga »