Author Topic: Map Editor Code  (Read 9049 times)

0 Members and 1 Guest are viewing this topic.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Map Editor Code
« on: June 19, 2009, 03:54:12 pm »
ok here is the code I am using for my map editor, after this project is done I will try to make it better, right now it only supports 22*16 maps, but it can easily be customized to support more. The mapmaker also includes a converter to convert your map to a binstring so you can use it with the stringtile command in Celtic III, and it also will display a minimap of the current map from a hex string (0h format not 00h) which I am going to cut from the final version because it is unnecessary. and doesn't work with the output by the program. The reason I am posting this is because I want people to take a look and tell me of any optimizations they can see. I also want to post this code so people can use it as a reference on how to make quick map editors for their own projects.
The code also is commented so it is easier to understand
Code: [Select]
:ClrHome //
:Disp "1=CONVERT","2=DISPLAY","3=MAPEDIT","0=QUIT //menu
:Input "□",A //
:A
:If Ans=3:Then //if map edit
:DelVar K
:ClrDraw
:Disp "1=NEW","0=KEEP //map menu
:Input "□",S //
:If S:Then //if new map
:{16,22→dim([A] //reset map
:Fill 5,[A] //fill it with the default background tile
:End
:For(A,0,33) //start loading map
:Pxl-On(A,45 //draw map outline
:Pxl-On(A,0 //
:End //
:For(B,0,44) //draw map outline
:Pxl-On(33,B //
:Pxl-On(0,B //
:End //
:For(A,‾1,1) //
:Pxl-On(38+A,0 //draw loading bar left edge
:End //
:For(A,‾1,1) //
:Pxl-On(38+A,17 //draw loading bar right edge
:End //
:For(B,1,17) //
:Pxl-On(39,B //draw loading bar
:Pxl-On(37,B //
:End //
:For(A,1,16) //start loading map
:Pxl-On(38,A //
:For(B,1,22) //
:[A](A,B→S //
:If 3=S //display default hard tile
:Then //
:Pxl-On(A+40,B //display on minimap
:For(θ,0,1) //
:For(Z,0,1) //
:Pxl-On(2A-Z,2B-θ //display on building map
:End:End //
:Else //
:If 6=S //display spike tile
:Then //
:Pxl-On(2A,2B //display on building map
:Else //
:If 10=S //display ladder tile
:Then //display on building map
:Pxl-On(A2,B2 //
:Pxl-On(A2,B2-1 //
:Else //
:If 11=S:Then //display water tile
:Pxl-On(A2-1,B2 //display on building map
:Pxl-On(A2,2B-1 //
:End:End:End:End:End:End //
:For(B,0,17) //
:For(A,‾1,1) //clear loading bar
:Pxl-Off(38+A,B //
:End:End //end loading map
:1→A:1→B
:While K≠105 //loop until user presses enter
:DelVar K //clear keyvalue
:Repeat K //loop until keyvalue
:For(Z,0,1) //
:For(θ,0,1) //change the current tile to negative
:Pxl-Change(2A-θ,2B-Z //
:End:End //
:getKey→K //getkey to keyvalue
:For(θ,0,1) //
:For(Z,0,1) //change current tile back
:Pxl-Change(2A-θ,2B-Z //
:End:End //
:End
:A-(K=25 and A≠1)+(K=34 and A≠16→A //change Y of current tile
:B-(K=24 and B≠1)+(K=26 and B≠22→B //change X of current tile
:If K=31:Then //if keyvalue is Alpha
:Pxl-On(A2,B2 //change pixels to spike tile
:Pxl-Off(A2-1,B2-1 //
:Pxl-Off(A2,2B-1 //
:Pxl-Off(A2-1,B2 //change matrix value to spike tile
:6→[A](A,B
:Else
:If K=22:Then //if keyvalue is mode
:Pxl-On(2A,2B-1 //change pixels to ladder tile
:Pxl-On(A2,B2 //
:Pxl-Off(2A-1,2B-1 //
:Pxl-Off(2A-1,2B //
:10→[A](A,B //change matrix value to ladder tile
:Else
:If K=32:Then //if keyvalue is X,T,theta,n
:Pxl-On(2A-1,B2 //change pixels to water tile
:Pxl-On(A2,2B-1 //
:Pxl-Off(A2,B2 //
:Pxl-Off(A2-1,B2-1 //
:11→[A](A,B //change matrix to water tile
:Else
:If K=21:Then //if keyvalue is 2nd
:[A](A,B→S //get matrix value
:If S≠3 and S≠4 and S≠9:Then //if matrix value is not a solid tile
:Pxl-On(A+40,B //turn on pixel on minimap
:Else
:Pxl-Off(A+40,B //else turn it off
:End
:For(θ,0,1) //
:For(Z,0,1) //
:If S=5:Then //display tile on buildermap
:Pxl-On(2A-θ,2B-Z //
:Else //
:Pxl-Off(2A-θ,2B-Z //
:End:End:End //
:If S≠5:Then //if not solid
:5→T //make solid
:Else
:3→T //otherwise make it the default solid
:End
:T→[A](A,B //insert value to matrix
:End:End:End:End:End:Else
:ClrDraw //this is the converter portion of the program
:If Ans=1:Then
:"0000000000000000000000000000000000000000000000→Str1 //this is the initial setup of the String
:For(A,1,16)
:For(B,1,22)
:1+[A](A,B→S //grabs teh tile value+1 from the matrix
:Str1+"0"+sub("0123456789ABCDEF",S,1→Str1 //inserts a "0" and the right value into the string
:If S=3 or S=4 or S=9 //if tile is solid
:Pxl-On(A-1,B-1 //turn on the pixel for the minimap
:End
:End
:det(17,Str1→Str1 //convert string to bin
:Else
:If Ans=2:Then //this is the display minimap
:For(A,1,16) //it requires a hex string (0h not 00h format)
:For(B,1,22)
:If inString("349",sub(Str1,22A-22+B,1 //if solid tile
:Pxl-On(A-1,B-1 //turn on minimap
:End:End:End
:ClrHome
/e

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: Map Editor Code
« Reply #1 on: June 19, 2009, 07:40:04 pm »
nice this might be useful if i decided to use this map format for a future game

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Map Editor Code
« Reply #2 on: June 19, 2009, 07:47:21 pm »
:) and the great thing about it is that it uses matrices and bin strings so you can develop for either with it
/e

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Map Editor Code
« Reply #3 on: June 21, 2009, 08:57:51 am »
Optimization? I will look. All those For( loops and matrix commands maybe arise some possibilities to optimize.
Hobbing in calculator projects.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Map Editor Code
« Reply #4 on: June 21, 2009, 06:43:17 pm »
hmm? how so?
/e

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: Map Editor Code
« Reply #5 on: June 21, 2009, 06:46:13 pm »
Oh I see! He means changing For(A,0,33) to For(A,0,33

But be careful with that stuff, due to the TI-OS glitch.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Map Editor Code
« Reply #6 on: June 21, 2009, 06:53:36 pm »
yeah, I tend to leave them closed just in case
/e

Offline Ti-newb

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 180
  • Rating: +3/-0
    • View Profile
Re: Map Editor Code
« Reply #7 on: June 22, 2009, 12:52:40 am »
uhhh.. *il start leaving some stuff closed..*

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Map Editor Code
« Reply #8 on: June 22, 2009, 02:17:00 am »
To save confusion, the glitch is VERY rare.

If your program isn't all that big, then you can close them no problem.
If you're pressing for space, getting rid of extra parentheses should be your first optimization.
Of course, have a back up just in case. (which you should do all the time anyway) Then run the program through to test it.
If the problem doesn't occur, (and 99% of the time it won't) then you're good.

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: Map Editor Code
« Reply #9 on: June 22, 2009, 02:37:39 am »
Well

from what I saw in TI|BD wiki, the slow down occurs only when the For( loop only contains a If instruction with no Then/Else and if the condition is false. I have no clue when the glitch causes the calc remains slows for the remainder of program execution, though. I used such For( loop at various places I think and only had such slow down occur in the last attempt

I don't remember exactly Metroid II and Zelda DLQ code, but maybe I used such For( loop in them and I sometimes wonder if this isn't what causes these games to run that slow. Metroid II running so slow when walking around is something I never understood, considering the walking loop isn't that big. It could be because of the large amount of sub-programs but I noticed the game doesn't even run faster if I delete most of them
« Last Edit: June 22, 2009, 02:41:05 am by DJ Omnimaga »

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Map Editor Code
« Reply #10 on: June 22, 2009, 07:13:24 am »
Yep. Cut parentheses in all For( unless they do a large loop or you see an If inside.
hmm? how so?
:{16,22→dim([A]                  //reset map
:Fill 5,[A]                  //fill it with the default background tile
I was looking in matrix commands to optimize. But just happens this is the smallest.
Alternatives were using identity( but it is not a "square" matrix. Also Something like 0[A]+5->[A] doesn't even works and is bigger.

Some For( like this one:
:For(A,1,16)                  //it requires a hex string (0h not 00h format)
:For(B,1,22)
:If inString("349",sub(Str1,22A-22+B,1         //if solid tile
:Pxl-On(A-1,B-1                  //turn on minimap
:End:End

See if changes in step and values can optimize things. Sort of this: (not tested and was rushed)
:For(A,22,352,22)               //nah this one actually increases size.
:For(B,-21,0)
:If inString("349",sub(Str1,A+B,1         //if solid tile
:Pxl-On(A/22-1,B+21               //this seems to kill the optimization in above lines even if A/22 is always integer
:End:End

But this kind of changes can be used in other loops. See if you find know you know this.



:DelVar K                  //clear keyvalue
Are you sure this line is needed?


:For(θ,0,1)                  //
:For(Z,0,1)                  //
:If S=5:Then               //display tile on buildermap
:Pxl-On(2A-θ,2B-Z            //
:Else                     //
:Pxl-Off(2A-θ,2B-Z            //
:End:End

There you can use Line( ?
Like this:
Line(2B,2A-1,2B-1,2A,S=5         // don't forget pixels change in arguments (row and column to x and y)
the last argument if is 1 (true) then it is a black line, otherwise (false) a white line.



:For(B,0,44)                  //draw map outline
:Pxl-On(33,B                  //
:Pxl-On(0,B                  //
:End
I think this is not a loading bar. So you could optimize by speed and see if size into Line( ?
Hobbing in calculator projects.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Map Editor Code
« Reply #11 on: June 22, 2009, 10:17:50 am »
Some For( like this one:
:For(A,1,16)                  //it requires a hex string (0h not 00h format)
:For(B,1,22)
:If inString("349",sub(Str1,22A-22+B,1         //if solid tile
:Pxl-On(A-1,B-1                  //turn on minimap
:End:End

See if changes in step and values can optimize things. Sort of this: (not tested and was rushed)
:For(A,22,352,22)               //nah this one actually increases size.
:For(B,-21,0)
:If inString("349",sub(Str1,A+B,1         //if solid tile
:Pxl-On(A/22-1,B+21               //this seems to kill the optimization in above lines even if A/22 is always integer
:End:End
lol, yeah, that does kind of kill the optimization
Quote
:DelVar K                  //clear keyvalue
Are you sure this line is needed?
yes I do need that or else it will not enter the key loop and you will be stuck doing the exact same thing until you press [on]
see there:
Code: [Select]
:DelVar K //clear keyvalue
:Repeat K //loop until keyvalue
:For(Z,0,1) //
:For(θ,0,1) //change the current tile to negative
:Pxl-Change(2A-θ,2B-Z //
:End:End //
:getKey→K //getkey to keyvalue
:For(θ,0,1) //
:For(Z,0,1) //change current tile back
:Pxl-Change(2A-θ,2B-Z //
:End:End //
:End
Quote
:For(θ,0,1)                  //
:For(Z,0,1)                  //
:If S=5:Then               //display tile on buildermap
:Pxl-On(2A-θ,2B-Z            //
:Else                     //
:Pxl-Off(2A-θ,2B-Z            //
:End:End

There you can use Line( ?
Like this:
Line(2B,2A-1,2B-1,2A,S=5         // don't forget pixels change in arguments (row and column to x and y)
the last argument if is 1 (true) then it is a black line, otherwise (false) a white line.
yes, I guess I could use two line statements, but then I would have to add a piece of code at the start to setup the window dimensions, and I always did hate trying to get that to work perfectly. I'll try it though, thanks!
Quote
:For(B,0,44)                  //draw map outline
:Pxl-On(33,B                  //
:Pxl-On(0,B                  //
:End
I think this is not a loading bar. So you could optimize by speed and see if size into Line( ?
I know that I could use a line here, which I should have, but I always dislike working with lines because of the problems of window dimensions, I should probably do that though, although, I do like my line drawing routine that I came up with for using pxl-on( it's nice and quick. XD I probably wasn't the first to use it though
/e

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Map Editor Code
« Reply #12 on: June 22, 2009, 12:03:22 pm »
Hum, in Repeat you enter in the loop no matter what. getkey being stored to K in the middle makes no use to DelVar K. If was a while, then the loop can be skipped.

eh problems setting windows setting?
I use this to set top border to (0,62). To get y is 62-Y
ZStandard
84->Xmin
52->Ymin
ZInteger

And this to (0,0) But Y is always negative. So to get Y
ZStandard
84->Xmin
-72->Ymin             // I think I got even a smaller version here... I don't where I used.
ZInteger


They never disappointed me. And is the smallest I can get.
EDIT: wonderful I have beaten TI|BD Friendly Graphing Window in size >_>
http://tibasicdev.wikidot.com/friendly-window
I will edit it someday.
« Last Edit: June 22, 2009, 12:27:00 pm by Eeems »
Hobbing in calculator projects.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6268
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Map Editor Code
« Reply #13 on: June 22, 2009, 12:29:44 pm »
hmm, I forgot about that, it's a old habit from when I coded with While statements instead of Repeat, because I didn't know how to use Repeat. I know about user friendly windows, I'll have to do that, thanks :) good thing that this was only a quick 30 minute program that I made not one I've been working on for a while XD
/e

Offline Ti-newb

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 180
  • Rating: +3/-0
    • View Profile
Re: Map Editor Code
« Reply #14 on: June 22, 2009, 08:48:43 pm »
Glad to see alot of optimizations/edits going on. Btw, how do I get onto irc with a ipod touch?