Help needed:How can i make a chase sequence

Started by Milos Regamer Jevtic, Tue 29/11/2011 15:57:04

Previous topic - Next topic

Milos Regamer Jevtic

Hi there! I'm a begginer game maker and i need help, how can i make a chase sequence? I mean, i make the baddy follow the player, but how can i make it so when the baddy makes a contact with the player, an attacking animation plays, and then it goes to the game over screen? If someone can type here what i need to type in the script, but the whole thing please. I am just starting to learn the scripting language, and i will give credit if you ask.
What is ultimate POWAH?!

Khris

You need to constantly check the distance between player and baddy.

Put this at the top of the global script, before everything else:
Code: ags
int DistanceFrom(this Character*, Character other) {
  int dx = this.x - other.x;
  int dy = (this.y - other.y)*2;                //  <--- perspective factor

  return FloatToInt(Maths.Sqrt(IntToFloat(dx*dx + dy*dy)));
}


Now find the repeatedly_execute function (use the dropdown menu at the top) and put this inside

Code: ags
  // chase code
  if (player.Room == cBaddy.Room && player.DistanceFrom(cBaddy) < 50) {

    player.StopMoving();
    cBaddy.StopMoving();
    // attack & death animations
    // game over screen
    // etc.
  }


Note that this code will only work if your baddy character's internal name is "cBaddy"; either change it to that or put their name into the code.
50 is the distance in pixels, adjust that to the desired value.

The most important thing: try to understand what the code does instead of mindlessly copy-pasting it.

Milos Regamer Jevtic

Thank you good sir, shalt you be credited? No probs i understood, i'll change stuff aka cBaddy to cSMan etc
What is ultimate POWAH?!

Khris

No need to credit me for five minutes of typing :)

Does it work, do you need help with the death stuff?

Milos Regamer Jevtic

Um actually i'm getting deh parser error of doom at 'this' that is the this in front of Character* oh and im using ags 2.something that was released last year not the newest one.
What is ultimate POWAH?!

Khris

The lastest 2.something is from 2006.

It doesn't support extender functions yet, so replace the first part with this:

Code: ags
int DistanceFrom(Character c, Character other) {
  int dx = c.x - other.x;
  int dy = (c.y - other.y)*2;                //  <--- perspective factor

  return FloatToInt(Maths.Sqrt(IntToFloat(dx*dx + dy*dy)));
}


Then replace "player.DistanceFrom(cBaddy)" with "DistanceFrom(player, cBaddy)".

Milos Regamer Jevtic

Ah damnit, the bastard just slaughtered me! Gotta make im slower! Nonetheless the thing works, can this topic be deleted? If not then good, i will come back here whenever i need the script, till i learn scripting completely, thank you very much! I will credit you whenever you like it or not :D
What is ultimate POWAH?!

monkey0506

No need to delete the topic, we keep them here as a reference so when future newbies come along we can yell at them for not using the forum search. :=

Nah, but we do like to keep these threads around. ;)

Milos Regamer Jevtic

Kk i will copy deh script(s) to a text file or 2, when i go to my friend so i can use his internet,cuz i don't have one,i'm writing from my phone.
What is ultimate POWAH?!

Ghost


Milos Regamer Jevtic

Os- whut? I hope that you are not making fun of me, i don't have the time to read the scripting tut, i have to work on room bgs, sprites, music  and le sounds (that i make with my mouth) so you see how much it tires me outta my mind.
What is ultimate POWAH?!

Khris

Yes, we are making fun of you.
Which is now wonder given your way of spelling alone, with "deh" instead of "the" and the like.

It's not surprising that you "don't have the time to read the scripting tut", we know your kind ::)

I can't wait to find out your video game fetish. I hope it's not Final Fantasy, because your predecessor Icey has that covered. Oh my, and how covered he has it. He's still doing it.

To make a long story short, if you haven't lied about your age, you're just barely old enough to post here. That doesn't mean that you won't get mocked and scolded if you can't behave mature though.
I just want to give you a fair warning, this forum isn't like most others. If you piss us off (for instance by demanding ready-made code all the time because you can't be bothered to figure coding out for yourself), this welcoming community can turn pretty sardonic on you.

You are already showing all the typical signs, opening threads like the "favourite AGS game line" one, asking for your threads to be deleted and others. This isn't a playground. Think, then post.

The most important thing is that you're too young to get why you're too young to get all this. So I really hope you'll simply take my word for it. I'll go out on a limb and say that you didn't lurk for a few months when you discovered this community, right? You started posting right away. And what's a better way to start than to open a thread in the Completed Games forum, without a download, breaking the rules with your very first post, then canceling the game the next day?

Well, so much for my rant. Welcome to the forums.

monkey0506

#12
Don't listen to Oceanspirit Khris. He's a known troll around these parts. :=

No, but seriously, the forum rules do include things such as not using "l33t-sp33k" or what have you. Of course if you don't even have the five minutes it would take to read (perhaps not fully understand, but just to skim over) the scripting tutorial ("This game, the world needs it. The world needs it NOW! Or it will EXPLODE!!11 NO TIEM FOR SKRIPTEN TOOTOOREEALZ") then you probably don't have time for such frivolities as the forum rules.

Yes, I am a sarcastic douchebag sometimes. But at least your original post in this thread was written in something reminiscent of English.

People are not going to take you seriously if you can't even take the time to write your posts in a (moderately) serious fashion. Very few people want to play a game created by someone who can't type a semi-proper sentence (unless it is an OSD game :D).

And yes, welcome to the forums.

Milos Regamer Jevtic

Ok seriously now, i'm 16 yo, and Monkey, you are one funny guy, or girl i don't know, and the l33t speech is a bad habbit from the past.
What is ultimate POWAH?!

SMF spam blocked by CleanTalk