YolkfolkThe Dizzy Fansite 1 logged in0 playing
Community discussion

My brilliant coding

Started by AndyG on 27 June 2014 • 11,541 views

24 posts
#55376

Now, I'm keenly aware that I'm missing the boat by several years here and that people who still use DizzyAGE / post here are all way better than me. But I'd still like to show off :smile: . And who knows, maybe some newcomers can use this stuff. The vets can tell me how rubbish and long-winded it is, but it does work {yolkfolk}:tongue:

MY BRILLIANT FALLING APPLE
(I set an animated crumbling apple in the screen above, as dynamic, id = 4060, anim = stop, collider = call handler, class = hurt. I set two colliders and two reset colliders, 4061 and 4062.)

func CollideObject_4061_1( idx )	//APPLE COLLIDER
{
idx = ObjFind(4060);
if(ObjGet(idx,O_STATUS)==0)         //NOT FALLING
{
ObjSet(idx,O_STATUS,1);              //FALLING
}
}

func CollideObject_4062_1( idx )	//APPLE RESET COLLIDER
{
idx = ObjFind(4060);
if(ObjGet(idx,O_STATUS)==2)        //FALLEN
{
ObjSet(idx,O_ANIM,0);                 //STATIC
ObjSet(idx,O_CLASS,2);               //HURT
ObjSet(idx,O_STATUS,0);             //NOT FALLEN
ObjSet(idx,O_Y,790);                  //SET Y TO ORIGINAL POSITION
ObjSet(idx,O_FRAME,0);              //FIRST ANIMATION FRAME
}
}

then:

func UpdateRoom_23_6()
{
idx = ObjFind(4060);
if(ObjGet(idx,O_STATUS)==1)              //FALLING
{
y = ObjGet(idx,O_Y);                          
y+=3;                                             //INCREMENT Y
if(y>913)                                        //HIT THE FLOOR
{ 
y=913;
ObjSet(idx,O_ANIM,1);                      //PLAY ANIMATION
ObjSet(idx,O_CLASS,0);                    //DON'T HURT
ObjSet(idx,O_STATUS,2);                  //FALLEN
}
ObjSet(idx,O_Y,y);
ObjPresent(idx);
}
}

func UpdateRoom_23_5()
{
idx = ObjFind(4060);
if(ObjGet(idx,O_STATUS)==1)
{
y = ObjGet(idx,O_Y);
y+=3;
if(y>913)
{ 
y=913;
ObjSet(idx,O_ANIM,1);
ObjSet(idx,O_CLASS,0);
ObjSet(idx,O_STATUS,2);
}
ObjSet(idx,O_Y,y);
ObjPresent(idx);
}
}

MY BRILLIANT CROCODILE
(The default 2-frame tile from FWD, set as dynamic, id = 4065, delay = 7, anim = stop, collider = hard collision, class = none. He is on layer 7, with an invisible block lower down so you don't keep falling if he munches you!)

func UpdateRoom_25_6()		//CROC
{

idx=ObjFind(4065);
ObjSet(idx,O_STATUS,ObjGet(idx,O_STATUS)+1);           //STATUS INCREMENT
if(ObjGet(idx,O_STATUS)==50)                                    //AT 50..
{
ObjSet(idx,B_ANIM,2);                                               //..REPEAT ANIMATION
ObjSet(idx,O_CLASS,3);                                             //KILL!
ObjSet(idx,O_COLLIDER,1);                                         //YES, DO KILL(?)
}
if(ObjGet(idx,O_STATUS)==150)                                  //AT 150..
{
ObjSet(idx,B_ANIM,0);                                               //STATIC
ObjSet(idx,B_FRAME,0);                                             //FIRST FRAME
ObjSet(idx,O_CLASS,0);                                            //DON'T HURT
ObjSet(idx,O_COLLIDER,2);                                        //BLOCK
ObjSet(idx,O_STATUS,0);                                           //RESET
}
}
👍 0
#81374
Or you can just unpack TUCA and copy and past the falling apple code from that :wink:

What does the Croc do?

If it works for you than that's the most important part.
👍 0
#81375
Well done Andy! Isn't it such a wonderful feeling when you've struggled and struggled with coding and then something clicks and it all finally works? I can relate to this not coming easily - I've made two DizzyAGE games and both were epic missions for me. I asked for help A LOT and I copied and pasted bits and pieces of code from several other people's scripts. To write your own bit of code to get something working the way you want it to is a real achievement :yes:

Now, just imagine how great you'll feel when you've finished writing a whole game!
👍 0
#81376
Thanks a lot :smile: it's definitely a good feeling! A few times, what I've tried to do was right but I forgot to save either the map or the script, so I was altering things that didn't need altering. I'll be very happy when it's complete, but I'm not rushing!

I tried looking at the remakes and they're all password protected :sad: . (I also wanted to see how the Treasure Island scrolls were done, because I think that's a nice touch). My croc is the snap happy gator from Fantasy World Dizzy - you have to wait for him to stop snapping and quickly jump on him :smile:
👍 0
#81377
I think the croc is spot on, so well done. But I'm curious as to why you call it a brush in the animation switching rather than an object.
👍 0
#81378

