Jump to content

Photo

sideview water

sideview water swim

  • Please log in to reply
17 replies to this topic

#1 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 25 August 2014 - 06:54 PM

Yo!

Does anyone have or could make a sideview water (or sideview swim) script? :(

I thought I wouldn't need this script in my quest, but I changed my mind...

 

 



#2 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 25 August 2014 - 07:12 PM

ffc script Swimming
{
	void run()
	{
		this->Vy = 0;
		float accel = 0.16;
		float holddown = 0;
		float max_sink = 0.5;
		
		this->X = Link->X;
		this->Y = Link->Y;
		
		// A little upward velocity at the bottom of the screen to start, so you don't get scrolled off immediately.
		if (Link->Y > 156)
		{
			this->Vy = -2.0;
		}
		
		while (true)
		{
			// Screen->Wavy = 5;
			holddown = 0;
			this->X = Link->X;
			Link->Y = this->Y;
			
			if (Link->InputDown)
			{
				holddown = 0.16;
			}
			if (holddown > 0)
			{
				max_sink = 1.2;
			}
			else
			{
				max_sink = 0.8;
			}
			
			this->Vy = Min(max_sink, this->Vy + accel + holddown);
			if (Screen->isSolid(Link->X + 1, Link->Y + 16) || Screen->isSolid(Link->X + 15, Link->Y + 16))
			{
				if (this->Vy > 0)
				{
					this->Vy = 0;
				}
			}
			
			if (Link->PressA)
			{
				Game->PlaySound(SFX_SPLASH);
				this->Vy = -1.8;
				if (Link->InputUp)
				{
					this->Vy = -2.5;
				}
			}
			
			if (Screen->isSolid(Link->X + 1, Link->Y) || Screen->isSolid(Link->X + 15, Link->Y))
			{
				if (this->Vy < 0)
				{
					this->Vy = 0;
				}
			}
			
			Link->InputA = false;
			// Link->InputB = false; // Commenting this out to allow B button item use for water jet item. Use DMap item restrictions instead?
			Link->InputUp = false;
			Link->InputDown = false;
			
			Waitframe();
		}
	}
}

Needs std.zh.



#3 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 26 August 2014 - 03:50 PM

Uuuh! Thanks, dude!

I will test the script right now :)



#4 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 26 August 2014 - 07:35 PM

Lejes, the script works fine, but is missing how to set the Link sprites when he is swimming.

I think a combo with 2 animation frames solves the problem, but I don't know how to implement it in the script.

 

This video is excellent to use as reference (1:41:20).

https://www.youtube....h?v=BxUFhLuNYVY

 

It is also interesting to note that in the same place there is a transition between being inside and outside the water. But to create this transition, I imagine it's much more complicated to change in the script...


Edited by accela2me, 26 August 2014 - 07:51 PM.


#5 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 26 August 2014 - 08:48 PM

There's no implementation of swimming animation in that script at all.

const int SWIM_LEFT_COMBO = 84;
const int SWIM_RIGHT_COMBO = 84;
const int SWIM_COMBO_CSET = 8;

// Checks for Miscellaneous Screen Flag "General Use 1 (Scripts)" and draws swimming tiles if it is on.
global script slot2
{
	void run()
	{
		while (true)
		{
			if ((Screen->Flags[SF_MISC] & 100b) != 0 && Link->Action != LA_SCROLLING)
			{
				Link->Invisible = true;
				if (Link->Dir == DIR_UP || Link->Dir == DIR_LEFT)
				{
					Screen->FastCombo(4, Link->X, Link->Y, SWIM_LEFT_TILE, SWIM_COMBO_CSET, OP_OPAQUE);
				}
				else
				{
					Screen->FastCombo(4, Link->X, Link->Y, SWIM_RIGHT_TILE, SWIM_COMBO_CSET, OP_OPAQUE);
				}
			}
			else
			{
				Link->Invisible = false;
			}
			Waitframe();
		}
	}
}

Here's a global script that draws a combo over Link based on which direction he's facing and a miscellaneous screen flag. There is no custom combo drawn on screen scrolling, because that's far more annoying to implement than you'd think. Transitioning between swimming and non-swimming on the same screen would be easy. You just have to define, exactly, what would constitute a swimming tile in your quest, and what you want to happen on the transition. Having nothing happen (i.e. no custom animation or hopping out of the water) would be easiest, of course.



#6 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 27 August 2014 - 04:36 PM

Sorry, dude. The global script didn't work (or I didn't understand how to set up correctly).

Oh, and the "const int" is SWIM_LEFT_COMBO or SWIM_LEFT_TILE?



#7 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 27 August 2014 - 05:03 PM

Yes, it should be "COMBO" everywhere. I forgot to change it back from TILE.



