Zelda scrolling issues (reposted from GD thread)

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Zelda scrolling issues (reposted from GD thread)

Post by Foxley »

I'm having some difficulty getting the scrolling scripts to work properly. It mostly works, but whenever I walk to a different screen and then immediately walk back to the previous screen, it doesn't trigger the script and basically breaks the game.

Try it out if you'd like:
https://dl.dropboxusercontent.com/s/7z9 ... tion37.zip

Any insights as to why this is happening? I suspect it may be something to do with "hero is walking" and/or wait ticks. Or, I honestly don't know.

Here's the HSS:

Code: Select all

plotscript, newgame script, begin
	variable (startx, starty)
	startx := hero x(me) -- 7
	starty := hero y(me) -- 5
	put camera (startx * 20, starty * 20)
	
	load slice collection (0)
	
	while (true) do (
		screen edge check
		wait (1)
	)
end

script, screen edge check, begin
	if (hero is walking == false) then (
		if (read zone(1, hero x(me), hero y(me)) && key is pressed(key:up)) then (scroll(up))
		if (read zone(2, hero x(me), hero y(me)) && key is pressed(key:right)) then (scroll(right))
		if (read zone(3, hero x(me), hero y(me)) && key is pressed(key:down)) then (scroll(down))
		if (read zone(4, hero x(me), hero y(me)) && key is pressed(key:left)) then (scroll(left))
	)
end

script, scroll, dir, begin
	suspend player
	switch (dir) do (
		case (left, right) pan camera (dir, 16, 8)
		case (up, down) pan camera (dir, 8, 5)
	)
	set hero speed (me, 1)
	walk hero (me, dir, 1)
	wait for camera
	set hero speed (me, 4)
	resume player
end

User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

OK, I finally figured it out after examining what the "while true" loop was doing step by step... It wasn't re-checking the screen scrolling zones with "screen edge check" on the same tick after resuming playing movement, so if you were to hold the opposite direction key right after scrolling, the hero would already be moving and wouldn't trigger the screen scroll on that tick.

Code: Select all

script, scroll, dir, begin
	suspend player
	switch (dir) do (
		case (left, right) pan camera (dir, 16, 8)
		case (up, down) pan camera (dir, 8, 5)
	)
	set hero speed (me, 1)
	walk hero (me, dir, 1)
	wait for camera
	set hero speed (me, 4)
	resume player
	screen edge check <-- This fixed it!
end
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

What General Discussion thread is that? I couldn't find it, and looks like I didn't add a link to it on the wiki, so I'll just link to this thread instead...

Your fix looks fine.
I notice that your script doesn't actually put the hero at the center of the screen. If the screen is 320x200, the camera should be 150 pixels left, 90 pixels up from the hero (since the hero x/y position is the hero's top-left corner).
Last edited by TMC on Wed Nov 16, 2016 1:08 pm, edited 2 times in total.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

TMC wrote:What General Discussion thread is that? I couldn't find it, and looks like I didn't add a link to it on the wiki, so I'll just link to this thread instead...
Oops, should have clarified. I posted it in the multicart thread on GD, realized a Q&A scripting question wasn't that appropriate, and deleted the post and reposted it here.
Your fix looks fine.
I notice that your script doesn't actually put the hero at the center of the screen. If the screen is 320x200, the camera should be 150 pixels left, 90 pixels up from the hero (since the hero x/y position is the hero's top-left corner).
I may have to test that later. I basically wanted the camera to be at the top left corner of the top left tile of the starting screen, of a 16x8 tile grid (a 320x40 pixel box is at the top for stats, items, etc) and my script more or less did what I wanted it to.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Oh right, for a Zelda scrolling script you'd likely want the camera to be tile-aligned.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I found an existing article, which I simply replaced with a link to this thread, and then went on a huge wiki editing binge. I should put the actual script on the wiki and explain it a little. And link to your game when it's done, rather than a temporary download link
Last edited by TMC on Thu Nov 17, 2016 4:04 pm, edited 1 time in total.
Post Reply