Thank you very much :smile: I was happy it worked! The object / brush mix-up was just the result of my trial and error, haha. At first they were all brushes (B_CLASS etc) but for some reason that didn't work. Then they were all objects. This is what ended up working. I guess I still don't fully understand the difference. BTW, if somebody could maybe PM me or something with the password for unpacking the remakes, that would be great!

Also, here is
MY BRILLIANT EAT-THE-CAKE-TO-REVEAL-A-NAIL-FILE PUZZLE
(With help from this forum!)

func DropObject_1001()                   //WHEN CAKE IS DROPPED
{
	item = ObjFind(1001);
	Message0(0,0,"YOU FIND THE CAKE TOOnTEMPTING TO DROPnAND SO EAT IT!");
	MessagePop();

	PlayerEmotion(9);                             //EATING ANIMATION
	WaitFrames(40);
	PlayerEmotion(0);                             //DEFAULT
	Message0(0,0, "OH?  WHAT'S THIS?");
	MessagePop();

	DoDropObject(item);
	ObjSet(item,O_DISABLE,1);                //DROP THE EATEN CAKE AND DISABLE IT
	
	idx = ObjFind(1003);	                    //ADD THE FILE TO THE INVENTORY 
	InventoryAdd(idx);                           //AND DROP IT (IT WAS PREVIOUSLY
	DoDropObject(idx);                          //PLACED IN AN INACCESSIBLE SCREEN)
}

BTW again: Has anyone else noticed that the default "eating" animation looks warped? I think I'll redo it at some point.

👍 0
#81379

Well done with the coding Andy! Particularly for the timing with the crocodile. Using increments like that ( ObjSet(idx,O_STATUS,ObjGet(idx,O_STATUS) + 1) etc.) was something I didn't work out for ages. It's a really useful technique too.

One little tip though. You'd be better off defining your own variable for the counter and using that. If you look in the USER tab in the editor, there's a list of object properties without names, just numbers: #32, #33, etc.

You can define these yourself and use them in your code. #32 and #33 are already used in the AI but the others are free.

You can add a define like this:

#def O_COUNTER 34

You only need to do this once. You can put it anywhere, but the def.gs file is where you're "meant" to put it.

After that you can use it in your code as you want. So your crocodile code would become:

func UpdateRoom_25_6()		//CROC
{

idx=ObjFind(4065);
ObjSet(idx,O_COUNTER,ObjGet(idx,O_COUNTER)+1);           //STATUS INCREMENT
if(ObjGet(idx,O_COUNTER)==50)                                    //AT 50..
{
ObjSet(idx,B_ANIM,2);                                               //..REPEAT ANIMATION
ObjSet(idx,O_CLASS,3);                                             //KILL!
ObjSet(idx,O_COLLIDER,1);                                         //YES, DO KILL(?)
}
if(ObjGet(idx,O_COUNTER)==150)                                  //AT 150..
{
ObjSet(idx,B_ANIM,0);                                               //STATIC
ObjSet(idx,B_FRAME,0);                                             //FIRST FRAME
ObjSet(idx,O_CLASS,0);                                            //DON'T HURT
ObjSet(idx,O_COLLIDER,2);                                        //BLOCK
ObjSet(idx,O_COUNTER,0);                                           //RESET
}
}

The advantage is that in a different puzzle, you might need O_STATUS to turn the object's motion on and off.

There are also player and game properties you can define and use too, but I'll leave that for you to work out. :smile:

👍 0
#81380
Thanks Noggin! To be honest, this was the plan. I was thinking something like O_USER_30 or whatever, and I was gonna look into it. STATUS was just to test my idea out, and I didn't think it would accept such high numbers. I was surprised when it worked, and then I saw no need to change it. But next time, I'll definitely do it your way :smile:

PS I do think I got lucky with the timing! 50 and 150 were the first numbers I tried and they seem perfect! He snaps 7 times then waits for about 3 seconds :smile:
👍 0
#81406
[quote data-userid="1205" data-postid="81376"]

I tried looking at the remakes and they’re all password protected :sad:  .

