YolkfolkThe Dizzy Fansite
Community discussion

Climbing up and down

Started by Grandad on 23 November 2009 • 29,066 views

54 posts
#54585
I've just been playing the Amiga version of Crystal Kingdom Dizzy and enjoyed the way that Dizzy could climb up and down masts on the pirate ship. I've noticed that Colin has done something similar in SummerBlast with the ivy by the museum, but when I had a sneaky peek, all I could see was two action blocks and some scripting that went way over my head as there didn't seem to be any reference to movement control by the player.

Visually, climbing seems much more satisfying than the regular 'jumping up on climb material' (especially as you can't climb down). Is this a really advanced bit of coding or can any old Tom, Dick or Grandad do it fairly easily?

Grandad
  {yolkfolk}:scratch:
👍 0
#67238
Check out P_CUSTOMMOVE and the chapter called 'player' in the manual. This allows you to use a custom move routine or the default one just by changing a value.

The custom movement scripts are in 'movement.gs'. Replace the jumping up code with your own script that moves the player up or down by altering the 'P_Y' property.

When the player collides with the climbing material change from default movement to custom movement.

This is how I would do it anyway.
👍 0
#67239
i'll have a look at how colin has done it tomorrow, and try to post an easy guide to doing it - if i can work it out! :tongue:
👍 0
#67241
^ surprised you haven't tried doing this before.
👍 0
#67244
[quote data-userid="23" data-postid="67239"]

i’ll have a look at how colin has done it tomorrow, and try to post an easy guide to doing it – if i can work it out! :tongue:

[/quote]

If you can and its not too complicated & I can follow it then it would be good to beable to add to Feverbound as is quite a bit of climbing but you have to jump.

👍 0
#67245
ummm colin's coding is quite complex, i think because it also incorporates the character switching code too.

Basically if i were to do it myself, i'd therefore write my own code. However I have no plans to do it myself, so unless my brain comes up with an easy way to do it, I can't help, sorry!

Maybe Colin would be able to explain it, but i suspect that it is pretty complicated. I've had a bit of a think how i'd do it, and it really isn't a 10 minute job. In fact i suspect it would take me about 2 or 3 hours to completely work out and get working properly.
👍 0
#67246
Thats ok, I expected it would be complex which means no way I could implement it. I would as always need an example and some explanation, perhaps Colin may if it isnt too difficult. It would fit neatly to Feverbound though but its a nice to have to make it more polished & playable rather than a real requirement, will just have to jump to climb {yolkfolk}:meh:
👍 0
#67247

Yes the code was quite complex. I Also know it wasn't really the best way, I expect, to actually do it.

I have sent Grandad a modified version of his game, with the climbing added so he can play about with it. I stripped the multi switching code out as well.
here is the code I added and i'll try to explain how it works
First I had to add the 2 tiles that show daisy turning and climbing.

on the map there are 2 new action object blocks. they are ID:-
8900 bottom of ivy
8901 top of ivy

there are 2 new daisy objects, pasted outside the play area
2002 daisy turning
2020 daisy climbing (animation needs to be stopped)

the action objects 8900-8901

1st they set the x and y coords for the object that will replace the player
next it enters a scripted state, stopping key control of the player
then replaces the player with the turning object 2002
it makes sure the tile animation is set at the 1st frame of the animation
and it slows the animation down with a delay
it show the animation for 12 game frames, then replaces the turn object 2002, with the climb object 2020
it then activates the climb control by setting the status of the bottom of ivy action 8900 to 1

//top bottom action
func ActionObject_8900()  
{
	idx = ObjFind(8900);
	if(ObjGet(idx,O_STATUS)==0)
	{
	chrx = ObjFind(2002);
	x = 3008;                                 //you need to set this at climb location
	y = PlayerGet(P_Y);			
	PlayerSet(P_STATUS,STATUS_SCRIPTED);
	PlayerSet(P_DISABLE,1);
	ObjSet(chrx,O_X,x);
	ObjSet(chrx,O_Y,y-14);
	ObjSet(chrx,O_DISABLE,0);
	ObjSet(chrx,O_FRAME,0);
	ObjPresent(chrx);
	ObjSet(chrx,O_DELAY,6);
	WaitFrames(12);
	ObjSet(chrx,O_DISABLE,1);
	chrx = ObjFind(2020);
	ObjSet(chrx,O_X,x);
	y-=2;
	ObjSet(chrx,O_Y,y-14);
	ObjSet(chrx,O_DISABLE,0);
	ObjSet(chrx,O_FRAME,0);
	ObjPresent(chrx);
	f=0;
	idx = ObjFind(8900);	
	ObjSet(idx,O_STATUS,1);	
	}
}

//top ivy action
func ActionObject_8901()
{
	chrx = ObjFind(2002);
	x = 3008;                             //you need to set x as climb location
	y = 258;                              //you need to set y<>8 pixels lower to drop down
	PlayerSet(P_STATUS,STATUS_SCRIPTED);
	PlayerSet(P_DISABLE,1);
	ObjSet(chrx,O_X,x);
	ObjSet(chrx,O_Y,y-14);
	ObjSet(chrx,O_DISABLE,0);
	ObjSet(chrx,O_FRAME,0);
	ObjPresent(chrx);
	ObjSet(chrx,O_DELAY,6);
	WaitFrames(12);
	ObjSet(chrx,O_DISABLE,1);
	chrx = ObjFind(2020);
	ObjSet(chrx,O_X,x);
	ObjSet(chrx,O_Y,y-14);
	ObjSet(chrx,O_DISABLE,0);
	ObjSet(chrx,O_FRAME,0);
	ObjPresent(chrx);
	f=0;
	idx = ObjFind(8900);	
	ObjSet(idx,O_STATUS,1);	
}

Room Updates

there are 3 room updates here, as you will climb through 3 rooms
they all check if the bottom of ivy action 8900 status is set at 1.
if it is, then it calls the ivy1 function, which is the movement control.
else it reenables the player

func UpdateRoom_12_3()
{
	idx = ObjFind(8900);
	if(ObjGet(idx,O_STATUS)==1)
	{
		Ivy1();
		ClearKeys();
	}
	idx = ObjFind(8900);
	if(ObjGet(idx,O_STATUS)==2)
	{
		PlayerSet(P_DIR, 0);
		PlayerSet(P_POW, 0);
		idx = ObjFind(8900);	
		ObjSet(idx,O_STATUS,0);
	}
}
func UpdateRoom_12_2()
{
	idx = ObjFind(8900);
	if(ObjGet(idx,O_STATUS)==1)
	{
		Ivy1();
		ClearKeys();
	}
	idx = ObjFind(8900);
	if(ObjGet(idx,O_STATUS)==2)
	{
		PlayerSet(P_DIR, 0);
		PlayerSet(P_POW, 0);
		idx = ObjFind(8900);	
		ObjSet(idx,O_STATUS,0);
	}
}
func UpdateRoom_12_1()
{
	idx = ObjFind(8900);
	if(ObjGet(idx,O_STATUS)==1)
	{
		Ivy1();
		ClearKeys();
	}
	idx = ObjFind(8900);
	if(ObjGet(idx,O_STATUS)==2)
	{
		PlayerSet(P_DIR, 0);
		PlayerSet(P_POW, 0);
		idx = ObjFind(8900);	
		ObjSet(idx,O_STATUS,0);
	}
}

Movement Control

This handles player input. for when the player presses cursor up, it will first check which frame of the animation is currently being shown on variable f and it's y coordinate. it then reduces both numbers by 1 (on the down key it adds 1 to them). So basically it is running the animation in reverse. the next few lines of code checks if has f has gone below 0. As this would cause an error it resets it to 8 (the animation has 8 frames).
it now checks if has reached the top of the climb (in this the top is set when y goes below 248). If it has then it removes the climb tile, resets the key checker and re-places the player into position. The last part will check if you are moving out of screen. If you didn't check, as you continue the climb he would walk off screen but you wouldn't follow. this code checks if you cross the coordinate it moves the player (that is hidden) into the new room.

func Ivy1()
{
//up
	if(GetKey(KEY_UP)==1) 
	{ 
	ClearKeys();
	chrx = ObjFind(2020);
	f = ObjGet(chrx,O_FRAME);
	y = ObjGet(chrx,O_Y);
	y-=1;
	f-=1;
	if(f<0)
	{
	f=8;
	}			
	if(y<248)                //this is the top point where he/she steps off
	{
	idx = ObjFind(8900);	
	ObjSet(idx,O_STATUS,2);	
	PlayerSet(P_X,3016);
	PlayerSet(P_Y,240);
	ClearKeys();
	PlayerSet(P_DIR, 0);
	PlayerSet(P_POW, 0);
	PlayerSet(P_DISABLE,0);
	PlayerEnterIdle();
	chrx = ObjFind(2020);
	ObjSet(chrx,O_DISABLE,1);
	}
	chrx = ObjFind(2020);
	ObjSet(chrx,O_FRAME,f);
	ObjSet(chrx,O_Y,y);
	if(y==400)
	{
	PlayerSet(P_Y,380);
	}
	if(y==264)
	{
	PlayerSet(P_Y,250);
	}
	}

//down

	if(GetKey(KEY_DOWN)==1)
	{
	ClearKeys();
	chrx = ObjFind(2020);
	f = ObjGet(chrx,O_FRAME);
	y = ObjGet(chrx,O_Y);
	y+=1;
	f+=1;
	if(f>8)
	{
	f=0;
	}
	if(y==488)                       //lowest point to get off
	{
	idx = ObjFind(8900);	
	ObjSet(idx,O_STATUS,2);	
	PlayerSet(P_X,3016);
	PlayerSet(P_Y,y+14);
	ClearKeys();
	PlayerSet(P_DIR, 0);
	PlayerSet(P_POW, 0);
	PlayerSet(P_DISABLE,0);
	PlayerEnterIdle();
	chrx = ObjFind(2020);
	ObjSet(chrx,O_DISABLE,1);
	}
	chrx = ObjFind(2020);
	ObjSet(chrx,O_FRAME,f);
	ObjSet(chrx,O_Y,y);
	if(y==538)
	{
	PlayerSet(P_Y,500);
	}
	if(y==401)
	{
	PlayerSet(P_Y,480);
	}
	if(y==265)
	{
	PlayerSet(P_Y,380);
	}
	}
}
👍 0
#67248
i find it very difficult to give up on something...

so i'm currently working on my own code :tongue:

I've currently got him to go into the 'climb' mode, and moving up and down, however I still need to change the collision detection for 'block' brushes, and implement my own. {yolkfolk}:dizzy:

I'll post the code once I've got it fully working.

EDIT:: Bah, getting bogged down with this collision detection coding :sad:

EDIT 2:: sorry, but i give up for tonight. The movement code again baffles me with it's unwillingness to do stuff.
👍 0
#67249
Seeing as you guys enjoy a challenge - heres one for the mix:

Can you get Dizzy to do near misses onto ledges, but hang on by his gloves and pull himself up - like in Prince of Persia?
👍 0
#67250
oh you have got to be joking...!
👍 0
#67253

Right, I've created a small example of how I would do it using custom movement which I still think is the best way.

I have drawn a single room which has a rope hanging from the ceiling. If Dizzy stands under or jumps onto the rope he can climb up or down. Dizzy can leave the rope by moving left or right. What I have not done is change dizzys graphic into a climbing one. I didn't want to over complicate the code at this point as I have written this to show how the climbing routine works. Once a user has it working then they can think about adding code to change Dizzy's costume.

To use it create a room and put in your climbing medium (rope, tree etc). Over (or under in my example) the climbing medium place a blank brush that is dynamic, material climb (to stop the effects of gravity), material map only and an ID (1001 for this example).

It works by using collision detection to see if Dizzy is over the blank climbing material. If he is then custom movement is switched on. When Dizzy leaves the brush then custom movement is turned off. Whilst custom movement is on the jump routine is not called. Instead Dizzy moves up by 4 pixels (can be made greater or smaller). Same for the down key, Dizzy moves down. All other movement is unchanged.

Enter the code below.

in game.gs at the bottom.

func CollideObject_1001_1() // moved into collision with rope
{
	PlayerSet(P_CUSTOMMOVE,1);
	PlayerEnterIdle();
}

func CollideObject_1001_0() // moved off collision with rope
{
	PlayerSet(P_CUSTOMMOVE,0);
}

In handlers.gs find 'func HandlerPlayerUpdate()' and add the following line before the final curly bracket.

if (PlayerGet(P_CUSTOMMOVE) == 1) CM_Update();

In movement.gs find 'func CM_EnterKeyState()'. Remove the whole function and relace it with the amended one below.

func CM_EnterKeyState()
{
	if( PlayerGet(P_LIFE)<=0 ) { CM_EnterIdle(); return; } // prepare to die

	dir = 0;
	if( GetKey(KEY_RIGHT) )	dir++;
	if( GetKey(KEY_LEFT) )	dir--;
	if( GetKey(KEY_JUMP) )		
	{
		PlayerSet(P_Y,PlayerGet(P_Y) -4); // speed of climb
		// call jump handler to determine the power of the jump
		ScrSetHandlerData(0,-1); // send no material
		ScrSetHandlerData(1,0);  // clean return for safety
	}
	else if( GetKey(KEY_DOWN) )		
	{
		PlayerSet(P_Y,PlayerGet(P_Y) +4); // speed of climb
		// call jump handler to determine the power of the jump
		ScrSetHandlerData(0,-1); // send no material
		ScrSetHandlerData(1,0);  // clean return for safety
	}
	else
	if(dir!=0)
	{
		CM_EnterWalk(dir);
	}
	else 
	{
		CM_EnterIdle();
	}
}

And thats all there is to it.

I recommend downloading my example to give you a better indication of how it works.

Download here.

Remember, this is just a rough example to show how to do it. It is not the final polished thing. Treat it as a starting point.

👍 0
#67268
The guy who wrote 'Spud's Quest' (fan game on this site) does that with Dizzy too ..but unfortunately it's not written with DizzyAge.

Grandad
👍 0
#67270
Had a play about with the code Colin kindly posted & I sort of got it working but some of the latter parts of the code with the numbers I wasnt sure with and Dizzy was reappearing in funny positions lol.

Got Dizzy to turn, to climb, although he just went up but no real climb animation which he does when he comes down, dunno if that correct or not. He sort of just glided up.

Anyway took me ages and ages to do just for one and I have lots of 'climb' brushes in Feverbound so its far too impractical without a much simpler code. The code list be hundred miles long lol & would take me eons.

Prob too soon to ask but how you getting on Jamie with tackling this.
👍 0
#67274
[quote data-userid="50" data-postid="67270"]

Had a play about with the code Colin kindly posted & I sort of got it working but some of the latter parts of the code with the numbers I wasnt sure with and Dizzy was reappearing in funny positions lol.

Got Dizzy to turn, to climb, although he just went up but no real climb animation which he does when he comes down, dunno if that correct or not. He sort of just glided up.

Anyway took me ages and ages to do just for one and I have lots of ‘climb’ brushes in Feverbound so its far too impractical without a much simpler code. The code list be hundred miles long lol & would take me eons.

Prob too soon to ask but how you getting on Jamie with tackling this.

[/quote]

LOL! why do you think my game script was so massive!

👍 0
#67275
[quote data-userid="150" data-postid="67249"]

Seeing as you guys enjoy a challenge – heres one for the mix:

Can you get Dizzy to do near misses onto ledges, but hang on by his gloves and pull himself up – like in Prince of Persia?

[/quote]

I thought i'd have a little go!

sort of works

ledge-hang-test.zip

up key to climb up and left key to fall back off!
👍 0
#67276
[quote data-userid="50" data-postid="67270"]

Prob too soon to ask but how you getting on Jamie with tackling this.

[/quote]

I haven't had chance to try again since the other day, as I also did the Ice Slide coding too. The problem is that the climb coding is rather more complicated...

I may have another bash at it tomorrow sometime if i get the time.
👍 0
#67277
OMG - Colin that is so cool

That is the sort of thing I never thought Id see - wow!!!

fyi, it only seems to work when I jump right onto the top ledge
When I jump left near the bottom ledge I cant seem to get it to work - but thats only minor detail - Great demo!!!


Now before someone creates the full game:
"Dizzy - Prince (of the Yolkfolk) of Persia"

I wonder if you can do this?:

Can Dizzy skid?

Like just after he comes off the ice - he travels a fraction longer before stopping - or a bit like in Sonic the Hedgehog - when you want him to turn around, he kinda over travels in the direction he was originally moving before skidding, stopping and turning back?
👍 0
#67316
Wow, that last chance grab is pretty cool stuff! I mean, seriously, that's really really great! Along with the skid example, you could create a pretty nifty fast-paced platformer... Maybe he could speed up to running (also like sonic), starting out at a little wobble, looking at the ground and gradually building up to full speed, his little gloves really pumping and his chest puffed out (in an eggy, rotund kinda way)? I'm not suggesting that somebody should try and code this and draw all the animations, I'm simply saying it would look pretty cool. And then when you flip the joystick the other way he skids along. Kind of like Mayhem in Monsterland on the C64 :teethy:
👍 0
#67317
Perhaps a Dizzy Olympics will the be next spin off.
👍 0