Author Topic: can you have some fighting in your game?  (Read 766 times)  Share 

can you have some fighting in your game?
« on: 09 Mar 2010, 22:37 »
Hi,

I have been using AGS for about 1 years now and i mastered all the simple techquies (hotspots, rooms, varibles etc). Now I would like to do a bit of action in my game, maybe a bit of fighting when you have to beat emeries. I have got no idea of how to start this kind of scripting off, can somebody advise me a simple script to learn to start please?

Thanks in advance

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #1 on: 09 Mar 2010, 23:24 »
[code]if (player.IsCollidingWithChar(cEnemy)) {
  cEnemy.Say("I AM DEAD!");
  cEnemy.ChangeRoom(-1);
}[/code]

That's a pretty simple one, I know, but it works..sort of..depending where you put it..maybe. :D
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: can you have some fighting in your game?
« Reply #2 on: 09 Mar 2010, 23:56 »
Seriously, monkey is right in his way, there's no simple script for that kind of things. It usually requires lots of scripting, but before scripting it requires lots of thinking, planning module logic, etc.

By the way, there's Ahmed's fighting game available, maybe you will find it useful, it has open code: http://www.bigbluecup.com/yabb/index.php?topic=20327.msg515108#msg515108
« Last Edit: 09 Mar 2010, 23:57 by Crimson Wizard »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: can you have some fighting in your game?
« Reply #3 on: 10 Mar 2010, 00:24 »
shaungaryevans:

