YolkfolkThe Dizzy Fansite 1 logged in0 playing
Community discussion

Some questions about AI

Started by AndyG on 8 June 2014 • 3,932 views

9 posts
#55364
Hi all,

Well I've been muddling through with DizzyAGE for something like 3 weeks now, mostly by trial and error, and having a lot of fun. There are 2 things that I can't seem to be able to do, with regards AI.

1. How can I set the player as the target? Like with the Dizzyhawk? Specifically, I want to set up the Harpy from MLD, to be activated 5 seconds after entering a room, and move to kill the player. (I will also need to set the respawn at the previous screen, which I can't work out and I'm guessing involves a separate script.)

2. Flies. Can they be set to shake around or do they need waypoints? If they need waypoints, can they be set to target random ones?

Thanks for any help, and hopefully I'll have something good to show before the end of the year :smile:
👍 0
#81292
...I've just realised that for flies, probably the simplest thing to do is just set them all as one animation. And this is what I'll do. Is this what everyone else does? I imagine if they need to hurt you, it would be a different story.
👍 0
#81293

The respawn thing is pretty easy although I've drawn a blank and can't find the code I used at the moment. but it uses func PlayerRespawn

Random flies are simple enough.
I had this in the AI file

func AIRandomFly( idx,pixx,pixy )
{
	if(idx==-1) return;
	if(ObjGet(idx,O_DISABLE)) return;
	if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
	if(ObjGet(idx,O_STATUS)!=1) return;

	id2 = ObjGet(idx,O_TARGET);
	if(id2==0) return;
	idx2 = ObjFind(id2);
	if(idx2==-1) return;

	speed = ObjGet(idx2,O_WAYPOINTSPEED);
	targx = ObjGet(idx2,O_ X) ;
	targy = ObjGet(idx2,O_Y);
	
	flyx = ObjGet(idx,O_ X) ;
	flyy = ObjGet(idx,O_Y);
	
	if(flyy<=targy+pixy && flyy>=targy-pixy && flyx<=targx+pixx && flyx>=targx-pixx)
	{
		flyrand=gs_rand(4);
		if(flyrand==0) {flyy-=speed; if(flyy<targy-pixy) flyy=targy-pixy; }
		if(flyrand==1) {flyy+=speed; if(flyy>targy+pixy) flyy=targy+pixy; }
		if(flyrand==2) {flyx-=speed; if(flyx<targx-pixx) flyx=targx-pixx; }
		if(flyrand==3) {flyx+=speed; if(flyx>targx+pixx) flyx=targx+pixx; }
	}
	
	ObjSet(idx,O_X,flyx);
	ObjSet(idx,O_Y,flyy);
}
func AIUpdateFlyY( idx,pix )
{
	if(idx==-1) return;
	if(ObjGet(idx,O_DISABLE)) return;
	if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
	if(ObjGet(idx,O_STATUS)!=1) return;

	id2 = ObjGet(idx,O_TARGET);
	if(id2==0) return;
	idx2 = ObjFind(id2);
	if(idx2==-1) return;

	speed = ObjGet(idx2,O_WAYPOINTSPEED);
	flip = ObjGet(idx2,O_WAYPOINTFLIP);
	targx = ObjGet(idx2,O_ X) ;
	targy = ObjGet(idx2,O_Y);
	
	flyx = ObjGet(idx,O_ X) ;
	flyy = ObjGet(idx,O_Y);
	ObjSet(idx,O_FLIP,flip);
	
	if(flyy<targy) { flyy+=speed; if(flyy>targy) flyy=targy; }
	if(flyy>targy) { flyy-=speed; if(flyy<targy) flyy=targy; }

	if(flyx<=targx+pix && flyx>=targx-pix)
	{
		flyrand=gs_rand(2);
		if(flyrand==0) {flyx-=2; if(flyx<targx-pix) flyx=targx-pix; }
		if(flyrand==1) {flyx+=2; if(flyx>targx+pix) flyx=targx+pix; }
	}
	if(flyy==targy) // reached waypoint, change target
	{		
		target = ObjGet(idx2,O_TARGET);
		ObjSet(idx,O_TARGET,target);		
	}
	
	ObjSet(idx,O_X,flyx);
	ObjSet(idx,O_Y,flyy);
}
func AIUpdateFlyX( idx,pix )
{
	if(idx==-1) return;
	if(ObjGet(idx,O_DISABLE)) return;
	if(!IsUpdate(ObjGet(idx,O_DELAY))) return;
	if(ObjGet(idx,O_STATUS)!=1) return;

	id2 = ObjGet(idx,O_TARGET);
	if(id2==0) return;
	idx2 = ObjFind(id2);
	if(idx2==-1) return;

	speed = ObjGet(idx2,O_WAYPOINTSPEED);
	flip = ObjGet(idx2,O_WAYPOINTFLIP);
	targx = ObjGet(idx2,O_ X) ;
	targy = ObjGet(idx2,O_Y);
	
	flyx = ObjGet(idx,O_ X) ;
	flyy = ObjGet(idx,O_Y);
	ObjSet(idx,O_FLIP,flip);
	
	if(flyx<targx) { flyx+=speed; if(flyx>targx) flyx=targx; }
	if(flyx>targx) { flyx-=speed; if(flyx<targx) flyx=targx; }

	if(flyy<=targy+pix && flyy>=targy-pix)
	{
		flyrand=gs_rand(2);
		if(flyrand==0) {flyy-=2; if(flyy<targy-pix) flyy=targy-pix; }
		if(flyrand==1) {flyy+=2; if(flyy>targy+pix) flyy=targy+pix; }
	}
	if(flyx==targx) // reached waypoint, change target
	{		
		target = ObjGet(idx2,O_TARGET);
		ObjSet(idx,O_TARGET,target);		
	}
	
	ObjSet(idx,O_X,flyx);
	ObjSet(idx,O_Y,flyy);

Then update the room for the fly, obviously with the individual ID and you can change those coridinates.

func UpdateRoom_*_*()  AIRandomFly(ObjFind(***),90,150);

In the map editor you'll need to place an invisible wavepoint, and each fly added must be targeted for that wavepoint, with their own ID any stuff, and I think they must be placed on the map in contact with it's wavepoint as a starting point, that's how I got it to work.. they will fly around the room. changing the coordinates will alter how far from the wavepoint they can travel. something like that.

Pretty simple, I hope I've explained it easily enough.. you can then have as many wavepoint and flies in as many rooms as you want.

👍 0
#81299
Thanks a lot for that, as ever! This will definitely be a copy and paste job when the time comes, as I'm still very much a beginner. In the end, I did just set an animation with 5 frames, especially since the flies were only 1 pixel each -- but I'm thinking this will be useful to have in my arsenal, maybe for birds :smile:

I did spend a few hours just now working out how to make the flies follow you for a few seconds if you touch them and then walk away. I think I'm getting to be quite accomplished but then I'm largely clueless when I see code like this :wall:
👍 0
#81300
Regarding your first query - it has been mentioned on these boards fairly recently and I KNOW somebody posted the bit of code you're after but try as I might I cannot find the thread! Hopefully whoever it was will read your question and post it again :wink:

EDIT: Just remembered that Delta had that exact function in his game "Illusion Island Dizzy" where a shark swam at Dizzy when he entered a room. Try unpakking that and checking his scripts! (it's not password protected like Fantasy World.)
👍 0
#81301
Andy, have a look at page 35 of the DizzyAge Coding Queries in this forum. At the top of the page is a posting by Delta explaining how a shark attacks Dizzy as he enters a particular room unless Dizzy drops a fish, then the shark goes after the fish. Although all you want is for the hawk to attack Dizzy after a few seconds it will give you an idea of all the actions you need to take into account, ie when entering the room, updating the room, resetting the 'hawk' for when you re-enter plus respawning you outside of the room if the 'hawk' gets you ...and most importantly, setting up a 'waypoint' that centers on Dizzy which is the 'target' for the hawk. Do note that Delta has given the playerrespawn function a number (24). It doesn't really matter what number you use as long as it is unique for a 'death' and that you use the same number as the 'death' property of the hawk in the map.

You never know, you might want to add 'throwing a dead rat' or something to stop the hawk attacking Dizzy.

PS - Pogie, you posted whilst I was actually looking it up (mainly cos it was addressed to me which is why I remember it).
👍 0
#81308
[quote data-userid="1205" data-postid="81299"]

Thanks a lot for that, as ever! This will definitely be a copy and paste job when the time comes, as I'm still very much a beginner. In the end, I did just set an animation with 5 frames, especially since the flies were only 1 pixel each -- but I'm thinking this will be useful to have in my arsenal, maybe for birds :smile:

I did spend a few hours just now working out how to make the flies follow you for a few seconds if you touch them and then walk away. I think I'm getting to be quite accomplished but then I'm largely clueless when I see code like this :wall:

[/quote]

Yeah all I do is copy and past all the reverent bits, find all the correct bits and where the go can be tricky.

I can't remember where this code came from but it was probably one of Delta's games as always. It's a pretty simple thing to add.
👍 0
#81311
Excellent, thanks all of you! I had played Illusion Island but hadn't got so far. I think I should take time to play (if not complete!) all the games, and see how others have done things I'd like to. Just like checking answers for a crossword: it's not cheating if you learn from it! I do like to have a good go myself but it can become a crazy guessing game sometimes (case in point, I found out how to flip my moving rat around by just changing everything until I discovered you're supposed to change the second User value of the waypoint to 0).
👍 0
#81313
Andy, the coding on 'page 35' is specifically about the 'shark and fish' and doesn't include any other coding that was also going on in Illusion Island.

PS if you look at the top of the AI.gs file it tells you that the second user value can be used to flip the object in any direction (using the same numbers as in the flip (teapot!) component in the map).
👍 0