#8 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 28 August 2014 - 06:05 PM

It worked! Well, not 100% yet, but we're almost there :)

Some weapons (sword and hammer, for example) also became invisible... and the transition between water and platforms really is very important (otherwise, it will leave the screen very limited).

How would the script with these last issues solved?



#9 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 28 August 2014 - 06:51 PM

The script was originally meant to ban all item use underwater. The swimming animation I've currently set up just makes Link invisible and draws the swimming tile over his position. Making it look right would require all kinds of custom animations I don't feel like drawing. You could try setting up your own Link tiles and use a Link Tile Modifier instead of making him invisible. That could solve weapon animation problems but it would also be a lot more work. As for transitions, you'd have to define what is water and what isn't. Currently it decides this based on a miscellaneous screen flag. A screen is either water, or it isn't. I can change this to be based on what kind of combo Link is on top of. That can be based on combo number, combo flag, type, whatever you want. I think stopping the custom animation and making Link jump when reaching the water's surface would be the easiest way to handle out of water transition.



#10 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 30 August 2014 - 09:27 AM

I used an item with LTM. Really solves the question with the weapons, but Link doesn't have that swimming animation when standing still, unlike when we use a combo.
I don't see this as a big problem, for blocking weapons when using the combo over the invisible Link... but only if he remains always under water.
Because if he gets out of the water onto a platform on the same screen, the weapons will need to be enabled again.
if it is not hard to do that in the script (instead of the DMAP or the Subscreen), to block the use of any weapon under water, then fine. Otherwise, it is a more complicated script than I imagined! ^^'



#11 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 30 August 2014 - 07:16 PM

I got out of water transitions working, but screen transitions have me stumped. The ZC engine is doing very strange things with Link's position, and I can't find a way to draw the combo over him properly or prevent him from immediately getting booted off the screen when scrolling up in sideview gravity.



#12 RetraRoyale

RetraRoyale

    Doyen(ne)

  • Members

Posted 30 August 2014 - 07:42 PM

When link changes screens, he is instantly warped to the opposite position on the new screen, and the code that draws him while scrolling is entirely separate. So what you'll probably have to do is manually draw link during screen transitions by remembering where he was and which way you are scrolling. (Also, note that there are a few post-scrolling frames where link just sits still before the new screen starts drawing its own scripts, if you decide to do FFC script based water.)

 

At least, that's how I would do it. If zscript has some magic method that I don't know about, then maybe it would be easier.



#13 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 30 August 2014 - 09:03 PM

import "std.zh"
import "string.zh"
import "ghost.zh"
import "ffcscript.zh"

const int SWIM_LEFT_COMBO = 84;
const int SWIM_RIGHT_COMBO = 84;
const int SWIM_COMBO_CSET = 8;
const int OUT_OF_WATER_JUMP = 3; // How high Link jumps when leaving the water. 3 is the standard Roc's Feather height.

// Checks for Combo Flag 102, "General Use 5 (Scripts)" and draws swimming tiles if Link is on top of it.
global script slot2
{
	void run()
	{
		while (true)
		{
			if ((Screen->ComboF[ComboAt(Link->X + 8, Link->Y + 15)] == CF_SCRIPT5 || Screen->ComboI[ComboAt(Link->X + 8, Link->Y + 15)] == CF_SCRIPT5) && Link->Action != LA_SCROLLING)
			{
				Link->Invisible = true;
				if (Link->Dir == DIR_UP || Link->Dir == DIR_LEFT)
				{
					Screen->FastCombo(4, Link->X, Link->Y, SWIM_LEFT_COMBO, SWIM_COMBO_CSET, OP_OPAQUE);
				}
				else
				{
					Screen->FastCombo(4, Link->X, Link->Y, SWIM_RIGHT_COMBO, SWIM_COMBO_CSET, OP_OPAQUE);
				}
			}
			else
			{
				Link->Invisible = false;
			}
			
			Waitframe();
		}
	}
}

