Author Topic: Pixel Testing Routine Tutorial  (Read 1978 times)

0 Members and 1 Guest are viewing this topic.

Offline josh landers

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 116
  • Rating: +1/-0
    • View Profile
Pixel Testing Routine Tutorial
« on: March 10, 2014, 05:08:39 pm »
If you have optimizations to add please post!

Problem: Your trying to move a sprite around and need it to not hit walls.
You have a regular 8x8 sized character.  The walls are of any thickness. 

So your first step after building a map is to set up a loop. Use something like repeat geykey(#) if the user presses that key the loop ends. Now choose the keys that will move the sprite, keep in mind going diagonal with this will look sloppy.
Code: [Select]
:prgmMAPSRC
:repeat getkey(15)
After you pick your keys for movement set up a loop for each key.Now pick the name of your subroutine.  Put that in following the sub put the result. In the no deduct a point or life ect.
Code: [Select]
:If geykey(#)
:Sub(X,Y,W)
:If W=1
:L- -
:else
:X- -        \or  y- - or + +
:End
:End

The subroutine is dependent on the location of your sprite and a "hotspot" your going to use r1 as x and r2 as y. r3 is w.
Code: [Select]
:Lbl Sub
:pxl-test(r1+#, r2+#)-> r3
:Return
Now the last part to this is to close off the whole thing with an end and after the end a return.
Code: [Select]
:End
:Return

TADA! Its not that bad. In fact I have use it with 4 hotspots and a a multidriectional character, this code is less then 500 bytes.