Screenwise scrolling

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Screenwise scrolling

Post by Bob the Hamster »

I wanted to share a little screenwise scrolling script I wrote.

Code: Select all

#-----------------------------------------------------------------------

define constant(1, timer:camera)

#-----------------------------------------------------------------------

plotscript, on new game, begin
  init game
end

#-----------------------------------------------------------------------

script, init game, begin
  set hero speed(me, 6)
  camera handler
end

script, camera handler, begin
  variable(x, y, sx, sy)
  x := (hero pixel x(me) + 10) / 20
  y := (hero pixel y(me) + 10) / 20
  sx := x ,mod, 16
  sy := y ,mod, 10
  if(sx == 0) then(scrolling action(-1, 0))
  elseif(sx == 15) then(scrolling action(1, 0))
  elseif(sy == 0) then(scrolling action(0, -1))
  elseif(sy == 9) then(scrolling action(0, 1))
  put camera on screen by tile(hero x(me), hero y(me))
  set timer(timer:camera, 0, 1, @camera handler)
end

script, scrolling action, xgo, ygo, begin
  suspend player
  cancel hero walk(me)
  wait for hero(me)
  pan camera screenwise(xgo, ygo)
  walk hero relative(me, xgo * 2, ygo * 2)
  wait for camera
  wait for hero(me)
  resume player
end

script, walk hero relative, rank, xgo, ygo, begin
  if&#40;xgo < 0&#41; then&#40;walk hero&#40;rank, left, abs&#40;xgo&#41;&#41;&#41;
  if&#40;xgo > 0&#41; then&#40;walk hero&#40;rank, right, abs&#40;xgo&#41;&#41;&#41;
  if&#40;ygo < 0&#41; then&#40;walk hero&#40;rank, up, abs&#40;ygo&#41;&#41;&#41;
  if&#40;ygo > 0&#41; then&#40;walk hero&#40;rank, down, abs&#40;ygo&#41;&#41;&#41;
end

script, pan camera screenwise, xgo, ygo, begin
  # Pan the camera one screen in the given direction
  if&#40;xgo < 0&#41; then&#40;pan camera&#40;left, 16, 10&#41;&#41;
  if&#40;xgo > 0&#41; then&#40;pan camera&#40;right, 16, 10&#41;&#41;
  if&#40;ygo < 0&#41; then&#40;pan camera&#40;up, 10, 10&#41;&#41;
  if&#40;ygo > 0&#41; then&#40;pan camera&#40;down, 10, 10&#41;&#41;
end

script, put camera on screen by tile, tx, ty, begin
  # Set the camera so that the selected tile coordinates will be on-screen
  put camera&#40;tx / 16 * 16 * 20, ty / 10 * 10 * 20&#41;
end
This assumes that your map is organized into screens of 16x10 tiles and that the edges of each are only ever used for walking between maps (so your practical gameplay area is 14x8 tiles)

Yes, this was inspired by playing Xoo Xeno Xafari, which I believe uses a whole bunch of 16x16 maps connected with regular doors-- but it just got me thinking, how would you script this if you wanted to make it a single map?
Attachments
starjelly0000.gif
starjelly0000.gif (396.85 KiB) Viewed 3390 times
Last edited by Bob the Hamster on Tue Aug 11, 2020 10:41 pm, edited 1 time in total.
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

Okay, I intend to absolutely use this. I had a fan game concept in my head and had been considering simply making the dungeon a series of 16x10 maps linked via doors, but now I think I can fit that entire game onto one map.
Remeber: God made you special and he loves you very much. Bye!
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

Not the same project I had in mind, but what the heck, I'll use it a little early.
Attachments
aaa0010.gif
aaa0010.gif (490.55 KiB) Viewed 3327 times
Remeber: God made you special and he loves you very much. Bye!
User avatar
FnrrfYgmSchnish
Metal Slime
Posts: 741
Joined: Thu Jun 18, 2009 4:37 am
Location: Middle of Nowhere

Post by FnrrfYgmSchnish »

Seeing those two GIFs of this scrolling script in action, I'm suddenly reminded of "Spiritual Warfare," an obscure(?) old NES game which was a Zelda-clone sort of thing that happened to be religiously themed (complete with Bible quiz mini-game to win extra money to buy items with.)