[/quote]

I've got unpaked versions of Peter's Magicland and Prince of the Yolkfolk remakes if you haven't managed to find them yet Andy?

👍 0
#81407
Please, that would be great! Magicland in particular, because I want to learn how to code the harpy :smile: . My email address is andy.goulding85[at]hotmail.co.uk, if this is easiest
👍 0
#81410
Done! :lol:

Also, Grandad made a game a few years ago called "Back to Magicland". I'm not sure whether the Harpy was doing what you wanted it do be doing (or if it was even there!) but you should check it out, there might be some useful code in there :smile:

https://www.yolkfolk.com/site/games.php?game_id=223%23
👍 0
#81416

I always thought it was a vampire called Velda who was supposed to be Zaks' mum.

The trick of this puzzle is to only activate the 'harpy' if Dizzy entered the room without having the cross in his inventory. Use an OpenRoom function with an if command to set the status to '0' if the cross is in the inventory and to '1' otherwise.

func OpenRoom_10_10()
{
if (InventoryHasItem(100))
{
ObjSet(ObjFind(1000), O_STATUS, 0);
return;
}
else
{
ObjSet(ObjFind(1000), O_STATUS, 1);
}
}

Then use a CloseRoom function to set the 'harpy' back to it's original position and set the status to '0'. As it's a repeating function you also need to reset the target object.

func CloseRoom_10_10()
{
ObjSet(ObjFind(1000), O_STATUS, 0);
ObjSet(ObjFind(1000), O_X, 2344);
ObjSet(ObjFind(1000), O_TARGET, 1001);
}

Then use an UpdateRoom function to start the movement if Dizzy isn't holding the cross.

func UpdateRoom_10_10()
{
idx = ObjFind(1000);
AIUpdateTrain(idx);
ObjPresent();
}

I didn't use a disable command as the harpy was set behind the tower wall and had a lower layer number than the wall.

👍 0
#81417
The Vampire in Magicland was Zaks mother or grandmother.
The Harpy sat on a cloud above the volcano and didn't do anything.
👍 0
#81419

I thought the Harpy (sat on the cloud above the volcano) moved to kill the player after a certain time spent in the room? Maybe it's just my bad memory (he certainly doesn't move in the DizzyAGE remake). Anyway, this is what I'd like to do. In my game, it will only do this if you don't have a certain item, so thanks Grandad, this will help. Especially the OpenRoom function, because I always use colliders, which can mean potentially 4 unnecessary objects!

It's the targeting the player that I thought would be a challenge when the time comes (and I have plenty to keep me occupied before I start). I was thinking something along the lines of:

