Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: Radical Pi on March 11, 2010, 12:34:47 am

Title: Movement with scrolling
Post by: Radical Pi on March 11, 2010, 12:34:47 am
Practically on an impulse, I decided to try and make a typical movement-with-a-string-map routine, but this map is 20x40 and scrolls. I also wanted it to stop scrolling when it gets to the edge of the map (domain error prevention, plus I think it's a nice effect). So when that happens, the player who has been so far stuck in the middle of the screen becomes off-centered. What I want to do next though is when you move away from the edge of the map, I want to re-center the player (one step at a time, of course). I'm probably not explaining this adequately...

Also, I'd prefer if no one gave me an answer in code. Just the theory behind it, so I can still get my practice.

Code: [Select]
:"a huge string implementation of a 20x40 map→Str1
:10→R
:20→C
:7→P
:13→Q
:For(A,1,8
:Output(A,1,sub(Str1,40P-80+Q+40A,16
:End
:Output(4,8,"π
:Repeat K=45
:Repeat max(Ans={24,25,26,34,45
:getKey→K
:End
:R-(K=25 and sub(Str1,40R-80+C,1)=" ")+(K=34 and sub(Str1,40R+C,1)=" →A
:C-(K=24 and sub(Str1,40R-41+C,1)=" ")+(K=26 and sub(Str1,40R-39+C,1)=" →B
:P+A-R→P
:Q+B-C→Q
:A→R
:B→C
:min(13,max(1,P→P
:min(25,max(1,Q→Q
:For(A,1,8
:Output(A,1,sub(Str1,40P-80+Q+40A,16
:End
:Output(R-P+1,C-Q+1,"π
:End
Disregard how it's not optimized right now. I'll do that after getting it all to work.
Title: Re: Movement with scrolling
Post by: meishe91 on March 11, 2010, 12:49:54 am
Would you want optimizations if any are spotted?
Title: Re: Movement with scrolling
Post by: Radical Pi on March 11, 2010, 01:03:51 am
Sure, but I probably won't be doing anything with them yet.
Title: Re: Movement with scrolling
Post by: meishe91 on March 11, 2010, 01:14:59 am
Ok.
Title: Re: Movement with scrolling
Post by: DJ Omnimaga on March 11, 2010, 01:52:01 am
Mhmm nice, it reminds me tifreak8x RPG Starter Kit 2 and Pokemon Purple.

I had such scrolling for the world map in ROL1 and 2, as well as Mana Force 2, but my attempt was incredibly slow. Part of it was because I wanted it to run at the same speed at the top of map as at the bottom, though, and it was a 40x50 map if I remember. I always had issue with the map running at like 1.5 FPS at the top of the string, then at the bottom 0.5 x.x
Title: Re: Movement with scrolling
Post by: {AP} on March 11, 2010, 03:15:38 am
For scrolling and staying in the middle as much as possible, here's the best I can explain it without giving code. (well, at least my method)

I'm not sure how much recoding it would take for you though. I haven't played with string maps (especially scrolling) much but I'm sure it's the same principle.

What's important is when you make it scroll. Currently, you scroll anytime you move in a direction that's not at the edge already. For example, you're going to want it the scroll up if it gets to say, the 4th row. Here's where I have a total of 4 variables for my location. Actual X(C), actual Y(R), amount scrolled right(A), and amount scrolled down(B). (The variables I'll use for reference, feel free to use your own.) If you're starting at the top corner, it should be 2,2,0,0 respectively. You're current outputted location should be Output(R-B,C-A,"π"). As you're moving right, once C>7 (about halfway) and A!=(Whatever the max to scroll right is) you should increase A and scroll the map. If after you move, C<8 and A!=0 then you should decrease A and scroll the map. Same principle for up and down.

Now, how you implement that will be what you need to figure out. (Sorry if I either explained too much. If you didn't understand something, however, just ask.)
Title: Re: Movement with scrolling
Post by: Radical Pi on March 11, 2010, 12:53:47 pm
I think I understand that as well as I possibly could without seeing it in code. Thanks. I'll rewrite my engine with those things in mind later when I have the time.

EDIT: I added these two lines between the Q+B-C→Q and the A→R line. I'm aware of how hideously inefficient this entire program is right now, but as long as it works for now I'm fine with it.
Code: [Select]
P+(K=25 and R-P+1>5)-(K=34 and R-P+1<4→P
Q+(K=24 and C-Q+1>9)-(K=26 and C-Q+1<8→Q
This has the convenient side-effect of letting you freely move between the center square of coordinates without scrolling.
Title: Re: Movement with scrolling
Post by: jsj795 on March 11, 2010, 02:08:01 pm
I did that to my pokemon clone before. This was sort of an experiment by me to do a grayscale with xlib, and when I was coding, I forgot that Ash always stays in the middle. Sadly, I deleted the code, so I don't have it anymore...
Title: Re: Movement with scrolling
Post by: {AP} on March 11, 2010, 04:06:18 pm
Glad I could help. =)

Also, sorry for the wrong numbers/etc... I wrote it on like 36+ hours of no sleep and like 4 weeks of crappy sleep. xP
Good to see you figured out a way though.
Title: Re: Movement with scrolling
Post by: ztrumpet on March 11, 2010, 06:48:40 pm
Great code Nyrax!  Good luck finishing it! ;D

I always had issue with the map running at like 1.5 FPS at the top of the string, then at the bottom 0.5 x.x
To clarify, this is because the farther you get in a string, the slower sub( is. =\
Title: Re: Movement with scrolling
Post by: Radical Pi on March 11, 2010, 07:27:51 pm
There's not really any way around the sub issue, unless I don't use strings at all. But then what's the alternative, matrices? I'd rather not have a matrix that big here :P

Code: (now optimized and generalized for strings of any size) [Select]
:"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                                  X   XX       X          X                   XX  X                   X      X        XX        X     X    X       X          XX    XX  X       X                 X   XX   X                     X       X    XX                       X      X     X XX                                      XX      X          X                    XX                       X      X       XX         X                    X   X   XX                X       X             XX                   X    X        X    XX                          X           XX           X     X        X       X   XX    X             X     X             XX        X        X         X  X       XX         X    X     X          X      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX→Str1
:20→L
:40→W
:10→R
:20→C
:7→P
:13→Q
:For(A,1,8
:Output(A,1,sub(Str1,WP-2W+Q+WA,16
:End
:Output(4,8,"π
:Repeat K=45
:Repeat max(Ans={24,25,26,34,45
:getKey→K
:End
:C-(K=24 and sub(Str1,WR-W-1+C,1)=" ")+(K=26 and sub(Str1,WR-W+1+C,1)=" →B
:R-(K=25 and sub(Str1,WR-2W+C,1)=" ")+(K=34 and sub(Str1,WR+C,1)=" →A
:min(L-7,max(1,P+Ans-R+(K=25 and R-P>4)-(K=34 and R-P<3→P
:min(W-15,max(1,Q+B-C+(K=24 and C-Q>8)-(K=26 and C-Q<7→Q
:A→R
:B→C
:For(A,1,8
:Output(A,1,sub(Str1,WP-2W+Q+WA,16
:End
:Output(R-P+1,Ans-Q+1,"π
:End

And with that, I think I'm done with this random mini-project.
Title: Re: Movement with scrolling
Post by: ztrumpet on March 11, 2010, 10:10:45 pm
That looks very nice!  Excellent job!  This would be nice in an RPG, but I'm not sure it you'd want to start an RPG off this. :)
Awesome job! ;D
Title: Re: Movement with scrolling
Post by: DJ Omnimaga on March 11, 2010, 11:51:24 pm
pretty fast ^^