It had black backgrounds just like Nathan's screens in most areas, and walls keeping you from walking off the edges where you weren't supposed to were mostly made up of single large rocks like James's screens rather than trying to copy Zelda's "mountain-ish" look.

Really neat to see that Zelda-type scrolling like this is possible in the OHRRPGCE!
FYS:AHS -- Working on Yagziknian NPC walkabout sprites
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

The screen jittered a little when I left the dungeon and went to the overworld through a standard door link, but then corrected itself (after I get some sleep I'll see if this repeats itself when I change the map to Crop mode instead of Wrap mode; it might also have to do with my standard doors being on the edges of maps). I have this script set up on the second floor of my dungeon, but not on the first floor (which is a one-screen map altogether) or any of the towns/interiors (likewise) or overworld (a 32x20 area with only the upper-left quarter being filled with anything).

Ah yes, Spiritual Warfare, probably Wisdom Tree's only good game. Or its most relatively good game?
Remeber: God made you special and he loves you very much. Bye!
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Oh, yeah, I never tested this on wrap maps or with regular doors.

That looks nice, Nathan!
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

I think what's happening is that my exit doors are usually on the bottom edge of the one-screen rooms the rest of the game consists of. So the script continues running itself even when you leave the map, and teleporting to one of the only maps large enough to scroll happening to be simultaneous with reaching the edge of the screen, the screen scrolls for a bit and then pops back into place.

So it looks like there's two easy ways to fix it: Shrinking the overworld to be 16x10 like most of the others and cutting off some inaccessible aesthetic tiles or writing different script(s) for the other maps. (My overworld is 32x20 but only 16x11 of that gets used). A third way would be to move everything in my town/dungeon maps up one space so the "return to overworld" doors never touch the edge, but I don't have a lot of room to work with here.
Attachments
aaa0011.png
aaa0011.png (14.92 KiB) Viewed 3291 times
aaa0009.png
aaa0009.png (3.44 KiB) Viewed 3292 times
aaa0007.png
aaa0007.png (16.14 KiB) Viewed 3291 times
Remeber: God made you special and he loves you very much. Bye!
User avatar
Willy Elektrix
Liquid Metal Slime
Posts: 910
Joined: Sun Aug 15, 2010 11:30 pm

Post by Willy Elektrix »

This is cool! Too had I didn't build Xoo as one big map.

Actually, that wouldn't have worked well anyway. Compartmentalizing all the numerous NPCs into lots of little maps turned out to be a handy organizational tool.
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

Be super careful not to put any open spots on the edge of a map if you use this. Your characters will get locked into walking in place against the edge.

I still haven't tried it with a wrap map; perhaps a Cave of Riches should be a floor of this dungeon?
Remeber: God made you special and he loves you very much. Bye!
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

Can confirm it works on wrap maps too, so long as there's corresponding empty spaces on both edges of the map.

This particular floor is going to have a puzzle to it.
Attachments
aaa0012.gif
aaa0012.gif (612.01 KiB) Viewed 3225 times
Remeber: God made you special and he loves you very much. Bye!
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

I found a funny interaction with this script and door linking into a map with a door placed on the edge of a screen. I mean, I suppose I could shrink all my indoors maps vertically by one square, keeping a completely blank row of spaces along the bottom edge, and moving my doors accordingly?

The heroes also walk to spaces above/below the town when they exit to the overworld and again I'm pretty sure this is because I put the exit doors right on the edges of the screens.
Attachments
aaa0014.gif
aaa0014.gif (1.2 MiB) Viewed 3158 times
Remeber: God made you special and he loves you very much. Bye!
Strela_999
Slime
Posts: 5
Joined: Thu Aug 20, 2020 3:41 pm

Post by Strela_999 »

It works for me as well, thanks, I was really stuck with that...
User avatar
Nathan Karr
Liquid Metal Slime
Posts: 1215
Joined: Fri Jan 25, 2008 3:51 am
Contact:

Post by Nathan Karr »

https://www.slimesalad.com/forum/viewgame.php?p=138395

Here you go, an entire game making use of this script.

Now that this weird distraction is finished I can return to revising TutOHRial.
Remeber: God made you special and he loves you very much. Bye!
Post Reply