func OpenRoom_10_10()
{
WaitFrames(500);
idx = ObjFind(1000);
if (ObjGet(idx,O_STATUS)==1)
         {
          ObjSet(idx, O_DISABLE, 0);
          if (ObjGet(idx,O_Y)> PlayerGet(P_Y)
                 {
                  ObjSet(idx,O_Y)-1;
                 }
          }
}

And so on, to update X and Y, + or -. This is just my first idea of how I might approach setting the player as the target. WaitFrames likely won't work, in which case I'll use a property increment (when O_USER_10 = 1000, or whatever ends up working). As I say, I won't start on this for a while, so it's not a cry for help, just sharing my baby ideas! {eggs2}:denzil:

👍 0
#81487
Hi Andy,

How's the game going? Have you worked out how to do the harpy yet? :smile:
👍 0
#81488
[quote data-userid="642" data-postid="81487"]

Hi Andy,

How’s the game going? Have you worked out how to do the harpy yet? :smile:

[/quote]

Hey Noggin, thanks for your interest! Nice to know people care :smile: . It's just on hold for the moment as I recently found a call centre job, which means I'm spending lots of time learning about finance... I'm not a good multi-tasker and pensions are really hard haha. I would say the game is about halfway complete, I'm really proud of what I have so far and I hope to have a finished game by the end of the year. It's loosely themed around Monopoly.

Not tried to make my harpy yet but it's next on my list and I'll put it here when (hopefully) I suss him out! Strangely enough, the last thing I coded was Olaf from the Lost Vikings, inspired by your avatar :smile:
👍 0
#81529

Hi everyone! I just returned to my game after about a month and I'm happy to say I hadn't forgotten everything as I'd feared :teethy: . In fact I finally worked out..

MY BRILLIANT HARPY

This is the harpy from MLD, who I'm sure moved to kill the player after a small time in a room with clouds. I could be wrong. Anyway, my harpy is called "The Fear"; he lives in the sky and will move to kill the player after maybe 5 seconds of trying to negotiate the clouds, unless you have taken some Xanax!

I think this will be useful for anyone looking to set the player as a target. He chases you quite quickly and kills you on contact.
So: my Harpy is set to 8500, dynamic, kill, call handler. (I also set one of the USER properties to COUNTER, in the def file.) I didn't need to worry about respawning, since the screen is just clouds, so by default the player respawns at the last block (the previous screen). The Harpy is hidden behind a cloud before he moves, so I didn't need to enable him.

func UpdateRoom_9_5()
{
	idx = ObjFind(8500);
	ObjSet(idx,O_COUNTER,ObjGet(idx,O_COUNTER)+1);  //Start counter when player enters room
	if(ObjGet(idx,O_COUNTER)==220)              //220 is about 5 seconds!
	{
	ObjSet(idx,O_STATUS,1);
	ObjSet(idx,O_COUNTER,0);
	}
	if(ObjGet(idx,O_STATUS)==1)
	{
		y = ObjGet(idx,O_Y);
		x = ObjGet(idx,O_ X) ;
		py = PlayerGet(P_Y);
		px = PlayerGet(P_ X) ;

		if(y < py)          //If Harpy's Y coordinate is lower than yours..
		{
		y+=2;            //...Increase it!  2 seems a good speed.
		ObjSet(idx,O_Y,y);
		ObjPresent(idx);
		}

		if(y > py)         //...And so on!
		{
		y-=2;
		ObjSet(idx,O_Y,y);
		ObjPresent(idx);
		}	

		if(x < px)
		{
		x+=2;
		ObjSet(idx,O_X,x);
		ObjPresent(idx);
		}

		if(x > px)
		{
		x-=2;
		ObjSet(idx,O_X,x);
		ObjPresent(idx);	
		}	
	}	
}

func CloseRoom_9_5() //When you leave the room...
{
idx = ObjFind(8500);
ObjSet(idx,O_X,2164); //Harpy is reset!
ObjSet(idx,O_Y,775);
ObjSet(idx,O_STATUS,0);
ObjSet(idx,O_COUNTER,0);
}

func DropObject_1025() //Drop the medicine
{
	item = ObjFind(1025);
	Message0(0,0,"YOU NECKnTHE MEDICINE...");
	MessagePop();
	Message0(0,0,"YOU FEELnSTRANGELY FEARLESS!");
	MessagePop();
	InventorySub(item);
	ObjSet(ObjFind(8500),O_DISABLE,1); //Disable the Harpy
	BrushSet(BrushFind(8501),B_COLOR,0xffffffff); //Make the sky a nice colour!
}

I hope this is useful to someone! My game should be complete quite soon :teethy:

👍 0
#81531

Pretty impressive Andy. I can see one or two things you might change.

First of all, there's no need to put in all those separate ObjPresent commands, you can just put one at the bottom. The other thing to remember is that the player coordinates P_X, P_Y are at the centre of the player, the object coords are at the top left corner.

So you'd be better off doing:

py = PlayerGet(P_Y) - ObjGet(idx,O_H)/2;
px = PlayerGet(P_ X) - ObjGet(idx,O_W)/2;

That way the centre of the harpy should line up with the centre of Dizzy. Looking forward to the game! :smile:

👍 0
#81532
Thanks a lot Noggin! I've amended as you said. It doesn't make a world of difference as he's set to kill, but to be honest it WAS bugging me a little. Now it looks neater :teethy:
👍 0
#81567

I'm a genius! :teethy: I'd set two custom PlayerEnterScripted for when Dizzy is using a teleport machine or being electrocuted, which I was happy with. I only realised this week that it caused an error if I did these things with the scuba costume. So I had a few ideas for workarounds which would have been quite complicated before I thought: what if it's looking for a different tile ID? What if the scuba simply adds a number to the IDs the game looks for? After a bit of searching I found:

// Player set costume
	costume = 0;
	if(ID_SCUBA!=-1) costume = InventoryHasItem(ID_SCUBA) ? 30 : 0;
	PlayerSet(P_COSTUME,costume);

Could it really be as simple as adding 30 to the tile ID I'd set and saving it again? Turns out it is! I was delighted as I had been planning to make a costume for Dizzy to wear near the end of the game. Without really understanding it, I copied and edited

if(ID_FANCY!=-1) costume = InventoryHasItem(ID_FANCY) ? 390 : 0;
	PlayerSet(P_COSTUME,costume);

set the define and set new animations from 400 onwards. Simple!

Apologies if everyone is already aware of this. As it's my first game, I'm learning as I go and it's a great sense of achievement!

👍 0