Author Topic: Grammer Sprite Editor  (Read 2490 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Grammer Sprite Editor
« on: November 17, 2011, 05:45:21 pm »
I was requested earlier to make a new example program and was then suggested to make a sprite editor. So here we are :)
Code: [Select]
*Indents are here solely for viewability

.0:Return                ;The header
"USprite→A               ;Stores the string location to A (used for optimisation since the string is used several times)
Get(A                    ;Gets the location of the appvar named Sprite
If =0                    ;Zero is returned if the var does not exist
Then
  ClrDraw                  ;Clears the draw buffer (graph screen) and resets text coordinates
  Text(º"How many sprites? ;º means draw to the last text coordintate
  DispGraph                ;Displays the draw buffer
  expr(Input →N            ;Allows the user to input a string and expr( turns it to a number
  Text(6,0,"Width?         ;
  DispGraph                ;
  expr(Input →W            ;
  Text(12,0,"Height?       ;
  DispGraph                ;
  expr(Input →H            ;
  Send(4+N*W*H,A→Z         ;Creates the appvar :)
  int(Z,W                  ;Stores the Width to the first byte of the var
  int(Z+1,H                ;Stores the Height to the second byte of the var
  iPart(Z+2,N              ;Stores the Number of sprites (stores it as a 2-byte word)
End
Unarchive A
Get(A→Z                  ;
IS>(Z→W                  ;reads the byte at Z, then increme,nts Z
IS>(Z→H
{Z→N
Z+2→Z
ClrDraw
0→X →Y →B                ;X will be X pixel Coord, Y=Ypixel coord, B=sprite number
π87EC→θ                  ;This is the location of the clipboard (256 bytes)
Line(0,0,1+H,1+W*8,3     ;Draws the boundaries for the sprite
Repeat A=55              ;55 is the [mode] key
Z+B*W*H→V                ;Used multiple times, so why not store it to a var?
Pt-On(0,V,0,0,W,H        ;Draws the sprite
Repeat A=55 +getKey(10 +getKey(11
  pxl-Test(Y,X→C
  9→D
    Repeat A
    D+1
    If >9                    ;Checks if the previous result is >9. This is the timer for blinking
    Pxl-Change(Y,X 0         ;Changes the pixel state at Y,X and then returns 0 in Ans
    →D
    getKey→A
    End
  Pxl-Off(Y,X
  C
  If getKey(56           ;56=Delete
  0
  If getKey(9            ;9=Enter
  1
  If getKey(54           ;54=2nd
  !C
  If Ans
  Pxl-On(Y,X
  If A=15
  Line(0,0,H,W*8,0       ;Draws a white rectangle to erase the sprite data
  Y+H+getKey(1
  -getKey(4
  /H θ'→Y                ;θ' is the remainder from the division. This lets the cursor loop :)
  X+getKey(3
  -getKey(2
  +W*8 /W*8 θ'→X
End
Pt-On(4,Z+B*W*H,0,0,W,H   ;Swaps the sprite data from on screen to the sprite set (saves the changes)
B+N+getKey(10
-getKey(11
/N θ'→B
End
Stop
That is working code (without the clipboard).

The program here allows you to create a sprite set if appvar Sprite does not exist, it prompts for the number of sprites to include as well as their size. There is clipboard functionality as well as a kind of "Undo" for mistakes. Have fun?

Oh, also, I was also told to make it work with the map editor, so that should happen soon >:D But I have to go to work now...

Oh, and for those who plan to use the sprite sets, the offset into the appvar data is 4 to get to the sprite data (the first 4 bytes tell the number of sprites and size).

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Grammer Sprite Editor
« Reply #1 on: November 18, 2011, 09:49:55 am »
Nice Program! O.o I might try it out! :)

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!