Author Topic: Movement with scrolling  (Read 5357 times)

0 Members and 1 Guest are viewing this topic.

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Movement with scrolling
« 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.
One of these days I'll get a sig I'm really proud of.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Movement with scrolling
« Reply #1 on: March 11, 2010, 12:49:54 am »
Would you want optimizations if any are spotted?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Movement with scrolling
« Reply #2 on: March 11, 2010, 01:03:51 am »
Sure, but I probably won't be doing anything with them yet.
One of these days I'll get a sig I'm really proud of.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Movement with scrolling
« Reply #3 on: March 11, 2010, 01:14:59 am »
Ok.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

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: Movement with scrolling
« Reply #4 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

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Movement with scrolling
« Reply #5 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.)
« Last Edit: March 11, 2010, 03:21:08 am by {AP} »

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Movement with scrolling
« Reply #6 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.
« Last Edit: March 11, 2010, 01:29:55 pm by Nyrax »
One of these days I'll get a sig I'm really proud of.

Offline jsj795

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1105
  • Rating: +84/-3
    • View Profile
Re: Movement with scrolling
« Reply #7 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...


Spoiler For funny life mathematics:
1. ROMANCE MATHEMATICS
Smart man + smart woman = romance
Smart man + dumb woman = affair
Dumb man + smart woman = marriage
Dumb man + dumb woman = pregnancy
2. OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime
3. SHOPPING MATH
A man will pay $2 for a $1 item he needs.
A woman will pay $1 for a $2 item that she doesn't need.
4. GENERAL EQUATIONS & STATISTICS
A woman worries about the future until she gets a husband.
A man never worries about the future until he gets a wife.
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.
5. HAPPINESS
To be happy with a man, you must understand him a lot and love him a little.
To be happy with a woman, you must love her a lot and not try to understand her at all.
6. LONGEVITY
Married men live longer than single men do, but married men are a lot more willing to die.
7. PROPENSITY TO CHANGE
A woman marries a man expecting he will change, but he doesn't.
A man marries a woman expecting that she won't change, and she does.
8. DISCUSSION TECHNIQUE
A woman has the last word in any argument.
Anything a man says after that is the beginning of a new argument.

Girls = Time * Money (Girls are a combination of time and money)
Time = Money (Time is money)
Girls = Money squared (So, girls are money squared)
Money = sqrt(Evil) (Money is also the root of all evil)
Girls = sqrt(Evil) squared (So, girls are the root of all evil squared)
Girls = Evil (Thus, girls are evil)
*Girls=Evil credit goes to Compynerd255*

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Movement with scrolling
« Reply #8 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.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Movement with scrolling
« Reply #9 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. =\

Offline Radical Pi

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1143
  • Rating: +5/-2
    • View Profile
    • RealityRevolution
Re: Movement with scrolling
« Reply #10 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.
One of these days I'll get a sig I'm really proud of.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Movement with scrolling
« Reply #11 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

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: Movement with scrolling
« Reply #12 on: March 11, 2010, 11:51:24 pm »
pretty fast ^^