// This version of the swimming script is meant to run in rooms with Sideview Gravity turned on.
// Put Combo Flag 102, "General Use 5 (Scripts)", on any combo you want to designate as water. Inherent or placed, it doesn't matter.
ffc script Swimming
{
	void run()
	{
		this->Vy = 0;
		float accel = 0.16;
		float holddown = 0;
		float jump = 0; // This variable makes Link sink a little faster after hitting the water.
		float max_sink = 0.5;
		bool underwater = false;
		int timerJump = 0;
		
		// A little upward velocity at the bottom of the screen to start, so you don't get scrolled off immediately.
		if (Link->Y > 156)
		{
			if ((Screen->Flags[SF_ROOMTYPE] & 100b) != 0)
			{
				Link->Jump = 2; // Change this to a higher number if you think it's still too little time before sinking off the bottom of the screen.
				Waitframes(10);
			}
			else
			{
				this->Vy = -2.0;
			}
		}
		
		this->X = Link->X;
		this->Y = Link->Y;
		
		// Checks for underwater status on new screen, so water-to-water screen transitions avoid surface jump mechanics.
		if (Screen->ComboF[ComboAt(Link->X + 8, Link->Y + 8)] == CF_SCRIPT5 || Screen->ComboI[ComboAt(Link->X + 8, Link->Y + 8)] == CF_SCRIPT5)
		{
			underwater = true;
		}
		
		while (true)
		{
			if (!underwater && (Screen->ComboF[ComboAt(Link->X + 8, Link->Y + 8)] == CF_SCRIPT5 || Screen->ComboI[ComboAt(Link->X + 8, Link->Y + 8)] == CF_SCRIPT5))
			{
				underwater = true;
				jump = 0.3;
				timerJump = 20;
			}
			if (underwater)
			{
				// Screen->Wavy = 5;
				holddown = 0;
				if (timerJump <= 0)
				{
					jump = 0;
				}
				this->X = Link->X;
				Link->Y = this->Y;
				
				if (Link->InputDown)
				{
					holddown = 0.16;
				}
				if (timerJump > 0)
				{
					jump = 0.3;
				}
				if (holddown > 0)
				{
					max_sink = 1.2;
				}
				else
				{
					max_sink = 0.8;
				}
				
				this->Vy = Min(max_sink, this->Vy + accel + holddown + jump);
				if (Screen->isSolid(Link->X + 1, Link->Y + 16) || Screen->isSolid(Link->X + 15, Link->Y + 16))
				{
					if (this->Vy > 0)
					{
						this->Vy = 0;
					}
				}
				
				if (Link->PressA)
				{
					Game->PlaySound(SFX_SPLASH);
					this->Vy = -1.8;
					if (Link->InputUp)
					{
						this->Vy = -2.5;
					}
				}
				
				if (Screen->isSolid(Link->X + 1, Link->Y) || Screen->isSolid(Link->X + 15, Link->Y))
				{
					if (this->Vy < 0)
					{
						this->Vy = 0;
					}
				}
				
				Link->InputA = false;
				// Link->InputB = false; // Commenting this out to allow B button item use for water jet item. Use DMap item restrictions instead?
				Link->InputUp = false;
				Link->InputDown = false;
				
				timerJump--;
			}
			
			if (underwater && !(Screen->ComboF[ComboAt(Link->X + 8, Link->Y + 15)] == CF_SCRIPT5 || Screen->ComboI[ComboAt(Link->X + 8, Link->Y + 15)] == CF_SCRIPT5))
			{
				if (timerJump <= 0)
				{
					Link->Jump = OUT_OF_WATER_JUMP;
					Game->PlaySound(SFX_JUMP);
				}
				underwater = false;
			}
			if (!underwater)
			{
				this->X = Link->X;
				this->Y = Link->Y;
				this->Vx = 0;
				this->Vy = 0;
			}
			
			Waitframe();
		}
	}
}

// Activates secrets permanently when stepped on. Meant for sideview swimming sections. Shifts to next combo in list, so set FFC properties to run this at screen init.
ffc script SideviewButton
{
	void run()
	{
		if (Screen->State[ST_SECRET])
		{
			this->Data++;
		}
		
		while (true)
		{
			if (Abs(Link->X - this->X) < 4 && Abs(Link->Y - this->Y) < 3)
			{
				this->Data++;
				Screen->TriggerSecrets();
				Game->PlaySound(SFX_SECRET);
				Screen->State[ST_SECRET] = true;
				Quit();
			}
			
			Waitframe();
		}
	}
}

I finally got this working, though I can't guarantee it doesn't have bugs. Transitioning out of the water only works upward, so no gravity defying water for you. I can't find info on how Link is drawn during screen scrolling, and I'm too lazy to work it out myself right now. I also included a simple secret activating button script, since traditional triggers don't work so well with these new mechanics.



#14 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 02 September 2014 - 03:37 PM

It was interesting the comment about to use FFC for this script. If it was a global script, the problem with the screen scrolling would be more easily solved or makes no difference?
Anyway, the new update made the script much better :)



#15 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 02 September 2014 - 05:40 PM

The part that draws swimming combos is already global. The big issue with screen transitions is that Link isn't really where he appears to be while the screen is scrolling. If you draw a combo on top of him, it won't show up where you want it to. The Link seen during screen scrolling isn't the real Link, but is in fact just a drawn object as well. This behavior is handled internally by ZC, and the source code hasn't been released so I'd have to reverse engineer it by looking at what happens on screen. Not super hard, but still tedious.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users