If you just want some working fighting code, try to be more specific (but don't expect a full-fledged fight engine script). Then we can give you some pointers.

If you rather want to add other advanced stuff later on and be able to do that yourself, you're going to need to learn how to tackle a scripting problem. I'm not sure where to point you; the web is full of tutorials but those are almost always aimed at learning a specific language.
In general, break down the engine into smaller parts, start simple and solve one problem at a time.

A good starting point would be implementing a numpad controlled sprite that can move and punch.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #4 on: 10 Mar 2010, 01:06 »
It also depends on your fighting style that you want to achieve. Presumably you are talking about some sort of real-time fighting, but if you want turned-based it will be totally different. Also to take into consideration, will the fighting be projectile or melee?

There's a lot more to "adding fighting to your game" than simply adding a couple lines of script. The snippet I posted could, after a fashion, prove useful depending on how your fighting will be managed. However, there is no catch-all generic (or simple for that matter) solution.
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Mr Flibble

  • In There Like SwimWear!
    • I can help with AGS tutoring
    •  
    • I can help with characters
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with story design
    •  
Re: can you have some fighting in your game?
« Reply #5 on: 10 Mar 2010, 02:19 »
Something I've been wondering about for a long time, which has applications here, is the idea of being able to split up sprites into regions or areas. It'd be useful for, for instance, fighting game collision detection (ie. did the enemy collide with a fist or just the body* or where did a specific punch land), or switching out segments of a character (like how the old LEC games worked, they didn't store the whole sprites each time, just the segment that was changing) or for having characters only being partially tinted by a region (for instance, so you could have them standing half in shadow, half in light)


*A nice and simple way to achieve this with existing behaviour would be to check if the sprites are colliding, then also check if the current frame of the player's (or enemy's) view. This would mean that the player would have to "punch" to cause damage, not just collide by walking into the enemy.
Ah! There is no emoticon for what I'm feeling!

CShelton

  • Program 9: Loading...
Re: can you have some fighting in your game?
« Reply #6 on: 10 Mar 2010, 02:30 »
Something I've been wondering about for a long time, which has applications here, is the idea of being able to split up sprites into regions or areas. It'd be useful for, for instance, fighting game collision detection (ie. did the enemy collide with a fist or just the body* or where did a specific punch land)

With some hackery and SSH's Pixel Perfect Collision Module you could build a complex character that has fist and foot collision areas. This would be accomplished by having multiple characters occupying the same space, each limb being a separate character with their own collision. Orchestrating all of this is no easy feat, though it can be done.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: can you have some fighting in your game?
« Reply #7 on: 10 Mar 2010, 09:26 »
Or you could use structs to store the coordinates of collision boxes for every frame. Similarly annoying to set up but faster and easier to change.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: can you have some fighting in your game?
« Reply #8 on: 11 Mar 2010, 17:22 »
Hi Guys,

Thanks for all the pointers, so i need to start from the begining on this a work on it, first thing i would suppose is the enemy's movement. He will walk on this own around the map, sorry to be a pain but how can you make a character move around the map/room without you controlling it?

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #9 on: 11 Mar 2010, 17:27 »
Well it depends whether you want them to walk along a predefined path or just wander around aimlessly at random. The first would involve creating some way of defining the path, the points along it to which the character will travel, and then the order in which each point is reached. That would probably be done using some sort of struct.

The second is much simpler:

[code]function repeatedly_execute_always() {
  if (!cEnemy.Moving) cEnemy.Walk(Random(Room.Width), Random(Room.Height));
}[/code]
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

suicidal pencil

  • The green-machine
    • I can help with animation
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Re: can you have some fighting in your game?
« Reply #10 on: 12 Mar 2010, 00:24 »
[code]function repeatedly_execute_always() {
  if (!cEnemy.Moving) cEnemy.Walk(Random(Room.Width), Random(Room.Height));
}[/code]

what about walkable areas and the such? If you had an urban scene, I think it would be a bit weird to watch an enemy walk up the side of a building :P


monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #11 on: 12 Mar 2010, 00:59 »
The Walk function can take account of walkable areas. In the example provided you'd presumably want to use eWalkableAreas and eNoBlock. Don't remember what the defaults are, but that's what the manual is for.
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Re: can you have some fighting in your game?
« Reply #12 on: 12 Mar 2010, 20:37 »
Thanks, i have now got someone that moves on his own, but one problem, the timer cursor stays on while he moves. I don't remember how to make the timer go off? Any help please?

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #13 on: 12 Mar 2010, 20:44 »
Okay just checked in with the manual and the default settings are eNoBlock and eWalkable areas so unless you specifically pass something different it shouldn't be blocking at all.

What is the exact code you are using?
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Re: can you have some fighting in your game?
« Reply #14 on: 12 Mar 2010, 20:48 »
if(cEgo.Room == 1) cChar1.Walk(Random(Room.Width), Random(Room.Height), eNoBlock);

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #15 on: 12 Mar 2010, 21:13 »
You forgot to check that the character isn't moving:

[code]if ((cEgo.Room == 1) && (!cChar1.Moving)) cChar1.Walk(Random(Room.Width), Random(Room.Height));[/code]

eNoBlock is the default so you don't need to pass that in explictly.
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Re: can you have some fighting in your game?
« Reply #16 on: 12 Mar 2010, 21:20 »
Thanks, that works now.

Back to the getting to the frighting bit now, now i know how to move cchar1 freely, can i make him to come towards me all the time as what enemys do please?

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #17 on: 12 Mar 2010, 21:41 »
Do you want him to chase after you if you get within a certain distance, if he can see you, or just all the time?

Regardless of when you want him to chase you, look up the Character.FollowCharacter function in the manual.
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Re: can you have some fighting in your game?
« Reply #18 on: 12 Mar 2010, 21:49 »
I had a look at the manual now, its only got how to set the distance between charatcher the the standing time. How to set set as if they look at him or he get anywhere near him, they chase him
« Last Edit: 12 Mar 2010, 22:00 by shaungaryevans »

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: can you have some fighting in your game?
« Reply #19 on: 13 Mar 2010, 00:32 »
You will have to script that yourself as it's not a built-in method. Something like:

[code]int DistanceFromCharacter(this Character*, Character *theCharacter) {
  // based on a script by KhrisMUC
  if (theCharacter == null) return -1;
  int z1 = 10000 / this.Scaling;
  int z2 = 10000 / theCharacter.Scaling;
  int x1 = this.x * (z1 / 100);
  int x2 = theCharacter.x * (z2 / 100);
  int dx = x1 - x2;
  int dz = z1 - z2;
  return FloatToInt(Maths.Sqrt(IntToFloat((dx * dx) + (dz * dz))));
}

bool IsFacingCharacter(this Character*, Character *theCharacter) {
  if (theCharacter == null) return false;
  bool turnBeforeWalk = GetGameOption(OPT_TURNBEFOREWALK); // whether characters turn before walking
  if (turnBeforeWalk) SetGameOption(OPT_TURNBEFOREWALK, 0); // temporarily disable this setting
  int loop = theCharacter.Loop; // store the current loop
  theCharacter.FaceCharacter(player, eNoBlock); // sets the character's loop towards the player
  bool facing = (theCharacter.Loop == loop); // whether theCharacter was already facing the this Character
  if (!facing) theCharacter.Loop = loop; // restore the previous loop if changed
  if (turnBeforeWalk) SetGameOption(OPT_TURNBEFOREWALK, 1); // restore turn before walking if disabled
  return facing; // return whether the player was facing the other character already
}

function repeatedly_execute() {
  if (player.DistanceFromCharacter(cChar1) <= 30) { // the player is within 30 units (scaled pixels) from the enemy's position
    if (cChar1.IsFacingCharacter(player)) cChar1.FollowCharacter(player, 1, 10); // or whatever values you want here
  }
}[/code]
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey